diff options
author | nyamatongwe <unknown> | 2003-03-21 11:38:48 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2003-03-21 11:38:48 +0000 |
commit | 58a7a76fc8f862a94711058b96e3b501845206b9 (patch) | |
tree | 4c47af45db5a669f902f1c13dd3b28f1064124df | |
parent | b0a60dd15c5f3188ea3bf9a5e62239d2f40b493f (diff) | |
download | scintilla-mirror-58a7a76fc8f862a94711058b96e3b501845206b9.tar.gz |
Thread safety on font ascent and character width determination.
-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; |