pygame documentation | || Home || Help Contents || || CD || Channel || Font || Joystick || Movie || Rect || Sound || || Surface || pygame || UserRect || cdrom || constants || cursors || display || || draw || event || font || image || joystick || key || mixer || || mixer_music || mouse || movie || surfarray || time || transform || version ||

## Font

The font object is created only from pygame.font.Font(). Once a font is created it's size and TTF file cannot be changed. The Font objects are mainly used to render() text into a new Surface. The Font objects also have a few states that can be set with set_underline(bool), set_bold(bool), set_italic(bool). Each of these functions contains an equivalent get_XXX() routine to find the current state. There are also many routines to query the dimensions of the text. The rendering functions work with both normal python strings, as well as with unicode strings.

get_ascent | - gets the font ascent
get_bold | - status of the bold attribute
get_descent | - gets the font descent
get_height | - average height of font glyph
get_italic | - status of the italic attribute
get_linesize | - gets the font recommended linesize
get_underline | - status of the underline attribute
render | - render text to a new image
set_bold | - assign the bold attribute
set_italic | - assign the italic attribute
set_underline | - assign the underline attribute
size | - size of rendered text

get_ascent
`Font.get_ascent() -> int`

Returns the ascent for the font. The ascent is the number of pixels from the font baseline to the top of the font.

get_bold
`Font.get_bold() -> bool`

Get the current status of the font's bold attribute

get_descent
`Font.get_descent() -> int`

Returns the descent for the font. The descent is the number of pixels from the font baseline to the bottom of the font.

get_height
`Font.get_height() -> int`

Returns the average size of each glyph in the font.

get_italic
`Font.get_italic() -> bool`

Get the current status of the font's italic attribute

get_linesize
`Font.get_linesize() -> int`

Returns the linesize for the font. Each font comes with it's own recommendation for the spacing number of pixels between each line of the font.

get_underline
`Font.get_underline() -> bool`

Get the current status of the font's underline attribute

render
`Font.render(text, antialias, fore_RGBA, [back_RGBA]) -> Surface`

Render the given text onto a new image surface. The given text can be standard python text or unicode. Antialiasing will smooth the edges of the font for a much cleaner look. The foreground and background color are both RGBA, the alpha component is ignored if given. If the background color is omitted, the text will have a transparent background.
Note that font rendering is not thread safe, therefore only one thread can render text at any given time.
Also, rendering smooth text with underlines will crash with SDL_ttf less that version 2.0, be careful.

set_bold
`Font.set_bold(bool) -> None`

Enables or disables the bold attribute for the font. Making the font bold does not work as well as you expect.

set_italic
`Font.set_italic(bool) -> None`

Enables or disables the italic attribute for the font.

set_underline
`Font.set_underline(bool) -> None`

Enables or disables the underline attribute for the font.

size
`Font.size(text) -> width, height`

Computes the rendered size of the given text. The text can be standard python text or unicode. Changing the bold and italic attributes can change the size of the rendered text.