Render of Thai text with and without mouse selection

Lars Knoll lars at trolltech.com
Mon Dec 27 21:35:33 GMT 2004


On Monday 27 December 2004 20:21, Leo Savernik wrote:
> Am Montag, 27. Dezember 2004 17:26 schrieb Otto Pattara:
> > > The only thing I can perceive from the small example is that the
> > > text moves around slightly while selecting it. This is the bug I'm
> > > talking about.
> >
> > Yes, then I think we are talking about the same thing.
> >
> > Would you mind sharing me some more information about this bug or
> > pointing to some URLs or source code? Just when you have time...
>
> Here you go:
>
> Painting the selection:
> http://lxr.kde.org/ident?i=paintSelection
>
> Painting the text (and the selection in a different pass):
> RenderText::paint
> http://lxr.kde.org/source/kdelibs/khtml/rendering/render_text.cpp#L908
>
> The problem is the fact that certain scripts combine adjacent characters
> when drawn as a single text run. However, the selection may break the
> combining at any point, thus producing two separate (and normally different
> looking) characters, one in front of, and one after the selection boundary.
>
> The proper solution would be to draw the full run, and clip it between the
> combined characters (this will keep the characters from being drawn in
> their separated form). However, there's no public API in Qt to retrieve the
> exact point of clipping (or is there, Lars?).

There are two ways to get it. One is through public API but painfully slow for 
complex writing systems:

QFontMetrics::charWidth(const QString &text, int pos)

will give you the width of a character in context and makes it possible to 
calculate the points you need.

The other one is quite a bit faster, but uses internal API (I can however 
promise that the API will not change in a BIC way in Qt 3 anymore). That is 
to use the QTextLayout class. QFontMetrics::charWidth() uses this class as 
well, but recalculates a lot for every single character, something you could 
avoid by using the class directly.

Cheers,
Lars


> Otto, feel free to work on the problem if you like. If you manage to
> achieve a working result, I'd like to see the patches.
>
> mfg
>  Leo




More information about the kfm-devel mailing list