[cairo] cairo_device_font_t

Owen Taylor otaylor at redhat.com
Thu Jan 13 13:28:09 PST 2005


Talked some more about some of the font API issues with Keith on IRC.

Starting points:

 - On windows, a HFONT is already scaled to a particular point size.
   While it is possible on NT and newer to transform a HFONT using
   SetWorldTransform, in general we want to select an HFONT based
   on the full CTM+font transform combination.

   Uniscribe does layout with respect to a HFONT, so the operation
   that Pango from Cairo is "draw these glyphs with this HFONT".

 - With FreeType, Pango has an internal PangoFont object that is
   specialized to a particular CTM+font transform. Getting the
   glyph metrics for a PangoFont from Cairo needs to be as fast
   as possible. Pango also needs to be able to quickly get an
   scaled FT_Face for a PangoFont.

   If the Cairo API involves passing in a scale and an unscaled
   font, that prohibits later optimizations within Cairo ... we
   always have to check the scale.

An API device that would allow fixing both these problems is to add
a cairo_device_font_t which is a font scaled to a particular CTM,
font matrix, and device. There would be API like:
 
 cairo_set_device_font (cairo_t *cr);
 cairo_device_font_t cairo_current_device_font (cairo_t *cr);
 
 cairo_ft_create_device_font(FcPattern *pattern, cairo_font_scale_t *scale);
 cairo_win32_create_device_font(HFONT *hfont);

The rule is that if you set a device font, it must have been created
appropriately for the current scale; if you don't follow that rule,
you get garbage metrics. Changing the CTM or target device clears
the current device font.

Open questions:

 - With this API, it's not clear that cairo_font_t is useful ...
   simple apps will use the toy API cairo_select_font() and 
   cairo_scale_font(). Pango and equivalents will use 
   cairo_device_font_t.  Perhaps we should just drop 
   cairo_font_t from the public API.

 - Do we need a function to get the cairo_font_scale_t for a 
   cairo context? Do we need to expose the logic in 
   _cairo_matrix_compute_scale_factors() for selecting a  point size
   from a font scale?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050113/9bffa3be/attachment.pgp


More information about the cairo mailing list