为了获取字形宽度,我将TTF
字体转换为AFM
,然后解析AFM
文件的内容以获取每个字形的宽度。
由于技术上来说,fontforge
是从二进制TTF
文件中捕获字形宽度,然后基于AFM
标准模板创建AFM
字体文件。我想知道是否可能通过fontforge命令直接将TTF
文件转换为字形宽度列表?!?
$ fontforge -script scriptfile.pe {arguments}
$ fontforge -c "script-string" {arguments}
$ fontforge -lang={ff|py} -c "script-string"
在阅读了文档之后,我编写了我的脚本文件.pe:
Open($1, 1)
Select($2)
Print( GlyphInfo('Width') )
然后:
$ fontforge -script scriptfile.pe YourFont.ttf A
... # Some output truncated.
1298
打开一个字体。然后选择:'文件' > '执行脚本...'。输入:
Select('A')
Error(ToString(GlyphInfo('Width')))
点击“确定”。
首先是单个字形的宽度(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
>>>
f.selection.all()
也会选择非字形。访问不存在的字形将引发错误。
fontforge
将ttf
文件转换为字形宽度。 - Googlebottex
或者superusers
没有使用fontforge
作为捕捉字形属性的编程工具。fontforge
的高级用户就是程序员。 - Googlebot