San*_*uuu 15 fonts ttf unicode
我需要自动验证哪些 Unicode 字符具有在 True Type Font 文件中为它们定义的实际字形。我该怎么做呢?当我在文本编辑器中打开 .ttf 文件时,我似乎无法找到有关如何理解我似乎得到的数字的信息。
otfinfo看起来很有希望:
-u, --unicode
Print each Unicode code point supported by the font, followed by
the glyph number representing that code point (and, if present,
the name of the corresponding glyph).
Run Code Online (Sandbox Code Playgroud)
例如 DejaVuSans-Bold 知道 fl 连字(?):
$ otfinfo -u /usr/share/fonts/TTF/DejaVuSans-Bold.ttf |grep ^uniFB02
uniFB02 4899 fl
Run Code Online (Sandbox Code Playgroud)
我找到了一个 python 库fonttools ( pypi ),它可以通过一些 python 脚本来完成。
这是一个简单的脚本,列出了所有指定字形的字体:
#!/usr/bin/env python3
from fontTools.ttLib import TTFont
import sys
char = int(sys.argv[1], base=0)
print("Looking for U+%X (%c)" % (char, chr(char)))
for arg in sys.argv[2:]:
try:
font = TTFont(arg)
for cmap in font['cmap'].tables:
if cmap.isUnicode():
if char in cmap.cmap:
print("Found in", arg)
break
except Exception as e:
print("Failed to read", arg)
print(e)
Run Code Online (Sandbox Code Playgroud)
第一个参数是代码点(十进制或带有 0x 的十六进制),其余是要查看的字体文件。
我没有费心让它对.ttc
文件起作用(它在某处需要一些额外的参数)。
注意:我首先尝试了 otfinfo 工具,但我只得到了基本的多语言平面字符(<= U+FFFF)。python 脚本找到扩展平面字符 OK。