diff options
| -rw-r--r-- | gtk/PlatGTK.cxx | 132 | 
1 files changed, 69 insertions, 63 deletions
| diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index f476af33f..797538e93 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -46,6 +46,58 @@  enum encodingType { singleByte, UTF8, dbcs}; +struct LOGFONT { +	int size; +	bool bold; +	bool italic; +	int characterSet; +	char faceName[300]; +}; + +#if USE_LOCK +static GMutex *fontMutex = NULL; +#endif + +static void InitializeGLIBThreads() { +#if USE_LOCK +	if (!g_thread_supported()) { +		g_thread_init(NULL); +	} +#endif +} + +static void FontMutexAllocate() { +#if USE_LOCK +	if (!fontMutex) { +		InitializeGLIBThreads(); +		fontMutex = g_mutex_new(); +	} +#endif +} + +static void FontMutexFree() { +#if USE_LOCK +	if (fontMutex) { +		g_mutex_free(fontMutex); +		fontMutex = NULL; +	} +#endif +} + +static void FontMutexLock() { +#if USE_LOCK +	g_mutex_lock(fontMutex); +#endif +} + +static void FontMutexUnlock() { +#if USE_LOCK +	if (fontMutex) { +		g_mutex_unlock(fontMutex); +	} +#endif +} +  // On GTK+ 1.x holds a GdkFont* but on GTK+ 2.x can hold a GdkFont* or a  // PangoFontDescription*.  class FontHandle { @@ -92,75 +144,26 @@ public:  		}  	}  	int CharWidth(unsigned char ch, encodingType et_) { -		if (ch <= 127) { -			if (et != et_) { -				return 0; -			} +		int w = 0; +		FontMutexLock(); +		if ((ch <= 127) && (et == et_)) { +			w = width[ch];  		} -		return width[ch]; +		FontMutexUnlock(); +		return w;  	}  	void SetCharWidth(unsigned char ch, int w, encodingType et_) {  		if (ch <= 127) { +			FontMutexLock();  			if (et != et_) {  				ResetWidths(et_);  			}  			width[ch] = w; +			FontMutexUnlock();  		}  	}  }; -struct LOGFONT { -	int size; -	bool bold; -	bool italic; -	int characterSet; -	char faceName[300]; -}; - -#if USE_LOCK -static GMutex *fontMutex = NULL; -#endif - -static void InitializeGLIBThreads() { -#if USE_LOCK -	if (!g_thread_supported()) { -		g_thread_init(NULL); -	} -#endif -} - -static void FontMutexAllocate() { -#if USE_LOCK -	if (!fontMutex) { -		InitializeGLIBThreads(); -		fontMutex = g_mutex_new(); -	} -#endif -} - -static void FontMutexFree() { -#if USE_LOCK -	if (fontMutex) { -		g_mutex_free(fontMutex); -		fontMutex = NULL; -	} -#endif -} - -static void FontMutexLock() { -#if USE_LOCK -	g_mutex_lock(fontMutex); -#endif -} - -static void FontMutexUnlock() { -#if USE_LOCK -	if (fontMutex) { -		g_mutex_unlock(fontMutex); -	} -#endif -} -  // X has a 16 bit coordinate space, so stop drawing here to avoid wrapping  static const int maxCoordinate = 32000; @@ -1298,20 +1301,23 @@ int SurfaceImpl::Ascent(Font &font_) {  	if (!(font_.GetID()))  		return 1;  #ifdef FAST_WAY -	if (PFont(font_)->ascent > 0) -		return PFont(font_)->ascent; +	FontMutexLock(); +	int ascent = PFont(font_)->ascent;  #ifdef USE_PANGO -	if (PFont(font_)->pfd) { +	if ((ascent == 0) && (PFont(font_)->pfd)) {  		PangoFontMetrics *metrics = pango_context_get_metrics(pcontext,  			PFont(font_)->pfd, pango_context_get_language(pcontext));  		PFont(font_)->ascent =  			PANGO_PIXELS(pango_font_metrics_get_ascent(metrics));  		pango_font_metrics_unref(metrics); -		return PFont(font_)->ascent; +		ascent = PFont(font_)->ascent;  	}  #endif - -	return PFont(font_)->pfont->ascent; +	if (ascent == 0) { +		ascent = PFont(font_)->pfont->ascent; +	} +	FontMutexUnlock(); +	return ascent;  #else  	gint lbearing; | 
