FontForge 包含两个解释器,因此您可以编写脚本来修改字体。其中一个解释器是 Python(首选),一个是遗留语言。 Fontforge 嵌入了 Python,但也可以将 Fontforge 构建为 Python 扩展。
那么您将使用什么:Python 或 传统语言?
什么界面:命令行或GUI或Python扩展?
命令行和传统语言
脚本可以在文件中,也可以只是作为参数呈现的字符串。您可能需要指定与 -lang 参数一起使用的解释器。见Command Line Arguments。
$ fontforge -script scriptfile.pe {arguments}
$ fontforge -c "script-string" {arguments}
$ fontforge -lang={ff|py} -c "script-string"
扫描documentation后我写了我的scriptfile.pe:
Open($1, 1)
Select($2)
Print( GlyphInfo('Width') )
比:
$ fontforge -script scriptfile.pe YourFont.ttf A
... # Some output truncated.
1298
从 GUI 执行脚本
打开一个字体。然后选择:“文件”>“执行脚本...”。输入:
Select('A')
Error(ToString(GlyphInfo('Width')))
点击“确定”。
Python 扩展
首先是单个字形的宽度 (docs):
>>> 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() 也选择了非字形。访问不存在的字形会引发错误。