为什么num\u glyphs与FT\u Get\u First\u Char/FT\u Get\u Next Ch枚举的glyphs数不匹配

2024-04-27 05:44:28 发布

您现在位置:Python中文网/ 问答频道 /正文

考虑下面的例子。它使用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_CharFT_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,
...

Tags: 函数selfget数字numfaceglyphsft