FontForge 包括两个解释器,因此您可以编写脚本来修改字体。其中一种解释器是 Python(首选),一种是遗留语言。 Fontforge 嵌入了 Python,但也可以将 Fontforge 构建为 Python 扩展。
那么你会用什么:Python or 遗留语言?
什么接口:命令行 or GUI or Python 扩展?
命令行和遗留语言
该脚本可以位于文件中,也可以只是作为参数呈现的字符串。您可能需要通过 -lang 参数指定要使用的解释器。看命令行参数 http://fontforge.org/cliargs.html.
$ fontforge -script scriptfile.pe {arguments}
$ fontforge -c "script-string" {arguments}
$ fontforge -lang={ff|py} -c "script-string"
扫描后文档 http://fontforge.org/scripting-alpha.html#GlyphInfo我写了我的 scriptfile.pe:
Open($1, 1)
Select($2)
Print( GlyphInfo('Width') )
Than:
$ fontforge -script scriptfile.pe YourFont.ttf A
... # Some output truncated.
1298
从 GUI 执行脚本
打开字体。然后选择:“文件”>“执行脚本...”。进入:
Select('A')
Error(ToString(GlyphInfo('Width')))
单击“确定”。
Python 扩展
首先是单个字形的宽度(docs http://fontforge.org/python.html):
>>> import fontforge
>>> f = fontforge.open("YourFont.ttf")
>>> f['A'].width
1298
这是您问题的答案。对于每个字形,编码索引、名称和宽度:
>>> for i in f.selection.all():
... try:
... name, width = f[i].glyphname, f[i].width
... print i, name, width
... except:
... pass
...
0 uni0009 0
2 uni0002 0
13 nonmarkingreturn 510
# ... Truncated ...
65707 germandbls.smcp 2266
>>>
注意:我使用了 try/ except 因为不知何故f.selection.all()
也选择非字形。访问不存在的字形将引发错误。