Why does num_glyphs not match the number of glyphs enumerated by FT_Get_First_Char / FT_Get_Next_Char

大憨熊 提交于 2019-12-24 23:17:23

问题


Consider the following example. It uses freetype (through a python wrapper) to load a font and then counts the glyphs.

import freetype as FT
f = FT.Face('/usr/share/fonts/truetype/Hack-Regular.ttf')
f.num_glyphs
# 1573
len([*f.get_chars()])
# 1549

As you can see the number obtained by counting does not match the number reported by the library when asked directly.

Why?

Note: Knowledge of the python wrapper shouldn't be necessary to address this question. The python functions used here are thin wrappers around functions from the C-API. The relevant bits are

get_chars uses FT_Get_First_Char and FT_Get_Next_Char to loop through all (?) characters provided

    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 just pulls up its namesake

num_glyphs = property(lambda self: self._FT_Face.contents.num_glyphs,
...

来源:https://stackoverflow.com/questions/56715162/why-does-num-glyphs-not-match-the-number-of-glyphs-enumerated-by-ft-get-first-ch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!