Search code examples
fontsheightfont-sizetruetype

How do I know the actual letter size of a TrueType font?


Which TrueType font table stores information about the actual character layout. That is, the size in pixels or points with which the symbol is displayed on the monitor.

For reference: I am working with font tables using the fontTools library.


Solution

  • Glyphs' heights are not specified anywhere (at least, not for a horizontal layout). Probably, what you're looking for is sxHeight from the 'OS/2' table (the distance between the baseline and the approximate height of non-ascending lowercase letters). There's also sxCapHeight field (for uppercase letters). Though, those fields were defined in the second version of the OS/2 table.

    To find out the glyph's height, you can simply subtract its lowest point from the highest one (i.e. glyph height = yMax - yMin). yMax and yMin are stored in Glyph Header in the 'glyf' table (for TrueType outlines).

    If you need glyphs' widths, 'hmtx' table contains an advance width for every glyph in a font, as well as left-side bearing (right-side bearing is not stored, when needed it has to be computed from left-side-bearing + maxX - minX). 'hhea' table contains a maximum advance width value (advanceWidthMax).