Search code examples
freetypefreetype2

How to get height of font in Freetype2


In Freetype2, We are using the below formula to calculate the font height for the given size. height = (int)((point_size / face->units_per_EM) * (face->ascender - face->descender)); where as point_size is user supplied data.

But for some fonts it gives wrong data. Could anyone help to find the correct formula to find the correct height of font face for given point? (Not for individual glyph).


Solution

  • Below is the method used in cocos2d-x:

    _lineHeight = static_cast((face->size->metrics.ascender - face->size->metrics.descender) >> 6);

    Most fonts are ok. For the not-ok case, I calibrate the value after get GlyphBitmap's height, and then use the larger one as the max line height.