[cairo] “text align center” Code Sample
Bill Spitzak
spitzak at gmail.com
Tue Nov 17 14:55:04 PST 2015
I absolutely agree that using the font extents for this works better.
On Tue, Nov 17, 2015 at 1:38 PM, Lawrence D'Oliveiro <
ldo at geek-central.gen.nz> wrote:
> 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
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20151117/76211986/attachment.html>
More information about the cairo
mailing list