我如何从Linux上的TrueType或嵌入式OpenType字体中提取支持的Unicode字符列表?
是否有工具或库可用于处理.ttf或.eot文件并构建字体提供的代码点列表(例如U+0123,U+1234等)?
#!/usr/bin/env python
import sys
from fontTools.ttLib import TTFont
with TTFont(sys.argv[1], 0, ignoreDecompileErrors=True) as ttf:
for x in ttf["cmap"].tables:
for (_, code) in x.cmap.items():
point = code.replace('uni', '\\u').lower()
print("echo -e '" + point + "'")
一种不安全但简单的查看方式:
python font.py my-font.ttf | sh
感谢Janus(https://dev59.com/i2855IYBdhLWcg3wPBtx#19438403)提供上面的答案。
FreeType项目提供演示应用程序,其中一个演示称为“ftdump”。然后,您可以执行:“ftdump -V path-to-the-font-file”,并获得您要查找的内容。要查看源代码,您可以在此处关闭源:https://www.freetype.org/developer.html
在Ubuntu上,可以使用“sudo apt install freetype2-demos”进行安装
注意:请尝试使用“-c”而不是“-V”。我看到参数在版本之间已更改。
from fontTools.ttLib import TTFont
def get_font_characters(font_path):
with TTFont(font_path) as font:
characters = {chr(y[0]) for x in font["cmap"].tables for y in x.cmap.items()}
return characters
fc-list :charset=1234
命令,并仔细检查其输出结果...(对我来说有效,它显示Gentium的字符集为2082但不是2161)。 - mirabilos