Re: Pango: Accessing x-height/mean-line in Pango layout
- From: Olivier Fourdan <ofourdan redhat com>
- To: Behdad Esfahbod <behdad behdad org>
- Cc: gtk-i18n-list gnome org
- Subject: Re: Pango: Accessing x-height/mean-line in Pango layout
- Date: Wed, 19 Dec 2012 11:43:38 +0100
Hi Behdad,
Behdad Esfahbod said the following on 12/18/2012 06:19 PM:
On 12-12-18 04:32 AM, Olivier Fourdan wrote:
[...]
While this would mostly work, it's not perfect as the positioning is done
based on the logical rect, which may vary depending on the text, ie "Papa" and
"papa" would not have the same height. Beside, to improve the positioning,
it's been requested that the label is placed at the middle of the lowercase
characters.
That's not correct. "Papa" and "papa" have the same logical height. That's
the whole difference between logical and ink extents.
Yes, you're right, of course, but what I meant is that "Papa" and
"papa" do not have the same height /visually/ so using the logical
rect does not give the expected result.
Using the ink rect is not suitable either as "Papa", "Mama", "papa"
and "mama" would all have different heights.
Looking at typefaces definitions here [1] and [2], the positioning should be
ideally made based in between the baseline and the mean-line (baseline -
x-height).
I wonder, how can I access the x-height (or better the meanline) using the
Pango API? Is there a simple API for this?
Not directly. If you are using pangofc, you can obtain the FT_Face from the
PangoFont, then get the (I think) "OS/2" table of the font, and get the
x-height from in there.
Humm, that sounds quite complicated and platform specific, no?
So I took another approach to the problem.
Assuming Pango rightfully places the strikethrough, I retrieved the
position of the strikethrough with something like:
context = pango_layout_get_context (layout);
language = pango_language_get_default ();
desc = pango_layout_get_font_description (layout);
metrics = pango_context_get_metrics (context, desc, language);
baseline = pango_layout_get_baseline(layout);
strikethrough = pango_font_metrics_get_strikethrough_position
(metrics);
thickness = pango_font_metrics_get_underline_thickness (metrics);
return PANGO_PIXELS(baseline - strikethrough - thickness / 2);
And that gives (what I believe is) an acceptable result, at least from
my point of view.
Cheers,
Olivier
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]