“text align center” Code Sample
Lawrence D'Oliveiro <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Organization | Geek Central |
| Message-ID | <[email protected]> |
This code sample <http://cairographics.org/samples/text_align_center/>
is supposed to show how to center text around a position both
horizontally and vertically. I don’t think the vertical centring looks
good.
If you want to do accurate vertical centring, the formula I came up
with is
text_mid_y = (- 2 * text_extents.y_bearing - text_extents.height) / 2
However, I find that it looks a bit better overall to do the vertical
centring based on the font metrics, rather than that of the specific
text:
font_mid_y = (font_extents.ascent - font_extents.descent) / 2
You can compare the different effects here
<http://default-cube.deviantart.com/art/Text-Vert-Align-520839470>, and
see if you agree or not.
--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo