[cairo] Getting real linearly-scalable text

Behdad Esfahbod behdad at behdad.org
Thu May 15 09:52:25 PDT 2008


On Wed, 2008-05-14 at 20:56 -0400, Behdad Esfahbod wrote:
> 
> It's only fair to also talk about metrics at this point.  If 
> metrics-hinting is off, we should also use metrics from a fixed size,
> scaled by cairo.  It gets trickier here.  Cairo returns metrics in user
> space.  So, for a fixed font matrix, regardless of the ctm matrix, one
> should get the same metrics.  This is indeed needed to ensure that a
> zoomed-in print preview of a book typeset using pangocairo has the exact
> same line breaks that the actual print does.  The scaled-font code takes
> glyph metrics from backends in font space and converts to user-space by
> applying the font matrix.  That is, it's completely independent of the
> ctm.  That's good.  We just need to ensure that for metrics-hinting=off,
> we use the metrics for the font at a fixed size.  That is, like what we
> need for paths.  This time however, we probably do need to cache the
> sizes for different font matrices.  So we can't just cache it on
> font_face_t.  We need a new object, that has all the identifying
> properties of cairo_scaled_font_t except for the CTM.  Then whether
> metrics-hinting is off or on decides whether we should share or not
> share this object across scaled-fonts with different CTMs.

Just after I sent this it occurred to me that metrics is more
complicated.  The "ink" metrics (bearings and width/height) should come
from the same source that the glyph path does, while the advance should
follow the metrics-hinting setting.  So what I explained above is only
about the advance values.  Seems like we have to compile the metrics
from two different sources.


I also thought a bit about how to approach implementing all this weird
caching behaviors.  One approach is to introduce three new objects,
cairo_scaled_font_glyph_raster_array_t,
cairo_scaled_font_glyph_path_array_t, and
cairo_scaled_font_glyph_metric_array_t.  All ref-counted so they can be
shared.  Then the scaled font will have a pointer to one of each of
those, and we can share them among multiple scaled fonts.  That becomes
quite complex quite fast, specially in the backend interface.

Another approach is to not touch the current backend interface, instead
link scaled fonts to canonical scaled fonts to be used for
raster/path/metrics.  That's kinda ugly, but may prove easier to
implement.

Anyway, I'll be thinking about it more this weekend while canoeing in
Northern Ontario.  Given enough time, the Right design will eventually
reveal its beauty...

-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759



More information about the cairo mailing list