Get the cap height with Pango metrics

Hello!
I needs some help on this, the question is in the title pretty much.
How can I compute the cap height of my Pango font?

Definition: https://en.wikipedia.org/wiki/Cap_height

PangoFontMetrics doesn’t have a field for this.

But you can use harfbuzz api to get it.

https://developer.gnome.org/pango/1.48/pango-Fonts.html#pango-font-get-hb-font

https://harfbuzz.github.io/harfbuzz-hb-ot-metrics.html#hb-ot-metrics-get-position

https://harfbuzz.github.io/harfbuzz-hb-ot-metrics.html#hb-ot-metrics-tag-t

Thanks for the tip Matthias.

I believe to have found a solution to estimate it using pure Pango API.
That is to calculate the ink extents of the “M” character, and take the height as the result.

While I’m not sure how well this works over a wide range of fonts, it did the trick in the cases I tested.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.