如何通过解析TTF字体文件获取字形宽度? [英] How to get glyph widths by parsing a TTF font file?

查看:1788
本文介绍了如何通过解析TTF字体文件获取字形宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关捕获的TrueType 字体的字形宽度,我通过<$ C $转换成相应的 TTF 文件C> fontforge 到 AFM ,这是在文本格式(而不是二进制)。然后,解析文本文件捕获字形宽度。

For capturing the glyph widths of a TrueType font, I convert the corresponding TTF file by fontforge into AFM, which is in text format (not binary). Then, parsing the text file to capture the glyph widths.

应该有直接分析二进制 TTF 文件捕获字形宽度更简单的方法。

There should be easier way to directly parse the binary TTF file to capture the glyph widths.

我AP preciate的shell脚本或C的策略,但任何编程语言是确定的,因为思想是关键,codeS可以适应。

I appreciate a strategy for shell script or C, but any programming language is OK, as the idea is the key, and codes can be adapted.

推荐答案

假设你的意思是超前宽度,你感兴趣的是的 hmtx表。这是相当简单的解析,正如你所看到的结构是:

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;

当然,为了解析hmtx,你还需要在一般的如何定位字体表的,你还需要在 numberOfHMetrics 从hhea表格和字体的 numGlyphs 从MAXP表值。所有这些结构中的链接,并给出应该很容易在任何语言解析

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.

这篇关于如何通过解析TTF字体文件获取字形宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆