考虑下面的例子。它使用freetype
(通过python wrapper)加载字体,然后计算glyphs
import freetype as FT
f = FT.Face('/usr/share/fonts/truetype/Hack-Regular.ttf')
f.num_glyphs
# 1573
len([*f.get_chars()])
# 1549
如你所见,通过计数得到的数字与图书馆直接询问时报告的数字不符
为什么
注意:解决这个问题不需要了解python包装器。这里使用的python函数是对C-API函数的精简包装。相关位为
get_chars
使用FT_Get_First_Char
和FT_Get_Next_Char
循环遍历提供的所有(?)字符
charcode, agindex = self.get_first_char()
yield charcode, agindex
while agindex != 0:
charcode, agindex = self.get_next_char(charcode, 0)
yield charcode, agindex
num_glyphs
只是调出了它的名字
num_glyphs = property(lambda self: self._FT_Face.contents.num_glyphs,
...
目前没有回答
相关问题 更多 >
编程相关推荐