pygame2.sdlttf – basic SDL_ttf wrapper module

Basic SDL_ttf wrapper module

Module Functions

pygame2.sdlttf.get_compiled_version() -> (int, int, int)

Gets the SDL_ttf version pygame2 was compiled against as three-value tuple.

This version is built at compile time. It can be used to detect which features may not be available through Pygame, if it is used as precompiled package using a different version of the SDL_ttf library.

pygame2.sdlttf.get_error() → :exc:`pygame2.Error`

Gets the last pygame2.Error occured.

SDL_ttf maintains an internal error message. This message will usually be given to you when a pygame2.Error is raised. You will rarely need to call this function.

pygame2.sdlttf.get_version() -> (int, int, int)

Gets the SDL version pygame2 currently uses as three-value tuple.

This version is detected at runtime. It can be used to detect which features may not be available through Pygame, if it is used as precompiled package using a different version of the SDL library.

pygame2.sdlttf.init() → None
Initializes the SDL_ttf library.
pygame2.sdlttf.quit() → None

Shuts down the SDL_ttf library.

After calling this function, you should not invoke any class, method or function related to the sdlttf module as they are likely to fail or might give unpredictable results.

pygame2.sdlttf.set_byte_swapped_unicode(swapped) → None
Sets, whether unicode text should be handled with a swapped BOM.
pygame2.sdlttf.was_init() → bool
Returns, whether the the SDL_ttf library is initialized.

Font

class pygame2.sdlttf.Font(file, size[, index]) → Font

Creates a new Font from a TTF font file.

Creates a new Font from a TTF font file using the specified size in points. If the font features different faces, they can be chosen using the optional index.

Note

The file object must support binary read and write access. This is especially important for Python 3.x users.

Attributes

Font.ascent
Gets the ascent of the Font.
Font.descent
Gets the descent of the Font.
Font.faces
Gets the amount of available font faces.
Font.family_name
Gets the font face family name.
Font.height
Gets the height of the Font.
Font.is_fixed_width
Gets whether the chosen font face is a fixed width one.
Font.line_skip
Gets the line skip of the Font.
Font.style
Gets or sets the style of the font. The style can be a valid value of the style constants in the pygame2.sdlttf.constants module.
Font.style_name
Gets the currently set font style name.

Methods

Font.get_glyph_metrics(text) → [(int,int,int,int,int), ...]

Gets the glyph metrics of a string.

Gets the glyph metrics for each individual character of a string. The metrics returned for each character consist of the xMin, yMin, xMax, yMax and advance values.

http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html contains a detailed description of those values.

If no suitable character for getting the glyph extents could be found in the font, a None value will be used instead of a 5-value tuple.

Font.get_size(text) → int, int
Gets the size of a text for this Font.
Font.render(text, fgcolor[, bgcolor, renderflag]) → :class:`pygame2.sdl.video.Surface`

Renders a text to a pygame2.sdl.video.Surface.

Renders the specified text to a pygame2.sdl.video.Surface. The text will have the chosen foreground color for the glyphs. The optional bgcolor argument denotes the background color to use for the returned pygame2.sdl.video.Surface, if - and only if - the renderflag is RENDER_SHADED (the default). Otherwise the pygame2.sdl.video.Surface will be transparent except for the rendered glyphs.

The renderflag argument can be set to one of the rendering constants of the pygame2.sdlttf.constants module.