问题
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