Re: “text align center” Code Sample
Bill Spitzak <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <CAL-8oAgUG5oqCJK47GkPp1kwBsUURdG3G2FMkALhAqzZy9jS+g@mail.gmail.com> |
I absolutely agree that using the font extents for this works better. On Tue, Nov 17, 2015 at 1:38 PM, Lawrence D'Oliveiro < [email protected]> 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 > [email protected] > http://lists.cairographics.org/mailman/listinfo/cairo -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo