How to get glyph widths by parsing a TTF font file?

前端 未结 1 1372
半阙折子戏
半阙折子戏 2021-01-24 05:21

For capturing the glyph widths of a TrueType font, I convert the corresponding TTF file by fontforge into AFM, which is in te

相关标签:
1条回答
  • 2021-01-24 06:15

    Assuming you mean advance widths, what you're interested in is the hmtx table. It's fairly straightforward to parse, as you can see the structure is:

    typedef struct  _longHorMetric {
        USHORT  advanceWidth;
        SHORT       lsb;
    }  longHorMetric;
    

    Of course, in order to parse the hmtx, you'll also need to know in general how to locate font tables, and you'll also need the numberOfHMetrics value from the hhea table and the font's numGlyphs from the maxp table. The structure of all of these is given in the links and should be fairly easy to parse in any language.

    0 讨论(0)
提交回复
热议问题