From 2391d025ac7b8c1d65664412279ca1b5b3aba3b6 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 1 Apr 2010 20:42:07 +0000 Subject: [PATCH] Bugfix for X11 font loading when NULL pointer encountered. --- .../sources/platform/sdl/gl_wrap.cpp | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp index 03e782532..653074d83 100644 --- a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp +++ b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp @@ -94,23 +94,51 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, throw std::runtime_error("Font not found."); } + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + // we need the height of 'a' which sould ~ be half ascent+descent metrics.setHeight(static_cast (fontInfo->ascent + fontInfo->descent) / 2); + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + for(unsigned int i = 0; i < static_cast (charCount); ++i) { + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(i < fontInfo->min_char_or_byte2 || i > fontInfo->max_char_or_byte2) { + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); metrics.setWidth(i, static_cast(6)); } else { + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); int p = i - fontInfo->min_char_or_byte2; - metrics.setWidth(i, static_cast ( + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] p = %d fontInfo->per_char = %p\n",__FILE__,__FUNCTION__,__LINE__,p,fontInfo->per_char); + if(fontInfo->per_char == NULL) { + XCharStruct *charinfo = &(fontInfo->min_bounds); + int charWidth = charinfo->rbearing - charinfo->lbearing; + int charHeight = charinfo->ascent + charinfo->descent; + int spanLength = (charWidth + 7) / 8; + + metrics.setWidth(i, static_cast (charWidth)); + } + else { + metrics.setWidth(i, static_cast ( fontInfo->per_char[p].rbearing - fontInfo->per_char[p].lbearing)); + } } + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); glXUseXFont(fontInfo->fid, 0, charCount, base); + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + XFreeFont(display, fontInfo); + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); #else // we badly need a solution portable to more than just glx //NOIMPL;