From 8927a4d7fe6aa2bce851e580ce133e2629c76374 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Thu, 13 Mar 2003 12:54:57 +0000 Subject: Avoiding drawing strings consisting entirely of space characters in transparent mode. Remembering pixel widths of all single character strings as many single character runs occur in source code. These add up to a 22% speed improvement. --- gtk/PlatGTK.cxx | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index 073e51faa..56ead18a3 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -49,6 +49,7 @@ class FontHandle { public: int ascent; + int width[128]; GdkFont *pfont; #ifdef USE_PANGO PangoFontDescription *pfd; @@ -59,12 +60,18 @@ public: #ifdef USE_PANGO pfd = 0; #endif + for (int i=0;i<128;i++) { + width[i] = 0; + } } #ifdef USE_PANGO FontHandle(PangoFontDescription *pfd_) { ascent = 0; pfont = 0; pfd = pfd_; + for (int i=0;i<128;i++) { + width[i] = 0; + } } #endif ~FontHandle() { @@ -1070,10 +1077,15 @@ void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font_, int ybase, const c DrawTextBase(rc, font_, ybase, s, len, fore); } -// On GTK+, exactly same as DrawTextNoClip void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore) { - DrawTextBase(rc, font_, ybase, s, len, fore); + // Avoid drawing spaces in transparent mode + for (int i=0;ipfd) { + if (len == 1 && (static_cast(*s) <= 127) && PFont(font_)->width[*s]) { + positions[0] = PFont(font_)->width[*s]; + return; + } PangoRectangle pos; pango_layout_set_font_description(layout, PFont(font_)->pfd); if (unicodeMode) { @@ -1131,6 +1147,9 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, int *positi delete []utfForm; } } + if (len == 1 && (static_cast(*s) <= 127)) { + PFont(font_)->width[*s] = positions[0]; + } return; } #endif -- cgit v1.2.3