Re: [Indic-computing-devel] Re: NCST Indix Examined
Status: Alpha
Brought to you by:
jkoshy
From: Arun S. <ar...@sh...> - 2002-02-22 07:31:06
|
On Tue, Feb 19, 2002 at 10:10:41AM -0800, Arun Sharma wrote: > The existing algorithm in Xaw: > > // startx = x[1] > // pixel_width = x[2] - x[1] > FindPosition(textpos, startx, pixel_width) > nchars = 0 > curpos = startx > while 1: > // Uses XFontStruct for efficiency > width = compute the width of the next char in the text buf > nchars++; > curpos += width > if (curpos >= startx + pixel_width) > break; > > // everything starting from textpos to textpos + nchars is "selected" I've studied how gtk implements this algorithm. The algorithm can be found at: gtk/gtktext.c - find_mouse_cursor_at_line() The algorithm is very similar, proceeding one character at a time (in other words, broken for (context sensitive) Indic fonts). It has a 256 byte cache which caches the widths of all the characters in the range 0-256 (gtk/gtktext.c - find_char_width()) per font. (Hint: Ammo for those of you looking for "latin1 bias" :) For everything > 256, it delegates it to gdk, which delegates it to XTextExtents(). XTextExtents is a network efficient function, in that it is capable of responding to requests locally (unlike XQueryTextExtents, which has to consult the X server). The way IndiX has implemented it, XTextExtents is mapped to XQueryTextExtents - sacrificing network efficiency. In other words, when you drag your mouse, gtk will execute the above loop and a X protocol request is made for every character to compute its width. A new protocol request - such as XComputeWidth (Is XComputeNChars a better name ?) will batch these XQueryTextExtent requests into a single request. Keyur, I didn't understand your comment on why this functionality doesn't belong to the X server. Or did I misread your statement ? Another data point: Using character codes is NOT unprecedented in XFree86. I just finished reading the i18n specs. http://www.x-docs.org/i18n/Framework.pdf and looked at the implementation: xc/lib/X11/omDefault.c - _Xutf8DefaultDrawString The input is clearly a UTF-8 string. It's calling _XmbDefaultDrawString which is calling XDrawString, which is doing a PolyText request in the X protocol. In other words, a character code is being sent over the X protocol. On a related note, can anyone on the list enlighten me on the difference between utf8 and mbs (multi byte string) ? I thought UTF-8 was a mbs too. -Arun |