[cairo] Writing a PangoLayoutLine on a line in cairo

Owen Taylor otaylor at redhat.com
Sat Feb 3 11:59:32 PST 2007

On Sat, 2007-02-03 at 21:48 +0200, Dov Grobgeld wrote:
> I
> In pango_cairo_show_layout() on the other hand, the layout logical
> upper left corner is aligned at the current cairo point when drawing,
> and I could not find any PangoLayout call that gets the distance from
> the top of the logical rectangle to the baseline position. Is this a
> bug, or did I miss something?

Well, one easy way to do it is to just draw the first line of the
layout instead of the entire layout - since the y origin when drawing a
single line is at the baseline of the line.

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

If you want to draw an entire layout with the first line positioned
at a particular y position, then you'd need to get the ascent of the
first line:

 PangoRectangle rect;
 pango_layout_line_get_extents(line, NULL, &rect); 
 double ascent = (double)PANGO_ASCENT(rect) / PANGO_SCALE;

It might be handy to have a convenience function to get this -
pango_layout_get_depth(), say, to steal terminology from TeX.

					- Owen

More information about the cairo mailing list