~ubuntu-branches/ubuntu/maverick/pygame/maverick

« back to all changes in this revision

Viewing changes to docs/ref/font.html

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-01-14 17:02:11 UTC
  • mfrom: (1.3.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100114170211-21eop2ja7mr9vdcr
Tags: 1.9.1release-0ubuntu1
* New upstream version (lp: #433304)
* debian/control:
  - build-depends on libportmidi-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
<html>
3
 
<title>font - Pygame Documentation</title>
4
 
<body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>
5
 
 
6
 
 
7
 
<table cellpadding=0 cellspacing=0 border=0 style='border: 3px solid black;' width='100%'>
8
 
<tr>
9
 
<td bgcolor='#c2fc20' style='padding: 6px;' align=center valign=center><a href='http://www.pygame.org/'><img src='../pygame_tiny.gif' border=0 width=200 height=60></a><br><b>pygame documentation</b></td>
10
 
<td bgcolor='#6aee28' style='border-left: 3px solid black; padding: 6px;' align=center valign=center>
11
 
        ||&nbsp;
12
 
        <a href=http://www.pygame.org>Pygame Home</a> &nbsp;||&nbsp;
13
 
        <a href=../index.html>Help Contents</a> &nbsp;||
14
 
        <a href=index.html>Reference Index</a> &nbsp;||
15
 
        <br>&nbsp;<br>
16
 
        
17
 
<a href="cdrom.html">Cdrom</a>&nbsp;||&nbsp;
18
 
<a href="color.html">Color</a>&nbsp;||&nbsp;
19
 
<a href="cursors.html">Cursors</a>&nbsp;||&nbsp;
20
 
<a href="display.html">Display</a>&nbsp;||&nbsp;
21
 
<a href="draw.html">Draw</a>&nbsp;||&nbsp;
22
 
<a href="event.html">Event</a>&nbsp;||&nbsp;
23
 
<a href="font.html">Font</a>&nbsp;||&nbsp;
24
 
<a href="image.html">Image</a>&nbsp;||&nbsp;
25
 
<a href="joystick.html">Joystick</a>&nbsp;||&nbsp;
26
 
<a href="key.html">Key</a>&nbsp;||&nbsp;
27
 
<a href="mask.html">Mask</a>&nbsp;||&nbsp;
28
 
<a href="mixer.html">Mixer</a>&nbsp;||&nbsp;
29
 
<a href="mouse.html">Mouse</a>&nbsp;||&nbsp;
30
 
<a href="movie.html">Movie</a>&nbsp;||&nbsp;
31
 
<a href="music.html">Music</a>&nbsp;||&nbsp;
32
 
<a href="overlay.html">Overlay</a>&nbsp;||&nbsp;
33
 
<a href="pixelarray.html">Pixelarray</a>&nbsp;||&nbsp;
34
 
<a href="pygame.html">Pygame</a>&nbsp;||&nbsp;
35
 
<a href="rect.html">Rect</a>&nbsp;||&nbsp;
36
 
<a href="scrap.html">Scrap</a>&nbsp;||&nbsp;
37
 
<a href="sndarray.html">Sndarray</a>&nbsp;||&nbsp;
38
 
<a href="sprite.html">Sprite</a>&nbsp;||&nbsp;
39
 
<a href="surface.html">Surface</a>&nbsp;||&nbsp;
40
 
<a href="surfarray.html">Surfarray</a>&nbsp;||&nbsp;
41
 
<a href="time.html">Time</a>&nbsp;||&nbsp;
42
 
<a href="transform.html">Transform</a>
43
 
</td></tr></table>
44
 
<br>
45
 
 
46
 
 
47
 
<a name="pygame.font">
48
 
<big><b>pygame.font</big></b><br><ul>
49
 
  <i>pygame module for loading and rendering fonts</i><br>
50
 
<ul><small><table>
51
 
  <tr><td><a href="font.html#pygame.font.init">pygame.font.init</a> - <font size=-1>initialize the font module</font></td><td>initialize the font module</td></tr>
52
 
  <tr><td><a href="font.html#pygame.font.quit">pygame.font.quit</a> - <font size=-1>uninitialize the font module</font></td><td>uninitialize the font module</td></tr>
53
 
  <tr><td><a href="font.html#pygame.font.get_init">pygame.font.get_init</a> - <font size=-1>true if the font module is initialized</font></td><td>true if the font module is initialized</td></tr>
54
 
  <tr><td><a href="font.html#pygame.font.get_default_font">pygame.font.get_default_font</a> - <font size=-1>get the filename of the default font</font></td><td>get the filename of the default font</td></tr>
55
 
  <tr><td><a href="font.html#pygame.font.get_fonts">pygame.font.get_fonts</a> - <font size=-1>get all available fonts</font></td><td>get all available fonts</td></tr>
56
 
  <tr><td><a href="font.html#pygame.font.match_font">pygame.font.match_font</a> - <font size=-1>find a specific font on the system</font></td><td>find a specific font on the system</td></tr>
57
 
  <tr><td><a href="font.html#pygame.font.SysFont">pygame.font.SysFont</a> - <font size=-1>create a Font object from the system fonts</font></td><td>create a Font object from the system fonts</td></tr>
58
 
  <tr><td><a href="font.html#pygame.font.Font">pygame.font.Font</a> - <font size=-1>create a new Font object from a file</font></td><td>create a new Font object from a file</td></tr>
59
 
</table></small></ul>
60
 
<p>The font module allows for rendering TrueType fonts into a new Surface object. This module is optional and requires SDL_ttf as a dependency. You should test that <tt>pygame.font</tt> is available and initialized before attempting to use the module. </p>
61
 
<p>Most of the work done with fonts are done by using the actual Font objects. The module by itself only has routines to initialize the module and create Font objects with <tt><a href="font.html#pygame.font.Font">pygame.font.Font</a> - <font size=-1>create a new Font object from a file</font></tt>. </p>
62
 
<p>You can load fonts from the system by using the <tt><a href="font.html#pygame.font.SysFont">pygame.font.SysFont</a> - <font size=-1>create a Font object from the system fonts</font></tt> function. There are a few other functions to help lookup the system fonts. </p>
63
 
<p>Pygame comes with a builtin default font. This can always be accessed by passing None as the font name. </p>
64
 
<!--COMMENTS:pygame.font--> &nbsp;<br> 
65
 
 
66
 
 
67
 
<a name="pygame.font.init">
68
 
<big><b>pygame.font.init</big></b><br><ul>
69
 
  <i>initialize the font module</i><br>
70
 
  <tt>pygame.font.init(): return None</tt><br>
71
 
<p>This method is called automatically by <tt><a href="pygame.html#pygame.init">pygame.init</a> - <font size=-1>initialize all imported pygame modules</font></tt>. It initializes the font module. The module must be initialized before any other functions will work. </p>
72
 
<p>It is safe to call this function more than once. </p>
73
 
<!--COMMENTS:pygame.font.init--> &nbsp;<br> 
74
 
<br></ul>
75
 
 
76
 
 
77
 
<a name="pygame.font.quit">
78
 
<big><b>pygame.font.quit</big></b><br><ul>
79
 
  <i>uninitialize the font module</i><br>
80
 
  <tt>pygame.font.quit(): return None</tt><br>
81
 
<p>Manually uninitialize SDL_ttf's font system. This is called automatically by <tt><a href="pygame.html#pygame.quit">pygame.quit</a> - <font size=-1>uninitialize all pygame modules</font></tt>. </p>
82
 
<p>It is safe to call this function even if font is currently not initialized. </p>
83
 
<!--COMMENTS:pygame.font.quit--> &nbsp;<br> 
84
 
<br></ul>
85
 
 
86
 
 
87
 
<a name="pygame.font.get_init">
88
 
<big><b>pygame.font.get_init</big></b><br><ul>
89
 
  <i>true if the font module is initialized</i><br>
90
 
  <tt>pygame.font.get_init(): return bool</tt><br>
91
 
<p>Test if the font module is initialized or not. </p>
92
 
<!--COMMENTS:pygame.font.get_init--> &nbsp;<br> 
93
 
<br></ul>
94
 
 
95
 
 
96
 
<a name="pygame.font.get_default_font">
97
 
<big><b>pygame.font.get_default_font</big></b><br><ul>
98
 
  <i>get the filename of the default font</i><br>
99
 
  <tt>pygame.font.get_default_font(): return string</tt><br>
100
 
<p>Return the filename of the system font. This is not the full path to the file. This file can usually be found in the same directory as the font module, but it can also be bundled in separate archives. </p>
101
 
<!--COMMENTS:pygame.font.get_default_font--> &nbsp;<br> 
102
 
<br></ul>
103
 
 
104
 
 
105
 
<a name="pygame.font.get_fonts">
106
 
<big><b>pygame.font.get_fonts</big></b><br><ul>
107
 
  <i>get all available fonts</i><br>
108
 
  <tt>pygame.font.get_fonts(): return list of strings</tt><br>
109
 
<p>Returns a list of all the fonts available on the system. The names of the fonts will be set to lowercase with all spaces and punctuation removed. This works on most systems, but some will return an empty list if they cannot find fonts. </p>
110
 
<!--COMMENTS:pygame.font.get_fonts--> &nbsp;<br> 
111
 
<br></ul>
112
 
 
113
 
 
114
 
<a name="pygame.font.match_font">
115
 
<big><b>pygame.font.match_font</big></b><br><ul>
116
 
  <i>find a specific font on the system</i><br>
117
 
  <tt>pygame.font.match_font(name, bold=False, italic=False): return path</tt><br>
118
 
<p>Returns the full path to a font file on the system. If bold or italic are set to true, this will attempt to find the correct family of font. </p>
119
 
<p>The font name can actually be a comma separated list of font names to try. If none of the given names are found, None is returned. </p>
120
 
<p>Example: </p>
121
 
<pre>    print pygame.font.match_font('bitstreamverasans')
122
 
    # output is: /usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf
123
 
    # (but only if you have Vera on your system)
124
 
</pre>
125
 
<!--COMMENTS:pygame.font.match_font--> &nbsp;<br> 
126
 
<br></ul>
127
 
 
128
 
 
129
 
<a name="pygame.font.SysFont">
130
 
<big><b>pygame.font.SysFont</big></b><br><ul>
131
 
  <i>create a Font object from the system fonts</i><br>
132
 
  <tt>pygame.font.SysFont(name, size, bold=False, italic=False): return Font</tt><br>
133
 
<p>Return a new Font object that is loaded from the system fonts. The font will match the requested bold and italic flags. If a suitable system font is not found this will fallback on loading the default pygame font. The font name can be a comma separated list of font names to look for. </p>
134
 
<!--COMMENTS:pygame.font.SysFont--> &nbsp;<br> 
135
 
<br></ul>
136
 
 
137
 
 
138
 
<a name="pygame.font.Font">
139
 
<big><b>pygame.font.Font</big></b><br><ul>
140
 
  <i>create a new Font object from a file</i><br>
141
 
  <tt>pygame.font.Font(filename, size): return Font</tt><br>
142
 
  <tt>pygame.font.Font(object, size): return Font</tt><br>
143
 
<ul><small><table>
144
 
  <tr><td><a href="font.html#Font.render">Font.render</a> - <font size=-1>draw text on a new Surface</font></td><td>draw text on a new Surface</td></tr>
145
 
  <tr><td><a href="font.html#Font.size">Font.size</a> - <font size=-1>determine the amount of space needed to render text</font></td><td>determine the amount of space needed to render text</td></tr>
146
 
  <tr><td><a href="font.html#Font.set_underline">Font.set_underline</a> - <font size=-1>control if text is rendered with an underline</font></td><td>control if text is rendered with an underline</td></tr>
147
 
  <tr><td><a href="font.html#Font.get_underline">Font.get_underline</a> - <font size=-1>check if text will be rendered with an underline</font></td><td>check if text will be rendered with an underline</td></tr>
148
 
  <tr><td><a href="font.html#Font.set_bold">Font.set_bold</a> - <font size=-1>enable fake rendering of bold text</font></td><td>enable fake rendering of bold text</td></tr>
149
 
  <tr><td><a href="font.html#Font.get_bold">Font.get_bold</a> - <font size=-1>check if text will be rendered bold</font></td><td>check if text will be rendered bold</td></tr>
150
 
  <tr><td><a href="font.html#Font.set_italic">Font.set_italic</a> - <font size=-1>enable fake rendering of italic text</font></td><td>enable fake rendering of italic text</td></tr>
151
 
  <tr><td><a href="font.html#Font.metrics">Font.metrics</a> - <font size=-1>Gets the metrics for each character in the pased string.</font></td><td>Gets the metrics for each character in the pased string.</td></tr>
152
 
  <tr><td><a href="font.html#Font.get_italic">Font.get_italic</a> - <font size=-1>check if the text will be rendered italic</font></td><td>check if the text will be rendered italic</td></tr>
153
 
  <tr><td><a href="font.html#Font.get_linesize">Font.get_linesize</a> - <font size=-1>get the line space of the font text</font></td><td>get the line space of the font text</td></tr>
154
 
  <tr><td><a href="font.html#Font.get_height">Font.get_height</a> - <font size=-1>get the height of the font</font></td><td>get the height of the font</td></tr>
155
 
  <tr><td><a href="font.html#Font.get_ascent">Font.get_ascent</a> - <font size=-1>get the ascent of the font</font></td><td>get the ascent of the font</td></tr>
156
 
  <tr><td><a href="font.html#Font.get_descent">Font.get_descent</a> - <font size=-1>get the descent of the font</font></td><td>get the descent of the font</td></tr>
157
 
</table></small></ul>
158
 
<p>Load a new font from a given filename or a python file object. The size is the height of the font in pixels. If the filename is None the Pygame default font will be loaded. If a font cannot be loaded from the arguments given an exception will be raised. Once the font is created the size cannot be changed. </p>
159
 
<p>Font objects are mainly used to render text into new Surface objects. The render can emulate bold or italic features, but it is better to load from a font with actual italic or bold glyphs. The rendered text can be regular strings or unicode. </p>
160
 
<!--COMMENTS:pygame.font.Font--> &nbsp;<br> 
161
 
 
162
 
 
163
 
<a name="Font.render">
164
 
<big><b>Font.render</big></b><br><ul>
165
 
  <i>draw text on a new Surface</i><br>
166
 
  <tt>Font.render(text, antialias, color, background=None): return Surface</tt><br>
167
 
<p>This creates a new Surface with the specified text rendered on it. Pygame provides no way to directly draw text on an existing Surface: instead you must use <tt><a href="font.html#Font.render">Font.render</a> - <font size=-1>draw text on a new Surface</font></tt> to create an image (Surface) of the text, then blit this image onto another Surface. </p>
168
 
<p>The text can only be a single line: newline characters are not rendered. The antialias argument is a boolean: if true the characters will have smooth edges. The color argument is the color of the text <tt>[e.g.:</tt> (0,0,255) for blue]. The optional background argument is a color to use for the text background. If no background is passed the area outside the text will be transparent. </p>
169
 
<p>The Surface returned will be of the dimensions required to hold the text. (the same as those returned by <tt>Font.size())</tt>. If an empty string is passed for the text, a blank surface will be returned that is one pixel wide and the height of the font. </p>
170
 
<p>Depending on the type of background and antialiasing used, this returns different types of Surfaces. For performance reasons, it is good to know what type of image will be used. If antialiasing is not used, the return image will always be an 8bit image with a two color palette. If the background is transparent a colorkey will be set. Antialiased images are rendered to 24-bit <tt>RGB</tt> images. If the background is transparent a pixel alpha will be included. </p>
171
 
<p>Optimization: if you know that the final destination for the text (on the screen) will always have a solid background, and the text is antialiased, you can improve performance by specifying the background color. This will cause the resulting image to maintain transparency information by colorkey rather than (much less efficient) alpha values. </p>
172
 
<p>If you render '\n' a unknown char will be rendered. Usually a rectangle. Instead you need to handle new lines yourself. </p>
173
 
<p>Font rendering is not thread safe: only a single thread can render text any time. </p>
174
 
<!--COMMENTS:Font.render--> &nbsp;<br> 
175
 
<br></ul>
176
 
 
177
 
 
178
 
<a name="Font.size">
179
 
<big><b>Font.size</big></b><br><ul>
180
 
  <i>determine the amount of space needed to render text</i><br>
181
 
  <tt>Font.size(text): return (width, height)</tt><br>
182
 
<p>Returns the dimensions needed to render the text. This can be used to help determine the positioning needed for text before it is rendered. It can also be used for wordwrapping and other layout effects. </p>
183
 
<p>Be aware that most fonts use kerning which adjusts the widths for specific letter pairs. For example, the width for "ae" will not always match the width for "a" + "e". </p>
184
 
<!--COMMENTS:Font.size--> &nbsp;<br> 
185
 
<br></ul>
186
 
 
187
 
 
188
 
<a name="Font.set_underline">
189
 
<big><b>Font.set_underline</big></b><br><ul>
190
 
  <i>control if text is rendered with an underline</i><br>
191
 
  <tt>Font.set_underline(bool): return None</tt><br>
192
 
<p>When enabled, all rendered fonts will include an underline. The underline is always one pixel thick, regardless of font size. This can be mixed with the bold and italic modes. </p>
193
 
<!--COMMENTS:Font.set_underline--> &nbsp;<br> 
194
 
<br></ul>
195
 
 
196
 
 
197
 
<a name="Font.get_underline">
198
 
<big><b>Font.get_underline</big></b><br><ul>
199
 
  <i>check if text will be rendered with an underline</i><br>
200
 
  <tt>Font.get_underline(): return bool</tt><br>
201
 
<p>Return True when the font underline is enabled. </p>
202
 
<!--COMMENTS:Font.get_underline--> &nbsp;<br> 
203
 
<br></ul>
204
 
 
205
 
 
206
 
<a name="Font.set_bold">
207
 
<big><b>Font.set_bold</big></b><br><ul>
208
 
  <i>enable fake rendering of bold text</i><br>
209
 
  <tt>Font.set_bold(bool): return None</tt><br>
210
 
<p>Enables the bold rendering of text. This is a fake stretching of the font that doesn't look good on many font types. If possible load the font from a real bold font file. While bold, the font will have a different width than when normal. This can be mixed with the italic and underline modes. </p>
211
 
<!--COMMENTS:Font.set_bold--> &nbsp;<br> 
212
 
<br></ul>
213
 
 
214
 
 
215
 
<a name="Font.get_bold">
216
 
<big><b>Font.get_bold</big></b><br><ul>
217
 
  <i>check if text will be rendered bold</i><br>
218
 
  <tt>Font.get_bold(): return bool</tt><br>
219
 
<p>Return True when the font bold rendering mode is enabled. </p>
220
 
<!--COMMENTS:Font.get_bold--> &nbsp;<br> 
221
 
<br></ul>
222
 
 
223
 
 
224
 
<a name="Font.set_italic">
225
 
<big><b>Font.set_italic</big></b><br><ul>
226
 
  <i>enable fake rendering of italic text</i><br>
227
 
  <tt>Font.set_bold(bool): return None</tt><br>
228
 
<p>Enables fake rendering of italic text. This is a fake skewing of the font that doesn't look good on many font types. If possible load the font from a real italic font file. While italic the font will have a different width than when normal. This can be mixed with the bold and underline modes. </p>
229
 
<!--COMMENTS:Font.set_italic--> &nbsp;<br> 
230
 
<br></ul>
231
 
 
232
 
 
233
 
<a name="Font.metrics">
234
 
<big><b>Font.metrics</big></b><br><ul>
235
 
  <i>Gets the metrics for each character in the pased string.</i><br>
236
 
  <tt>Font.metrics(text): return list</tt><br>
237
 
<p>The list contains tuples for each character, which contain the minimum <tt>X</tt> offset, the maximum <tt>X</tt> offset, the minimum <tt>Y</tt> offset, the maximum <tt>Y</tt> offset and the advance offset (bearing plus width) of the character. [(minx, maxx, miny, maxy, advance), (minx, maxx, miny, maxy, advance), <tt>...]</tt> </p>
238
 
<!--COMMENTS:Font.metrics--> &nbsp;<br> 
239
 
<br></ul>
240
 
 
241
 
 
242
 
<a name="Font.get_italic">
243
 
<big><b>Font.get_italic</big></b><br><ul>
244
 
  <i>check if the text will be rendered italic</i><br>
245
 
  <tt>Font.get_italic(): return bool</tt><br>
246
 
<p>Return True when the font italic rendering mode is enabled. </p>
247
 
<!--COMMENTS:Font.get_italic--> &nbsp;<br> 
248
 
<br></ul>
249
 
 
250
 
 
251
 
<a name="Font.get_linesize">
252
 
<big><b>Font.get_linesize</big></b><br><ul>
253
 
  <i>get the line space of the font text</i><br>
254
 
  <tt>Font.get_linesize(): return int</tt><br>
255
 
<p>Return the height in pixels for a line of text with the font. When rendering multiple lines of text this is the recommended amount of space between lines. </p>
256
 
<!--COMMENTS:Font.get_linesize--> &nbsp;<br> 
257
 
<br></ul>
258
 
 
259
 
 
260
 
<a name="Font.get_height">
261
 
<big><b>Font.get_height</big></b><br><ul>
262
 
  <i>get the height of the font</i><br>
263
 
  <tt>Font.get_height(): return int</tt><br>
264
 
<p>Return the height in pixels of the actual rendered text. This is the average size for each glyph in the font. </p>
265
 
<!--COMMENTS:Font.get_height--> &nbsp;<br> 
266
 
<br></ul>
267
 
 
268
 
 
269
 
<a name="Font.get_ascent">
270
 
<big><b>Font.get_ascent</big></b><br><ul>
271
 
  <i>get the ascent of the font</i><br>
272
 
  <tt>Font.get_ascent(): return int</tt><br>
273
 
<p>Return the height in pixels for the font ascent. The ascent is the number of pixels from the font baseline to the top of the font. </p>
274
 
<!--COMMENTS:Font.get_ascent--> &nbsp;<br> 
275
 
<br></ul>
276
 
 
277
 
 
278
 
<a name="Font.get_descent">
279
 
<big><b>Font.get_descent</big></b><br><ul>
280
 
  <i>get the descent of the font</i><br>
281
 
  <tt>Font.get_descent(): return int</tt><br>
282
 
<p>Return the height in pixels for the font descent. The descent is the number of pixels from the font baseline to the bottom of the font. </p>
283
 
<!--COMMENTS:Font.get_descent--> &nbsp;<br> 
284
 
<br></ul>
285
 
<br></ul>
286
 
<br></ul>
287
 
 
288
 
</body></html>
 
1
 
 
2
<html>
 
3
<title>font - Pygame Documentation</title>
 
4
<body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>
 
5
 
 
6
 
 
7
<table cellpadding=0 cellspacing=0 border=0 style='border: 3px solid black;' width='100%'>
 
8
<tr>
 
9
<td bgcolor='#c2fc20' style='padding: 6px;' align=center valign=center><a href='http://www.pygame.org/'><img src='../pygame_tiny.gif' border=0 width=200 height=60></a><br><b>pygame documentation</b></td>
 
10
<td bgcolor='#6aee28' style='border-left: 3px solid black; padding: 6px;' align=center valign=center>
 
11
        ||&nbsp;
 
12
        <a href=http://www.pygame.org>Pygame Home</a> &nbsp;||&nbsp;
 
13
        <a href=../index.html>Help Contents</a> &nbsp;||
 
14
        <a href=index.html>Reference Index</a> &nbsp;||
 
15
        <br>&nbsp;<br>
 
16
        
 
17
<a href="camera.html">Camera</a>&nbsp;||&nbsp;
 
18
<a href="cdrom.html">Cdrom</a>&nbsp;||&nbsp;
 
19
<a href="color.html">Color</a>&nbsp;||&nbsp;
 
20
<a href="cursors.html">Cursors</a>&nbsp;||&nbsp;
 
21
<a href="display.html">Display</a>&nbsp;||&nbsp;
 
22
<a href="draw.html">Draw</a>&nbsp;||&nbsp;
 
23
<a href="event.html">Event</a>&nbsp;||&nbsp;
 
24
<a href="examples.html">Examples</a>&nbsp;||&nbsp;
 
25
<a href="font.html">Font</a>&nbsp;||&nbsp;
 
26
<a href="gfxdraw.html">Gfxdraw</a>&nbsp;||&nbsp;
 
27
<a href="image.html">Image</a>&nbsp;||&nbsp;
 
28
<a href="joystick.html">Joystick</a>&nbsp;||&nbsp;
 
29
<a href="key.html">Key</a>&nbsp;||&nbsp;
 
30
<a href="locals.html">Locals</a>&nbsp;||&nbsp;
 
31
<a href="mask.html">Mask</a>&nbsp;||&nbsp;
 
32
<a href="midi.html">Midi</a>&nbsp;||&nbsp;
 
33
<a href="mixer.html">Mixer</a>&nbsp;||&nbsp;
 
34
<a href="mouse.html">Mouse</a>&nbsp;||&nbsp;
 
35
<a href="movie.html">Movie</a>&nbsp;||&nbsp;
 
36
<a href="music.html">Music</a>&nbsp;||&nbsp;
 
37
<a href="overlay.html">Overlay</a>&nbsp;||&nbsp;
 
38
<a href="pixelarray.html">Pixelarray</a>&nbsp;||&nbsp;
 
39
<a href="pygame.html">Pygame</a>&nbsp;||&nbsp;
 
40
<a href="rect.html">Rect</a>&nbsp;||&nbsp;
 
41
<a href="scrap.html">Scrap</a>&nbsp;||&nbsp;
 
42
<a href="sndarray.html">Sndarray</a>&nbsp;||&nbsp;
 
43
<a href="sprite.html">Sprite</a>&nbsp;||&nbsp;
 
44
<a href="surface.html">Surface</a>&nbsp;||&nbsp;
 
45
<a href="surfarray.html">Surfarray</a>&nbsp;||&nbsp;
 
46
<a href="tests.html">Tests</a>&nbsp;||&nbsp;
 
47
<a href="time.html">Time</a>&nbsp;||&nbsp;
 
48
<a href="transform.html">Transform</a>
 
49
</td></tr></table>
 
50
<br>
 
51
 
 
52
 
 
53
<a name="pygame.font">
 
54
<big><b>pygame.font</big></b><br><ul>
 
55
  <i>pygame module for loading and rendering fonts</i><br>
 
56
<ul><small><table>
 
57
  <tr><td><a href="font.html#pygame.font.init">pygame.font.init</a> - <font size=-1>initialize the font module</font></td><td>initialize the font module</td></tr>
 
58
  <tr><td><a href="font.html#pygame.font.quit">pygame.font.quit</a> - <font size=-1>uninitialize the font module</font></td><td>uninitialize the font module</td></tr>
 
59
  <tr><td><a href="font.html#pygame.font.get_init">pygame.font.get_init</a> - <font size=-1>true if the font module is initialized</font></td><td>true if the font module is initialized</td></tr>
 
60
  <tr><td><a href="font.html#pygame.font.get_default_font">pygame.font.get_default_font</a> - <font size=-1>get the filename of the default font</font></td><td>get the filename of the default font</td></tr>
 
61
  <tr><td><a href="font.html#pygame.font.get_fonts">pygame.font.get_fonts</a> - <font size=-1>get all available fonts</font></td><td>get all available fonts</td></tr>
 
62
  <tr><td><a href="font.html#pygame.font.match_font">pygame.font.match_font</a> - <font size=-1>find a specific font on the system</font></td><td>find a specific font on the system</td></tr>
 
63
  <tr><td><a href="font.html#pygame.font.SysFont">pygame.font.SysFont</a> - <font size=-1>create a Font object from the system fonts</font></td><td>create a Font object from the system fonts</td></tr>
 
64
  <tr><td><a href="font.html#pygame.font.Font">pygame.font.Font</a> - <font size=-1>create a new Font object from a file</font></td><td>create a new Font object from a file</td></tr>
 
65
</table></small></ul>
 
66
<p>The font module allows for rendering TrueType fonts into a new Surface object. This module is optional and requires SDL_ttf as a dependency. You should test that <tt>pygame.font</tt> is available and initialized before attempting to use the module. </p>
 
67
<p>Most of the work done with fonts are done by using the actual Font objects. The module by itself only has routines to initialize the module and create Font objects with <tt><a href="font.html#pygame.font.Font">pygame.font.Font</a> - <font size=-1>create a new Font object from a file</font></tt>. </p>
 
68
<p>You can load fonts from the system by using the <tt><a href="font.html#pygame.font.SysFont">pygame.font.SysFont</a> - <font size=-1>create a Font object from the system fonts</font></tt> function. There are a few other functions to help lookup the system fonts. </p>
 
69
<p>Pygame comes with a builtin default font. This can always be accessed by passing None as the font name. </p>
 
70
<!--COMMENTS:pygame.font--> &nbsp;<br> 
 
71
 
 
72
 
 
73
<a name="pygame.font.init">
 
74
<big><b>pygame.font.init</big></b><br><ul>
 
75
  <i>initialize the font module</i><br>
 
76
  <tt>pygame.font.init(): return None</tt><br>
 
77
<p>This method is called automatically by <tt><a href="pygame.html#pygame.init">pygame.init</a> - <font size=-1>initialize all imported pygame modules</font></tt>. It initializes the font module. The module must be initialized before any other functions will work. </p>
 
78
<p>It is safe to call this function more than once. </p>
 
79
<!--COMMENTS:pygame.font.init--> &nbsp;<br> 
 
80
<br></ul>
 
81
 
 
82
 
 
83
<a name="pygame.font.quit">
 
84
<big><b>pygame.font.quit</big></b><br><ul>
 
85
  <i>uninitialize the font module</i><br>
 
86
  <tt>pygame.font.quit(): return None</tt><br>
 
87
<p>Manually uninitialize SDL_ttf's font system. This is called automatically by <tt><a href="pygame.html#pygame.quit">pygame.quit</a> - <font size=-1>uninitialize all pygame modules</font></tt>. </p>
 
88
<p>It is safe to call this function even if font is currently not initialized. </p>
 
89
<!--COMMENTS:pygame.font.quit--> &nbsp;<br> 
 
90
<br></ul>
 
91
 
 
92
 
 
93
<a name="pygame.font.get_init">
 
94
<big><b>pygame.font.get_init</big></b><br><ul>
 
95
  <i>true if the font module is initialized</i><br>
 
96
  <tt>pygame.font.get_init(): return bool</tt><br>
 
97
<p>Test if the font module is initialized or not. </p>
 
98
<!--COMMENTS:pygame.font.get_init--> &nbsp;<br> 
 
99
<br></ul>
 
100
 
 
101
 
 
102
<a name="pygame.font.get_default_font">
 
103
<big><b>pygame.font.get_default_font</big></b><br><ul>
 
104
  <i>get the filename of the default font</i><br>
 
105
  <tt>pygame.font.get_default_font(): return string</tt><br>
 
106
<p>Return the filename of the system font. This is not the full path to the file. This file can usually be found in the same directory as the font module, but it can also be bundled in separate archives. </p>
 
107
<!--COMMENTS:pygame.font.get_default_font--> &nbsp;<br> 
 
108
<br></ul>
 
109
 
 
110
 
 
111
<a name="pygame.font.get_fonts">
 
112
<big><b>pygame.font.get_fonts</big></b><br><ul>
 
113
  <i>get all available fonts</i><br>
 
114
  <tt>pygame.font.get_fonts(): return list of strings</tt><br>
 
115
<p>Returns a list of all the fonts available on the system. The names of the fonts will be set to lowercase with all spaces and punctuation removed. This works on most systems, but some will return an empty list if they cannot find fonts. </p>
 
116
<!--COMMENTS:pygame.font.get_fonts--> &nbsp;<br> 
 
117
<br></ul>
 
118
 
 
119
 
 
120
<a name="pygame.font.match_font">
 
121
<big><b>pygame.font.match_font</big></b><br><ul>
 
122
  <i>find a specific font on the system</i><br>
 
123
  <tt>pygame.font.match_font(name, bold=False, italic=False): return path</tt><br>
 
124
<p>Returns the full path to a font file on the system. If bold or italic are set to true, this will attempt to find the correct family of font. </p>
 
125
<p>The font name can actually be a comma separated list of font names to try. If none of the given names are found, None is returned. </p>
 
126
<p>Example: </p>
 
127
<pre>    print pygame.font.match_font('bitstreamverasans')
 
128
    # output is: /usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf
 
129
    # (but only if you have Vera on your system)
 
130
</pre>
 
131
<!--COMMENTS:pygame.font.match_font--> &nbsp;<br> 
 
132
<br></ul>
 
133
 
 
134
 
 
135
<a name="pygame.font.SysFont">
 
136
<big><b>pygame.font.SysFont</big></b><br><ul>
 
137
  <i>create a Font object from the system fonts</i><br>
 
138
  <tt>pygame.font.SysFont(name, size, bold=False, italic=False): return Font</tt><br>
 
139
<p>Return a new Font object that is loaded from the system fonts. The font will match the requested bold and italic flags. If a suitable system font is not found this will fallback on loading the default pygame font. The font name can be a comma separated list of font names to look for. </p>
 
140
<!--COMMENTS:pygame.font.SysFont--> &nbsp;<br> 
 
141
<br></ul>
 
142
 
 
143
 
 
144
<a name="pygame.font.Font">
 
145
<big><b>pygame.font.Font</big></b><br><ul>
 
146
  <i>create a new Font object from a file</i><br>
 
147
  <tt>pygame.font.Font(filename, size): return Font</tt><br>
 
148
  <tt>pygame.font.Font(object, size): return Font</tt><br>
 
149
<ul><small><table>
 
150
  <tr><td><a href="font.html#Font.render">Font.render</a> - <font size=-1>draw text on a new Surface</font></td><td>draw text on a new Surface</td></tr>
 
151
  <tr><td><a href="font.html#Font.size">Font.size</a> - <font size=-1>determine the amount of space needed to render text</font></td><td>determine the amount of space needed to render text</td></tr>
 
152
  <tr><td><a href="font.html#Font.set_underline">Font.set_underline</a> - <font size=-1>control if text is rendered with an underline</font></td><td>control if text is rendered with an underline</td></tr>
 
153
  <tr><td><a href="font.html#Font.get_underline">Font.get_underline</a> - <font size=-1>check if text will be rendered with an underline</font></td><td>check if text will be rendered with an underline</td></tr>
 
154
  <tr><td><a href="font.html#Font.set_bold">Font.set_bold</a> - <font size=-1>enable fake rendering of bold text</font></td><td>enable fake rendering of bold text</td></tr>
 
155
  <tr><td><a href="font.html#Font.get_bold">Font.get_bold</a> - <font size=-1>check if text will be rendered bold</font></td><td>check if text will be rendered bold</td></tr>
 
156
  <tr><td><a href="font.html#Font.set_italic">Font.set_italic</a> - <font size=-1>enable fake rendering of italic text</font></td><td>enable fake rendering of italic text</td></tr>
 
157
  <tr><td><a href="font.html#Font.metrics">Font.metrics</a> - <font size=-1>Gets the metrics for each character in the pased string.</font></td><td>Gets the metrics for each character in the pased string.</td></tr>
 
158
  <tr><td><a href="font.html#Font.get_italic">Font.get_italic</a> - <font size=-1>check if the text will be rendered italic</font></td><td>check if the text will be rendered italic</td></tr>
 
159
  <tr><td><a href="font.html#Font.get_linesize">Font.get_linesize</a> - <font size=-1>get the line space of the font text</font></td><td>get the line space of the font text</td></tr>
 
160
  <tr><td><a href="font.html#Font.get_height">Font.get_height</a> - <font size=-1>get the height of the font</font></td><td>get the height of the font</td></tr>
 
161
  <tr><td><a href="font.html#Font.get_ascent">Font.get_ascent</a> - <font size=-1>get the ascent of the font</font></td><td>get the ascent of the font</td></tr>
 
162
  <tr><td><a href="font.html#Font.get_descent">Font.get_descent</a> - <font size=-1>get the descent of the font</font></td><td>get the descent of the font</td></tr>
 
163
</table></small></ul>
 
164
<p>Load a new font from a given filename or a python file object. The size is the height of the font in pixels. If the filename is None the Pygame default font will be loaded. If a font cannot be loaded from the arguments given an exception will be raised. Once the font is created the size cannot be changed. </p>
 
165
<p>Font objects are mainly used to render text into new Surface objects. The render can emulate bold or italic features, but it is better to load from a font with actual italic or bold glyphs. The rendered text can be regular strings or unicode. </p>
 
166
<!--COMMENTS:pygame.font.Font--> &nbsp;<br> 
 
167
 
 
168
 
 
169
<a name="Font.render">
 
170
<big><b>Font.render</big></b><br><ul>
 
171
  <i>draw text on a new Surface</i><br>
 
172
  <tt>Font.render(text, antialias, color, background=None): return Surface</tt><br>
 
173
<p>This creates a new Surface with the specified text rendered on it. Pygame provides no way to directly draw text on an existing Surface: instead you must use <tt><a href="font.html#Font.render">Font.render</a> - <font size=-1>draw text on a new Surface</font></tt> to create an image (Surface) of the text, then blit this image onto another Surface. </p>
 
174
<p>The text can only be a single line: newline characters are not rendered. The antialias argument is a boolean: if true the characters will have smooth edges. The color argument is the color of the text <tt>[e.g.:</tt> (0,0,255) for blue]. The optional background argument is a color to use for the text background. If no background is passed the area outside the text will be transparent. </p>
 
175
<p>The Surface returned will be of the dimensions required to hold the text. (the same as those returned by <tt>Font.size())</tt>. If an empty string is passed for the text, a blank surface will be returned that is one pixel wide and the height of the font. </p>
 
176
<p>Depending on the type of background and antialiasing used, this returns different types of Surfaces. For performance reasons, it is good to know what type of image will be used. If antialiasing is not used, the return image will always be an 8bit image with a two color palette. If the background is transparent a colorkey will be set. Antialiased images are rendered to 24-bit <tt>RGB</tt> images. If the background is transparent a pixel alpha will be included. </p>
 
177
<p>Optimization: if you know that the final destination for the text (on the screen) will always have a solid background, and the text is antialiased, you can improve performance by specifying the background color. This will cause the resulting image to maintain transparency information by colorkey rather than (much less efficient) alpha values. </p>
 
178
<p>If you render '\n' a unknown char will be rendered. Usually a rectangle. Instead you need to handle new lines yourself. </p>
 
179
<p>Font rendering is not thread safe: only a single thread can render text any time. </p>
 
180
<!--COMMENTS:Font.render--> &nbsp;<br> 
 
181
<br></ul>
 
182
 
 
183
 
 
184
<a name="Font.size">
 
185
<big><b>Font.size</big></b><br><ul>
 
186
  <i>determine the amount of space needed to render text</i><br>
 
187
  <tt>Font.size(text): return (width, height)</tt><br>
 
188
<p>Returns the dimensions needed to render the text. This can be used to help determine the positioning needed for text before it is rendered. It can also be used for wordwrapping and other layout effects. </p>
 
189
<p>Be aware that most fonts use kerning which adjusts the widths for specific letter pairs. For example, the width for "ae" will not always match the width for "a" + "e". </p>
 
190
<!--COMMENTS:Font.size--> &nbsp;<br> 
 
191
<br></ul>
 
192
 
 
193
 
 
194
<a name="Font.set_underline">
 
195
<big><b>Font.set_underline</big></b><br><ul>
 
196
  <i>control if text is rendered with an underline</i><br>
 
197
  <tt>Font.set_underline(bool): return None</tt><br>
 
198
<p>When enabled, all rendered fonts will include an underline. The underline is always one pixel thick, regardless of font size. This can be mixed with the bold and italic modes. </p>
 
199
<!--COMMENTS:Font.set_underline--> &nbsp;<br> 
 
200
<br></ul>
 
201
 
 
202
 
 
203
<a name="Font.get_underline">
 
204
<big><b>Font.get_underline</big></b><br><ul>
 
205
  <i>check if text will be rendered with an underline</i><br>
 
206
  <tt>Font.get_underline(): return bool</tt><br>
 
207
<p>Return True when the font underline is enabled. </p>
 
208
<!--COMMENTS:Font.get_underline--> &nbsp;<br> 
 
209
<br></ul>
 
210
 
 
211
 
 
212
<a name="Font.set_bold">
 
213
<big><b>Font.set_bold</big></b><br><ul>
 
214
  <i>enable fake rendering of bold text</i><br>
 
215
  <tt>Font.set_bold(bool): return None</tt><br>
 
216
<p>Enables the bold rendering of text. This is a fake stretching of the font that doesn't look good on many font types. If possible load the font from a real bold font file. While bold, the font will have a different width than when normal. This can be mixed with the italic and underline modes. </p>
 
217
<!--COMMENTS:Font.set_bold--> &nbsp;<br> 
 
218
<br></ul>
 
219
 
 
220
 
 
221
<a name="Font.get_bold">
 
222
<big><b>Font.get_bold</big></b><br><ul>
 
223
  <i>check if text will be rendered bold</i><br>
 
224
  <tt>Font.get_bold(): return bool</tt><br>
 
225
<p>Return True when the font bold rendering mode is enabled. </p>
 
226
<!--COMMENTS:Font.get_bold--> &nbsp;<br> 
 
227
<br></ul>
 
228
 
 
229
 
 
230
<a name="Font.set_italic">
 
231
<big><b>Font.set_italic</big></b><br><ul>
 
232
  <i>enable fake rendering of italic text</i><br>
 
233
  <tt>Font.set_bold(bool): return None</tt><br>
 
234
<p>Enables fake rendering of italic text. This is a fake skewing of the font that doesn't look good on many font types. If possible load the font from a real italic font file. While italic the font will have a different width than when normal. This can be mixed with the bold and underline modes. </p>
 
235
<!--COMMENTS:Font.set_italic--> &nbsp;<br> 
 
236
<br></ul>
 
237
 
 
238
 
 
239
<a name="Font.metrics">
 
240
<big><b>Font.metrics</big></b><br><ul>
 
241
  <i>Gets the metrics for each character in the pased string.</i><br>
 
242
  <tt>Font.metrics(text): return list</tt><br>
 
243
<p>The list contains tuples for each character, which contain the minimum <tt>X</tt> offset, the maximum <tt>X</tt> offset, the minimum <tt>Y</tt> offset, the maximum <tt>Y</tt> offset and the advance offset (bearing plus width) of the character. [(minx, maxx, miny, maxy, advance), (minx, maxx, miny, maxy, advance), <tt>...]</tt> </p>
 
244
<!--COMMENTS:Font.metrics--> &nbsp;<br> 
 
245
<br></ul>
 
246
 
 
247
 
 
248
<a name="Font.get_italic">
 
249
<big><b>Font.get_italic</big></b><br><ul>
 
250
  <i>check if the text will be rendered italic</i><br>
 
251
  <tt>Font.get_italic(): return bool</tt><br>
 
252
<p>Return True when the font italic rendering mode is enabled. </p>
 
253
<!--COMMENTS:Font.get_italic--> &nbsp;<br> 
 
254
<br></ul>
 
255
 
 
256
 
 
257
<a name="Font.get_linesize">
 
258
<big><b>Font.get_linesize</big></b><br><ul>
 
259
  <i>get the line space of the font text</i><br>
 
260
  <tt>Font.get_linesize(): return int</tt><br>
 
261
<p>Return the height in pixels for a line of text with the font. When rendering multiple lines of text this is the recommended amount of space between lines. </p>
 
262
<!--COMMENTS:Font.get_linesize--> &nbsp;<br> 
 
263
<br></ul>
 
264
 
 
265
 
 
266
<a name="Font.get_height">
 
267
<big><b>Font.get_height</big></b><br><ul>
 
268
  <i>get the height of the font</i><br>
 
269
  <tt>Font.get_height(): return int</tt><br>
 
270
<p>Return the height in pixels of the actual rendered text. This is the average size for each glyph in the font. </p>
 
271
<!--COMMENTS:Font.get_height--> &nbsp;<br> 
 
272
<br></ul>
 
273
 
 
274
 
 
275
<a name="Font.get_ascent">
 
276
<big><b>Font.get_ascent</big></b><br><ul>
 
277
  <i>get the ascent of the font</i><br>
 
278
  <tt>Font.get_ascent(): return int</tt><br>
 
279
<p>Return the height in pixels for the font ascent. The ascent is the number of pixels from the font baseline to the top of the font. </p>
 
280
<!--COMMENTS:Font.get_ascent--> &nbsp;<br> 
 
281
<br></ul>
 
282
 
 
283
 
 
284
<a name="Font.get_descent">
 
285
<big><b>Font.get_descent</big></b><br><ul>
 
286
  <i>get the descent of the font</i><br>
 
287
  <tt>Font.get_descent(): return int</tt><br>
 
288
<p>Return the height in pixels for the font descent. The descent is the number of pixels from the font baseline to the bottom of the font. </p>
 
289
<!--COMMENTS:Font.get_descent--> &nbsp;<br> 
 
290
<br></ul>
 
291
<br></ul>
 
292
<br></ul>
 
293
 
 
294
</body></html>