The ft2font module provides a Python interface to the FT2Font C API.
get_charmap is one of the methods in this API as is set_charmap. A
font can have multiple character maps.
get_charmap() returns the default one. Others can be specified
by providing an argument to get_charmap(). To add a new charmap
to the font, you must first find out what charmaps it contains,
so get_charmap is needed for this.
I disagree. Method FT2Font::get_charmap doesn't return the list of
available character maps; it returns a dictionary mapping glyph
indices to character codes in the *current character map*.
You wrote "other character maps can be specified by providing an
argument to get_charmap", but method FT2Font::get_charmap doesn't
accept any parameter (I looked at line 1208 of file ft2font.cpp).
In addition, changing this method to return the reverse mapping would
violate the rule of least surprise.
Yes, but in my opinion, this is the current solution that violates
"the rule of least surprise".
Method FT2Font::get_charmap calls two important methods of FreeType:
FT_Get_First_Char and FT_Get_Next_Char. These two methods are used to
parse all character codes from first to last in the current character
map, and returning corresponding glyphs.
You can read those methods description and an example at this URL:
Reading this example, it seems apparent the "least surprising
solution" is a mapping from character codes to glyph indices, doesn't
Note that creating the reverse dict is easy in Python.
Yep, it's why we love programming in Python!
On 11/6/06, Paul Barrett <pebarrett@...149...> wrote: