这就是“
fontTools
'包,其中包含用于读取和查询TrueType字体的python类。这是可能的
from fontTools.ttLib import TTFont
f = TTFont('/path/to/font/arial.ttf')
print(f.getGlyphOrder()) # a list of the glyphs in the order
# they appear
print(f.getReversedGlyphMap() # mapping from glyph names to Id
id = f.getGlyphID('Euro') # The internal code for the Euro character,
# Raises attribute error if the character
# isn't present.
f.getTableData('cmap')
一种字体可以有多个cmap表。这个
freetype interface
也可以读取ttf文件。可以使用freetype尝试渲染字符,并查看结果:这会很慢。
import freetype as ft
face = ft.Face('arial.ttf')
face.set_size(25*32)
face.load_char(â½)
bitmap = face.glyph.bitmap.buffer
if bitmap == [255, 255, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 255, 255]:
print("No interobang in the font")