如何找出在 TTF 文件中定义了哪些 unicode 代码点?

San*_*uuu 15 fonts ttf unicode

我需要自动验证哪些 Unicode 字符具有在 True Type Font 文件中为它们定义的实际字形。我该怎么做呢?当我在文本编辑器中打开 .ttf 文件时,我似乎无法找到有关如何理解我似乎得到的数字的信息。

mic*_*has 8

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)

  • @Sanuuu,“-u”选项没有出现在“--help”中,但似乎仍然存在。然而(至少在 Debian 2.105 版本中)它似乎只列出了基本平面(最多 U+FFFF)。“-g”选项了解扩展平面,但这并不适用于所有字体。 (2认同)
  • 仅供参考:在 mac 上,可以使用“brew install lcdf-typetools”安装“otfinfo” (2认同)

Jan*_*dec 8

我找到了一个 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。