[Gtk2] About bug 11523: analysis and proper fix(es)
Luiz Americo Pereira Camara
luizmed at oi.com.br
Sat Jul 12 17:37:17 CEST 2008
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*
* 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
Luiz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TextOutCacheGtk2.zip
Type: application/zip
Size: 2836 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/gtk2/attachments/20080712/e239c59e/attachment-0001.zip>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gtk2settext_ver1.diff
URL: <http://lists.lazarus-ide.org/pipermail/gtk2/attachments/20080712/e239c59e/attachment-0003.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gtk2settext_ver2.diff
URL: <http://lists.lazarus-ide.org/pipermail/gtk2/attachments/20080712/e239c59e/attachment-0004.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gtk2settext_ver3.diff
URL: <http://lists.lazarus-ide.org/pipermail/gtk2/attachments/20080712/e239c59e/attachment-0005.ksh>
More information about the Gtk2
mailing list