[cairo] Pango + cairo

Owen Taylor otaylor at redhat.com
Tue Mar 15 06:36:22 PST 2005


On Mon, 2005-03-14 at 22:40 -0800, Keith Packard wrote:
> I'm trying to replace the 'toy' font code in libsvg-cairo with suitable 
> pango-ified bits.
> 
> I have the right text appearing on the screen, but have two unresolved 
> issues.
> 
> 1)	How to set the 'point' size of the font so that manipulations to 
> 	the cairo matrix will affect the glyph size.
> 
> 	Right now, I set the cairo matrix up and then call
> 	pango_font_description_set_size, but this leaves me with a fixed
> 	pixel size font.  Note that layout occurs in scaled units, which
> 	is mystifying to me.

I'm not sure I understand the problem ... if you use the same layout
and change the CTM, then you need to call pango_cairo_update_layout().
Pango can't know that the CTM changed. (*)

> 2)	How do I get the ascent from the layout?  I need to align the baseline
> 	of the text with the current point, while pango aligns the upper left 
> 	corner of the text box with the current point.

There are several ways of doing this ... if you know it's a single line,
you can do:

 PangoLayoutLine *line = pango_layout_get_lines (layout)->data;

and just draw the line rather than the layout ... the origin for lines
is the baseline. If you want to align multiple layouts on the first
line, then the "depth" of a layout can be computed again from the
first line as:

 pango_layout_line_get_extents (line, NULL, &logical_rect);
 depth = - logical_rect.y;  /* In pango units */

> Are these problems with the current cairo API?  Or am I just doing 
> something wrong?

Well, I can't see how the second is a problem with the Cairo API. 
The first? You could get *closer* to reasonable with a different
cairo_font_t API, at some expense, but I don't think closer to
reasonable is necessarily good. Many people don't have a good eye
for subtly ugly text.

Regards,
						Owen

(*) pango_cairo_show_layout() could call this function itself, and maybe
    the common case could be optimized to not dump the computed layout,
    but that fact that pango_layout_get_size() (and friends) would need
    this call is just going to be more confusing in the end.
-------------- 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/20050315/97ce2c8b/attachment.pgp


More information about the cairo mailing list