[cairo] text measurement in perf?

Robert O'Callahan robert at ocallahan.org
Tue May 29 20:24:37 PDT 2007

I just want to mention on this list what I'm doing for glyph extents in
Mozilla at the moment [1]. I'm taking advantage of the fact that almost all
the time, we only care about glyph extents when they fall outside the "font
box" for the string [2] --- the box formed by the font ascent and descent
vertically, and the glyph advances horizontally. Most glyphs fall inside
their font-box, so we special-case glyphs that have no left bearing (for LTR
scripts) and do not extend beyond the font ascent/descent --- in these cases
we can just cache the offset of the glyph's right edge. The cache can
actually be an array of 16-bit offsets indexed by glyph, which is very fast
and small. I don't bother limiting the cache size. With this cache, I'm
seeing negligible slowdown on Mac page load times (compared to not getting
glyph extents at all). With this cache I'm not really using the cairo cache
at all, so I'm bypassing it and going straight to ATSUI.

I'm not sure how to integrate this with cairo in the long term. A simple API
change would be to give me a way to get the extents for a single glyph,
bypassing the cache ... then I wouldn't need my own plaform-specific glyph
extents code. A more complex API would be something like "give me the
extents for this glyph list, unioned with the font-box for the glyphs",
which would allow the above optimization to be performed by cairo itself.

[1] Well, it's not checked in yet.
[2] This is to compute a "big enough" area that needs to be repainted when
the text changes.

"Two men owed money to a certain moneylender. One owed him five hundred
denarii, and the other fifty. Neither of them had the money to pay him back,
so he canceled the debts of both. Now which of them will love him more?"
Simon replied, "I suppose the one who had the bigger debt canceled." "You
have judged correctly," Jesus said. [Luke 7:41-43]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cairographics.org/archives/cairo/attachments/20070530/dbfb0090/attachment-0001.html 

More information about the cairo mailing list