[cairo] How to measure Fonts

Kalle Vahlman kalle.vahlman at gmail.com
Mon Feb 5 09:06:53 PST 2007


2007/2/5, Behdad Esfahbod <behdad at behdad.org>:
> On Mon, 2007-02-05 at 03:44 -0500, Kalle Vahlman wrote:
> >
> >
> > I think that in the move_to(), your calculation is a bit wrong. For
> > example, for a font height of 10 pixels, it will end up in 15, while
> > you'll want it to be 5. You should first take the half of the height
> > of the rectangle (20/2) and then substract half of the height of the
> > font (extents.height/2) to get it on the correct level. So:
> >
> >   cairoContext->move_to(0, (20/2)-(extents.height/2));
> >
> > should take the current point to where you want it to be.
>
> This is true for PangoLayout objects that have origin at top left.  For
> cairo text api and PangoLayoutLine objects however, the origin is at the
> left of the baseline. So the calculations in the original message ar
> crrect.

Ah, I didn't know that (have only played around with the layout).
Thanks for correcting me :)

-- 
Kalle Vahlman, zuh at iki.fi
Powered by http://movial.fi
Interesting stuff at http://syslog.movial.fi


More information about the cairo mailing list