Download the source code: ft2-0.3.tar.gz
You need a recent version of the Freetype 2 library, which provides the include file ft2build.h. According to the file CHANGES in the Freetype sources, this file is available since Freetype version 2.0.2
The installation itself should be simple - just run:
python setup.py install
Note: I dont see the point, why I should try to copy the Freetype 2 documentation -- this would only introduce unnecessary errors ;) So I give only a short overview of the available attributes and methods. For details, please have a look into the Freetype 2 documentation.
Many integers used by the ft2 module are actually fixed point numbers. A more ambitious implementation could mimic these data types with specialized Python objects, including conversion from/to floats -- but I think that the advantages are not worth the effort of implementing all this stuff.
creates a new Freetype 2 library instance.
Library objects have no attributes and methods.
creates a new face instance.
library must be an ft2.Library object.
stream must be an IO stream (e.g., a file object or a StringIO object) providing the methods read, seek and tell.
index is the index of the face in the font file.
Attributes (all are read-only). The attribute names are the same as those defined in struct FT_Face_Rec:
The fields num_fixed_sizes, available_sizes of struct FT_Face_Rec are not accessible from ft2.Face instances. The data of the field charmaps is available via the object constructor ft2.CharMap(face, index)
getMetrics returns the data of FT_Face_Rec.size->metrics
For the freetype functions FT_Load_Char, FT_Render_Glyph and FT_Select_Charmap exist no corresponding ft2.Face methods. FT_Load_Char "only" avoids the lookup of a glyph index in the encoding vector, compared with FT_Load_Glyph. Selection of a character map is possible with setCharmap. FT_Render_Glyph causes a "metamorphosis" of the affected FT_Glyph instance. "Imitating" this behaviour in Python is of course possible, but would require a slightly more complicated __getattr__ method. I prefer to create a bitmap object that is cleanly separated from a Glyph object, while the original glyph object is not altered.
The glyph slot defined in FT_Face_Rec and related functions are not accessible. Use instances of ft.Glyph instead.
creates a new charmap instance. face must of type ft2.Face; index is an index into the list of the charmaps available for this face. The Python expression "index in range(face.num_charmaps)" must evaluate to true, otherwise the constructor raises an error.
encoding_as_string returns the encoding ID as a string. Example:
freetype.h defines the Unicode encoding as::
FT_ENC_TAG( FT_ENCODING_UNICODE, u, n, i, c )
encoding_as_string returns unic in this case.
No methods available
creates a new Glyph object for the glyph with index index.
creates a new Bitmap object. Note: internally, this is an FT_BitmapGlyph object. The attributes listed below are both from the FT_BitmapGlyph instance and from the FT_Bitmap instance belonging to the FT_Bitmap_Glyph instance.
bitmap is a string of length width * rows containing the bitmap data
None
Most constants defined in freetype2.h like FT_ENCODING_xxx are defined in the dictionary of the ft2 module.