If you are using xft there is no round-trip for measuring text. Xft loads the font into local memory and does all the rendering in local memory, and sends images over to the X server for Xrender to composite onto the screen. All the extents and measuring information is stored locally.
Lots of people don't believe this. However it is MUCH more efficient to do it this way, as the "extent" type information and the fact that fonts have thousands of characters means that this data is probably an order of magnitude larger than the images of the letters themselves, so this minimizes communication. Windows also works this way, pretty much. Originally they used a memory-mapped server but I'm pretty certain they have switched to a per-process instance, as the overhead of locking and garbage collection in that server exceeded the overhead of each process rendering it's own copy of each letter. Note also that the WIN32 api we are using also has 16-bit coordinates. I would not worry about legacy X fonts. I believe the current implementation already downloads the entire font description to local memory to avoid the round trip anyway. On 05/08/2012 03:23 AM, Albrecht Schlosser wrote: > Question: How "expensive" would measuring the text before doing > the real output in X11 be? > > Reasoning: In STR #2798 [1] there's a proposal to clip text before > drawing in X11, because of the problem with 16-bit coordinates > in X11 vs. 32-bit coordinates in FLTK. The proposed patch [2] is > incomplete (and not correct), but a correct clipping algorithm > would IMHO mean that we'd need to measure the text. The problem > is that text that would normally be outside the clipping range > could "wrap" into the display because X11 ignores the upper 16 > bits of the (FLTK) coordinate space. Note that this is not a > problem for Windows and OS X, since these are using 32-bit > coordinates anyway. > > Does anybody here know how "expensive" this would be in terms > of CPU usage and - probably *much* more important - X11 server > interactions? The measuring would have to be right before calling > > XUtf8DrawString(fl_display, fl_window, font_descriptor()->font, fl_gc, > x, y, c, n); > > in fl_font_x.cxx (isn't there another one for XFT?), so the font > for measuring the text would probably be set up already. Would this > introduce more X server messages, or would measuring be a local > operation? > > Second question: What function should be used: fl_measure() or > fl_text_extents()? Would there be a performance difference to be > expected, or would it only be the small difference in the exact > layout? The latter could IMHO be ignored, I'd suggest to use the > faster method, because exactness wouldn't matter here, anyway. > > Albrecht > > > [1] http://www.fltk.org/str.php?L2798 > [2] http://www.fltk.org/strfiles/2798/patch.txt _______________________________________________ fltk-dev mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk-dev
