What's the formula to calculate the height of a given text?

234 Views Asked by At

OTF documentation says:

USE_TYPO_METRICS If set, it is strongly recommended that applications use OS/2.sTypoAscender - OS/2.sTypoDescender + OS/2.sTypoLineGap as the default line spacing for this font.

Dejavu-serif-condensed-italic is a font that has set this bit, so the given formula works.

But all other fonts I've tested so far have not set it.

When I tried a way to calculate the height it is working for one font, but not for the others. Then I've used a different way, that worked for another font, but not for the font it worked before - and so on.

Roboto-Regular

This is Roboto-Regular, the formula usWinAscent + usWinDescent is working with it, as you can see on the image.

OpenSans-Regular

This picture shows OpenSans-Regular with the same calculation; here the result does not fit with the text.

JetBrainsMono-Regular

The picture shows the calculated height for JetBrainsMono-Regular.

An interesting point of this font is, that the line gap from the hhea or os2 table is 0. YMin, descender, sTypoDescender and usWinDescent have the value 300 or -300. YMax, ascender, sTypoAscender and usWinAscent share the absolute value 1020.

So all logical calculations lead to 1320 font design units. By testing it manually, the result should be 1300 to return a correct line height.

So what's an accurate formula to calculate the height of a line?

0

There are 0 best solutions below