[Gtk2] About bug 11523: analysis and proper fix(es)

Mattias Gaertner nc-gaertnma at netcologne.de
Sun Jul 13 10:06:34 CEST 2008

On Sat, 12 Jul 2008 12:37:17 -0300
Luiz Americo Pereira Camara <luizmed at oi.com.br> wrote:

> The problem occurs because each device context instance has a text
> cache while the layout is shared between all device contexts that
> have the same font.
> In TextOutCacheGtk2.zip there's a project that helps to show the
> problem.
> Considering that "Single Line" option is set:
> Str1 is draw to Bitmap1.Canvas:
>  - The text cache of Bitmap1.Canvas is empty and is set to Str1 data
>  - Str1 is set as the layout text
> Str2 is draw to Bitmap2.Canvas:
>  - The text cache of Bitmap2.Canvas is empty and is set to Str2 data
>  - Str2 is set as the layout text
> Str1 is draw (again) to Bitmap1.Canvas:
>  - The text cache of Bitmap1.Canvas has Str1 data so it does not set
> the layout text
>  - The layout still have Str2 as the text...
> I can't explain what's going on when "Single Line" option is not
> set...
> The fix is simple, instead of caching the text data at each time the 
> layout text is set, retrieve the text directly from the layout using 
> pango_layout_get_text (unlike the *set_text function this is pretty 
> cheap since it just returns a pointer of the stored text). With this 
> approach i have two wons: no data copy/duplication and avoid the out
> of sync between cache and layout texts.
> I implemented  in three ways (see the patches):
> 1) Stores the OldFont (Pangolayout) and compare the Old/New strings 
> using strcomp*
> Than i noticed that is not necessary to store the old font and comes 
> with the 2nd implementation. There's also no more need to be a method
> of TGtk2DeviceContext.
> 2) Just compare the two strings using StrComp*

That's better.

> * Is better to use StrLComp instead of StrComp
> But i lost the shortcut evaluation of length that prevents a string 
> comparation. So...
> 3) Stores the old length in the layout object using a gquark* and 
> compare both strings with comparebytes (i know that both strings are
> the same size)
> ** The old length can be also stored in a field of font GdiObject

Have you compared times?
I guess option 3 will be even slower for normal texts.


More information about the Gtk2 mailing list