[cairo] Pango/Cairo integration thoughts

Owen Taylor otaylor at redhat.com
Thu Sep 23 14:45:30 PDT 2004

I spent some time thinking about what Pango needs from the Cairo font

For background, the paper/slides at: 


explain how I see the Pango/Cairo API working from the user perspective.

Also, possible useful background is the (previously referenced here)

Which explains why a layout engine might want to get both device-independent
and device-dependent metrics for the same font.

Quick summary of Pango/Cairo integration


 PangoLayout *layout = pango_cairo_create_layout (cr);
 pango_layout_set_text (layout, "Hello world");
 pango_cairo_show_layout (cr);
 g_object_unref (layout);


  /* Fontmaps and context can be used with any cairo_t */
  PangoFontMap *font_map = pango_cairo_get_default_font_map ();
  PangoContext *context = pango_cairo_font_map_create_context (font_map);
  PangoLayout *layout = pango_layout_new (context);
  int width, height;

  /* But we need to copy information (like the CTM) from the cairo_t 
   * into the the context in order to get correct layout */
  pango_cairo_context_update (context, cr);
  pango_layout_set_text (layout, "Hello world");
  pango_cairo_show_layout (cr);
  /* Layout is done in user space coordinates */
  pango_layout_get_size (layout, &width, &height);
  cairo_rmoveto (cr, 0, (double)height / PANGO_SCALE);

  g_object_unref (layout);
  g_object_unref (context);

Operation A: Getting metrics


 FcPattern + {size/font_matrix} + user_to_device_matrix 


 Device-dependent font metrics
 Device-independent font metrics
 Device-dependent glyph metrics
 Device-independent glyph metrics


 * All of the above quantities can be computed given the FT_Face set up
   with the appropriate FT_Set_Char_Size/FT_Set_Transform. So, a 
   "XftLockFace" call is sufficient. However, for glyph metrics, 
   sharing cached information with Cairo and/or hooking glyph-metric
   caches to the glyph image caches may be useful.

 * Currently Pango never uses a font matrix that isn't a straightforward size,
   but I've written {size/font_matrix} since the ability to distort fonts
   is already in the current Cairo API. (Interaction with changes to the
   matrix done out of fonts.conf needs to be investigated)

 * The metrics that Pango is interested in (both device-independent
   and device dependent) are the metrics in the *user* coordinate
   system. So, the device independent metrics are affected by the
   {size/font_matrix} but independent of the user_to_device_matrix.

   These are different from the metrics that Xft returns for transformed

 * Hinting doesn't make sense except for transformation matrices which
   are pure scale+multiple-of-90-degree rotation. For all other transformations,
   device-dependent and device-independent metrics should be the same.

   (Hinting for 90-degree-multiple rotated fonts isn't currently implemented 
   in FreeType, it may be useful to actually do glyph images unrotated then 
   rotate. On the other hand, perhaps FreeType just needs to be fixed.)
Operation B: Drawing

 FcPattern + {size/font_matrix} + [user_to_device_matrix] + cairo_t

 list of glyphs to the context


 * The [user_to_device_matrix] is in parentheses above because Pango 
   will have it and be able to pass it, however, it's fine if the
   results when it doesn't match the CTM of the cairo_t are 
 * The combination
    FcPattern + {size/font_matrix} + user_to_device_matrix

   shared between the two operations has two properties:

    - It corresponds to the PangoFont object, Pango creates this
      when doing layout and saves it bewteen computing metrics
      and drawing.

    - It corresponds to the key of the the glyph metrics cache
      in Cairo.

   So, it might be useful to actually have an exported object 
   from the Cairo API for this.

-------------- 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/20040923/20d185a4/attachment.pgp

More information about the cairo mailing list