pygame / docs / reST / ref / freetype.rst


--- Note that some features may change before a formal release

This module allows for rendering all font formats supported by FreeType, namely TTF, Type1, CFF, OpenType, SFNT, PCF, FNT, BDF, PFR and Type42 fonts. It can render any UTF-32 character in a font file.

This module is optional, and replaces all of the functionality of the original 'font' module, whilst expanding it. This module depends in no way on the SDL_ttf library.

You should test that :mod:`pygame.freetype` is initialized before attempting to use the module; if the module is available and loaded, it will be automatically initialized by pygame.init()

Most of the work done with fonts is done by using the actual Font objects. The module by itself only has routines to initialize itself and create Font objects with pygame.freetype.Font().

You can load fonts from the system by using the pygame.freetype.SysFont() function. There are a few other functions to help lookup the system fonts.

Pygame comes with a builtin default font. This can always be accessed by passing None as the font name to the Font constructor.

'file' can be either a string representing the font's filename, a file-like object containing the font, or None; in this last case the default, built-in font will be used.

Optionally, a *ptsize* argument may be specified to set the default size in points which will be used to render the font. Such size can also be specified manually on each method call. Because of the way the caching system works, specifying a default size on the constructor doesn't imply a performance gain over manually passing the size on each function call.

If the font file has more than one face, the *index* argument may be specified to specify which face index to load. Defaults to 0; font loading will fail if the given index is not contained in the font.

The 'style' argument will set the default style (italic, underline, bold) used to draw this font. This style may be overriden on any Font.render() call.