3
<body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>
6
<table cellspacing=3 width=100%><tr><td bgcolor=#00000>
7
<table width=100%><tr><td bgcolor=c2fc20 align=center>
8
<a href=http://www.pygame.org>
9
<img src=../pygame_tiny.gif border=0 width=200 height=60></a><br>
10
<b>pygame documentation</b>
11
</td><td bgcolor=6aee28 align=center valign=top width=100%>
14
<a href=http://www.pygame.org>Home</a> ||
15
<a href=../index.html>Help Contents</a> ||
18
|| <a href=pygame.html>pygame</a> ||
19
<a href=pygame_cdrom.html>cdrom</a> ||
20
<a href=pygame_constants.html>constants</a> ||
21
<a href=pygame_display.html>display</a> ||
22
<a href=pygame_draw.html>draw</a> ||
23
<a href=pygame_event.html>event</a> ||<br>
24
|| <a href=pygame_font.html>font</a> ||
25
<a href=pygame_image.html>image</a> ||
26
<a href=pygame_joystick.html>joystick</a> ||
27
<a href=pygame_key.html>key</a> ||
28
<a href=pygame_mixer.html>mixer</a> ||
29
<a href=pygame_mixer_music.html>mixer_music</a> ||<br>
30
|| <a href=pygame_mouse.html>mouse</a> ||
31
<a href=pygame_movie.html>movie</a> ||
32
<a href=pygame_surfarray.html>surfarray</a> ||
33
<a href=pygame_time.html>time</a> ||
34
<a href=pygame_transform.html>transform</a> ||<br>
35
<br>|| <a href=CD.html>CD</a> ||
36
<a href=Channel.html>Channel</a> ||
37
<a href=Clock.html>Clock</a> ||
38
<a href=Font.html>Font</a> ||
39
<a href=Joystick.html>Joystick</a> ||
40
<a href=Movie.html>Movie</a> ||<br>
41
|| <a href=Rect.html>Rect</a> ||
42
<a href=Sound.html>Sound</a> ||
43
<a href=Surface.html>Surface</a> ||<br>
44
<br>|| <a href=pygame_cursors.html>cursors</a> ||
45
<a href=pygame_sprite.html>sprite</a> ||
46
<a href=pygame_version.html>version</a> ||<br>
49
</td></tr></table></td></tr></table>
51
<h2 align=center>Font</h2>
52
The font object is created only from <a href=pygame_font.html#Font>pygame.font.Font()</a>. Once a
53
font is created it's size and TTF file cannot be changed. The
54
Font objects are mainly used to <a href=#render>render()</a> text into a new Surface.
55
The Font objects also have a few states that can be set with
56
<a href=#set_underline>set_underline(bool)</a>, <a href=#set_bold>set_bold(bool)</a>, <a href=#set_italic>set_italic(bool)</a>. Each of
57
these functions contains an equivalent get_XXX() routine to find
58
the current state. There are also many routines to query the
59
dimensions of the text. The rendering functions work with both
60
normal python strings, as well as with unicode strings.
65
<tr><td><a href=#get_ascent>get_ascent</a></td><td> -
66
gets the font ascent</td></tr>
69
<tr><td><a href=#get_bold>get_bold</a></td><td> -
70
status of the bold attribute</td></tr>
73
<tr><td><a href=#get_descent>get_descent</a></td><td> -
74
gets the font descent</td></tr>
77
<tr><td><a href=#get_height>get_height</a></td><td> -
78
average height of font glyph</td></tr>
81
<tr><td><a href=#get_italic>get_italic</a></td><td> -
82
status of the italic attribute</td></tr>
85
<tr><td><a href=#get_linesize>get_linesize</a></td><td> -
86
gets the font recommended linesize</td></tr>
89
<tr><td><a href=#get_underline>get_underline</a></td><td> -
90
status of the underline attribute</td></tr>
93
<tr><td><a href=#render>render</a></td><td> -
94
render text to a new image</td></tr>
97
<tr><td><a href=#set_bold>set_bold</a></td><td> -
98
assign the bold attribute</td></tr>
101
<tr><td><a href=#set_italic>set_italic</a></td><td> -
102
assign the italic attribute</td></tr>
105
<tr><td><a href=#set_underline>set_underline</a></td><td> -
106
assign the underline attribute</td></tr>
109
<tr><td><a href=#size>size</a></td><td> -
110
size of rendered text</td></tr>
117
<a name=get_ascent><font size=+2><b>get_ascent
118
</b></font><br><font size=+1><tt>
119
Font.get_ascent() -> int
121
Returns the ascent for the font. The ascent is the number of
122
pixels from the font baseline to the top of the font.
125
<a name=get_bold><font size=+2><b>get_bold
126
</b></font><br><font size=+1><tt>
127
Font.get_bold() -> bool
129
Get the current status of the font's bold attribute
132
<a name=get_descent><font size=+2><b>get_descent
133
</b></font><br><font size=+1><tt>
134
Font.get_descent() -> int
136
Returns the descent for the font. The descent is the number of
137
pixels from the font baseline to the bottom of the font.
140
<a name=get_height><font size=+2><b>get_height
141
</b></font><br><font size=+1><tt>
142
Font.get_height() -> int
144
Returns the average size of each glyph in the font.
147
<a name=get_italic><font size=+2><b>get_italic
148
</b></font><br><font size=+1><tt>
149
Font.get_italic() -> bool
151
Get the current status of the font's italic attribute
154
<a name=get_linesize><font size=+2><b>get_linesize
155
</b></font><br><font size=+1><tt>
156
Font.get_linesize() -> int
158
Returns the linesize for the font. Each font comes with it's own
159
recommendation for the spacing number of pixels between each line
163
<a name=get_underline><font size=+2><b>get_underline
164
</b></font><br><font size=+1><tt>
165
Font.get_underline() -> bool
167
Get the current status of the font's underline attribute
170
<a name=render><font size=+2><b>render
171
</b></font><br><font size=+1><tt>
172
Font.render(text, antialias, fore_RGBA, [back_RGBA]) -> Surface
174
Render the given text onto a new image surface. The given text
175
can be standard python text or unicode. Antialiasing will smooth
176
the edges of the font for a much cleaner look. The foreground
177
and background color are both RGBA, the alpha component is ignored
178
if given. If the background color is omitted, the text will have a
179
transparent background.
181
Note that font rendering is not thread safe, therefore only one
182
thread can render text at any given time.
184
Also, rendering smooth text with underlines will crash with SDL_ttf
185
less that version 2.0, be careful.
188
<a name=set_bold><font size=+2><b>set_bold
189
</b></font><br><font size=+1><tt>
190
Font.set_bold(bool) -> None
192
Enables or disables the bold attribute for the font. Making the
193
font bold does not work as well as you expect.
196
<a name=set_italic><font size=+2><b>set_italic
197
</b></font><br><font size=+1><tt>
198
Font.set_italic(bool) -> None
200
Enables or disables the italic attribute for the font.
203
<a name=set_underline><font size=+2><b>set_underline
204
</b></font><br><font size=+1><tt>
205
Font.set_underline(bool) -> None
207
Enables or disables the underline attribute for the font.
210
<a name=size><font size=+2><b>size
211
</b></font><br><font size=+1><tt>
212
Font.size(text) -> width, height
214
Computes the rendered size of the given text. The text can be
215
standard python text or unicode. Changing the bold and italic
216
attributes can change the size of the rendered text.