File: font.html

package info (click to toggle)
pygame 2.1.2%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,416 kB
  • sloc: ansic: 66,042; python: 46,176; javascript: 9,214; objc: 273; sh: 78; makefile: 56; cpp: 25
file content (698 lines) | stat: -rw-r--r-- 40,765 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698

<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>pygame.font &#8212; pygame v2.1.2 documentation</title>
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/pygame.css" />
    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <link rel="shortcut icon" href="../_static/pygame.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="pygame.freetype" href="freetype.html" />
    <link rel="prev" title="pygame.fastevent" href="fastevent.html" /> 
  </head><body>  

    <div class="document">

  <div class="header">
    <table>
      <tr>
	<td class="logo">
	  <a href="https://www.pygame.org/">
	    <img src="../_static/pygame_tiny.png"/>
	  </a>
	  <h5>pygame documentation</h5>
	</td>
	<td class="pagelinks">
	  <div class="top">
	    <a href="https://www.pygame.org/">Pygame Home</a> ||
	    <a href="../index.html">Help Contents</a> ||
	    <a href="../genindex.html">Reference Index</a>

        <form action="../search.html" method="get" style="display:inline;float:right;">
          <input name="q" value="" type="text">
          <input value="search" type="submit">
        </form>
	  </div>
	  <hr style="color:black;border-bottom:none;border-style: dotted;border-bottom-style:none;">
	  <p class="bottom"><b>Most useful stuff</b>:
	    <a href="color.html">Color</a> | 
	    <a href="display.html">display</a> | 
	    <a href="draw.html">draw</a> | 
	    <a href="event.html">event</a> | 
	    <a href="font.html">font</a> | 
	    <a href="image.html">image</a> | 
	    <a href="key.html">key</a> | 
	    <a href="locals.html">locals</a> | 
	    <a href="mixer.html">mixer</a> | 
	    <a href="mouse.html">mouse</a> | 
	    <a href="rect.html">Rect</a> | 
	    <a href="surface.html">Surface</a> | 
	    <a href="time.html">time</a> | 
	    <a href="music.html">music</a> | 
	    <a href="pygame.html">pygame</a>
	  </p>

	  <p class="bottom"><b>Advanced stuff</b>:
	    <a href="cursors.html">cursors</a> | 
	    <a href="joystick.html">joystick</a> | 
	    <a href="mask.html">mask</a> | 
	    <a href="sprite.html">sprite</a> | 
	    <a href="transform.html">transform</a> | 
	    <a href="bufferproxy.html">BufferProxy</a> | 
	    <a href="freetype.html">freetype</a> | 
	    <a href="gfxdraw.html">gfxdraw</a> | 
	    <a href="midi.html">midi</a> | 
	    <a href="pixelarray.html">PixelArray</a> | 
	    <a href="pixelcopy.html">pixelcopy</a> | 
	    <a href="sndarray.html">sndarray</a> | 
	    <a href="surfarray.html">surfarray</a> | 
	    <a href="math.html">math</a>
	  </p>

	  <p class="bottom"><b>Other</b>:
	    <a href="camera.html">camera</a> | 
	    <a href="sdl2_controller.html#module-pygame._sdl2.controller">controller</a> | 
	    <a href="examples.html">examples</a> | 
	    <a href="fastevent.html">fastevent</a> | 
	    <a href="scrap.html">scrap</a> | 
	    <a href="tests.html">tests</a> | 
	    <a href="touch.html">touch</a> | 
	    <a href="pygame.html#module-pygame.version">version</a>
	  </p>
	</td>
      </tr>
    </table>
  </div>

      <div class="documentwrapper">
          <div class="body" role="main">
            
<section id="module-pygame.font">
<span id="pygame-font"></span><dl class="definition">
<dt class="title module sig sig-object">
<code class="docutils literal notranslate"><span class="pre">pygame.font</span></code></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">pygame module for loading and rendering fonts</span></div>
</div>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 36%" />
<col style="width: 1%" />
<col style="width: 63%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.init">pygame.font.init</a></div>
</td>
<td>—</td>
<td>initialize the font module</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.quit">pygame.font.quit</a></div>
</td>
<td>—</td>
<td>uninitialize the font module</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.get_init">pygame.font.get_init</a></div>
</td>
<td>—</td>
<td>true if the font module is initialized</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.get_default_font">pygame.font.get_default_font</a></div>
</td>
<td>—</td>
<td>get the filename of the default font</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.get_fonts">pygame.font.get_fonts</a></div>
</td>
<td>—</td>
<td>get all available fonts</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.match_font">pygame.font.match_font</a></div>
</td>
<td>—</td>
<td>find a specific font on the system</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.SysFont">pygame.font.SysFont</a></div>
</td>
<td>—</td>
<td>create a Font object from the system fonts</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font">pygame.font.Font</a></div>
</td>
<td>—</td>
<td>create a new Font object from a file</td>
</tr>
</tbody>
</table>
<p>The font module allows for rendering TrueType fonts into a new Surface object.
It accepts any UCS-2 character ('u0001' to 'uFFFF'). This module is optional
and requires SDL_ttf as a dependency. You should test that <a class="tooltip reference internal" href="#module-pygame.font" title=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygame.font</span></code><span class="tooltip-content">pygame module for loading and rendering fonts</span></a>
is available and initialized before attempting to use the module.</p>
<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 <code class="docutils literal notranslate"><span class="pre">pygame.font.Font()</span></code>.</p>
<p>You can load fonts from the system by using the <code class="docutils literal notranslate"><span class="pre">pygame.font.SysFont()</span></code>
function. There are a few other functions to help lookup the system fonts.</p>
<p>Pygame comes with a builtin default font. This can always be accessed by
passing None as the font name.</p>
<p>To use the <a class="tooltip reference internal" href="freetype.html#module-pygame.freetype" title=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygame.freetype</span></code><span class="tooltip-content">Enhanced pygame module for loading and rendering computer fonts</span></a> based <code class="docutils literal notranslate"><span class="pre">pygame.ftfont</span></code> as
<a class="tooltip reference internal" href="#module-pygame.font" title=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygame.font</span></code><span class="tooltip-content">pygame module for loading and rendering fonts</span></a> define the environment variable PYGAME_FREETYPE before the
first import of <a class="tooltip reference internal" href="pygame.html#module-pygame" title=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygame</span></code><span class="tooltip-content">the top level pygame package</span></a>. Module <code class="docutils literal notranslate"><span class="pre">pygame.ftfont</span></code> is a <a class="tooltip reference internal" href="#module-pygame.font" title=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygame.font</span></code><span class="tooltip-content">pygame module for loading and rendering fonts</span></a>
compatible module that passes all but one of the font module unit tests:
it does not have the UCS-2 limitation of the SDL_ttf based font module, so
fails to raise an exception for a code point greater than 'uFFFF'. If
<a class="tooltip reference internal" href="freetype.html#module-pygame.freetype" title=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygame.freetype</span></code><span class="tooltip-content">Enhanced pygame module for loading and rendering computer fonts</span></a> is unavailable then the SDL_ttf font module will be
loaded instead.</p>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.font.init">
<span class="sig-prename descclassname"><span class="pre">pygame.font.</span></span><span class="sig-name descname"><span class="pre">init</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.init" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">initialize the font module</span></div>
<div class="line"><span class="signature">init() -&gt; None</span></div>
</div>
<p>This method is called automatically by <code class="docutils literal notranslate"><span class="pre">pygame.init()</span></code>. It initializes the
font module. The module must be initialized before any other functions will
work.</p>
<p>It is safe to call this function more than once.</p>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.font.quit">
<span class="sig-prename descclassname"><span class="pre">pygame.font.</span></span><span class="sig-name descname"><span class="pre">quit</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.quit" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">uninitialize the font module</span></div>
<div class="line"><span class="signature">quit() -&gt; None</span></div>
</div>
<p>Manually uninitialize SDL_ttf's font system. This is called automatically by
<code class="docutils literal notranslate"><span class="pre">pygame.quit()</span></code>.</p>
<p>It is safe to call this function even if font is currently not initialized.</p>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.font.get_init">
<span class="sig-prename descclassname"><span class="pre">pygame.font.</span></span><span class="sig-name descname"><span class="pre">get_init</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.get_init" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">true if the font module is initialized</span></div>
<div class="line"><span class="signature">get_init() -&gt; bool</span></div>
</div>
<p>Test if the font module is initialized or not.</p>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.font.get_default_font">
<span class="sig-prename descclassname"><span class="pre">pygame.font.</span></span><span class="sig-name descname"><span class="pre">get_default_font</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.get_default_font" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">get the filename of the default font</span></div>
<div class="line"><span class="signature">get_default_font() -&gt; string</span></div>
</div>
<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>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.font.get_fonts">
<span class="sig-prename descclassname"><span class="pre">pygame.font.</span></span><span class="sig-name descname"><span class="pre">get_fonts</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.get_fonts" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">get all available fonts</span></div>
<div class="line"><span class="signature">get_fonts() -&gt; list of strings</span></div>
</div>
<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>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.font.match_font">
<span class="sig-prename descclassname"><span class="pre">pygame.font.</span></span><span class="sig-name descname"><span class="pre">match_font</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.match_font" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">find a specific font on the system</span></div>
<div class="line"><span class="signature">match_font(name, bold=False, italic=False) -&gt; path</span></div>
</div>
<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>
<p>The font name can also be an iterable of font names, a string of
comma-separated font names, or a bytes of comma-separated font names, in
which case the set of names will be searched in order.
If none of the given names are found, None is returned.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.0.1: </span>Accept an iterable of font names.</p>
</div>
<p>Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">print</span> <span class="n">pygame</span><span class="o">.</span><span class="n">font</span><span class="o">.</span><span class="n">match_font</span><span class="p">(</span><span class="s1">&#39;bitstreamverasans&#39;</span><span class="p">)</span>
<span class="c1"># output is: /usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf</span>
<span class="c1"># (but only if you have Vera on your system)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.font.SysFont">
<span class="sig-prename descclassname"><span class="pre">pygame.font.</span></span><span class="sig-name descname"><span class="pre">SysFont</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.SysFont" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">create a Font object from the system fonts</span></div>
<div class="line"><span class="signature">SysFont(name, size, bold=False, italic=False) -&gt; Font</span></div>
</div>
<p>Return a new Font object that is loaded from the system fonts. The font will
match the requested bold and italic flags. Pygame uses a small set of common
font aliases. If the specific font you ask for is not available, a reasonable
alternative may be used. If a suitable system font is not found this will
fall back on loading the default pygame font.</p>
<p>The font name can also be an iterable of font names, a string of
comma-separated font names, or a bytes of comma-separated font names, in
which case the set of names will be searched in order.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.0.1: </span>Accept an iterable of font names.</p>
</div>
</dd></dl>

<dl class="py class definition">
<dt class="sig sig-object py title" id="pygame.font.Font">
<span class="sig-prename descclassname"><span class="pre">pygame.font.</span></span><span class="sig-name descname"><span class="pre">Font</span></span><a class="headerlink" href="#pygame.font.Font" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">create a new Font object from a file</span></div>
<div class="line"><span class="signature">Font(filename, size) -&gt; Font</span></div>
<div class="line"><span class="signature">Font(pathlib.Path, size) -&gt; Font</span></div>
<div class="line"><span class="signature">Font(object, size) -&gt; Font</span></div>
</div>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 29%" />
<col style="width: 1%" />
<col style="width: 70%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.bold">pygame.font.Font.bold</a></div>
</td>
<td>—</td>
<td>Gets or sets whether the font should be rendered in (faked) bold.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.italic">pygame.font.Font.italic</a></div>
</td>
<td>—</td>
<td>Gets or sets whether the font should be rendered in (faked) italics.</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.underline">pygame.font.Font.underline</a></div>
</td>
<td>—</td>
<td>Gets or sets whether the font should be rendered with an underline.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.render">pygame.font.Font.render</a></div>
</td>
<td>—</td>
<td>draw text on a new Surface</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.size">pygame.font.Font.size</a></div>
</td>
<td>—</td>
<td>determine the amount of space needed to render text</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.set_underline">pygame.font.Font.set_underline</a></div>
</td>
<td>—</td>
<td>control if text is rendered with an underline</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.get_underline">pygame.font.Font.get_underline</a></div>
</td>
<td>—</td>
<td>check if text will be rendered with an underline</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.set_bold">pygame.font.Font.set_bold</a></div>
</td>
<td>—</td>
<td>enable fake rendering of bold text</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.get_bold">pygame.font.Font.get_bold</a></div>
</td>
<td>—</td>
<td>check if text will be rendered bold</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.set_italic">pygame.font.Font.set_italic</a></div>
</td>
<td>—</td>
<td>enable fake rendering of italic text</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.metrics">pygame.font.Font.metrics</a></div>
</td>
<td>—</td>
<td>gets the metrics for each character in the passed string</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.get_italic">pygame.font.Font.get_italic</a></div>
</td>
<td>—</td>
<td>check if the text will be rendered italic</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.get_linesize">pygame.font.Font.get_linesize</a></div>
</td>
<td>—</td>
<td>get the line space of the font text</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.get_height">pygame.font.Font.get_height</a></div>
</td>
<td>—</td>
<td>get the height of the font</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.get_ascent">pygame.font.Font.get_ascent</a></div>
</td>
<td>—</td>
<td>get the ascent of the font</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="font.html#pygame.font.Font.get_descent">pygame.font.Font.get_descent</a></div>
</td>
<td>—</td>
<td>get the descent of the font</td>
</tr>
</tbody>
</table>
<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>
<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>
<dl class="py attribute definition">
<dt class="sig sig-object py title" id="pygame.font.Font.bold">
<span class="sig-name descname"><span class="pre">bold</span></span><a class="headerlink" href="#pygame.font.Font.bold" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Gets or sets whether the font should be rendered in (faked) bold.</span></div>
<div class="line"><span class="signature">bold -&gt; bool</span></div>
</div>
<p>Whether the font should be rendered in bold.</p>
<p>When set to True, this 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>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.0.0.</span></p>
</div>
</dd></dl>

<dl class="py attribute definition">
<dt class="sig sig-object py title" id="pygame.font.Font.italic">
<span class="sig-name descname"><span class="pre">italic</span></span><a class="headerlink" href="#pygame.font.Font.italic" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Gets or sets whether the font should be rendered in (faked) italics.</span></div>
<div class="line"><span class="signature">italic -&gt; bool</span></div>
</div>
<p>Whether the font should be rendered in italic.</p>
<p>When set to True, this 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>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.0.0.</span></p>
</div>
</dd></dl>

<dl class="py attribute definition">
<dt class="sig sig-object py title" id="pygame.font.Font.underline">
<span class="sig-name descname"><span class="pre">underline</span></span><a class="headerlink" href="#pygame.font.Font.underline" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Gets or sets whether the font should be rendered with an underline.</span></div>
<div class="line"><span class="signature">underline -&gt; bool</span></div>
</div>
<p>Whether the font should be rendered in underline.</p>
<p>When set to True, 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>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.0.0.</span></p>
</div>
</dd></dl>

<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.font.Font.render">
<span class="sig-name descname"><span class="pre">render</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.Font.render" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">draw text on a new Surface</span></div>
<div class="line"><span class="signature">render(text, antialias, color, background=None) -&gt; Surface</span></div>
</div>
<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 <code class="docutils literal notranslate"><span class="pre">Font.render()</span></code> to create an image (Surface) of the text, then
blit this image onto another Surface.</p>
<p>The text can only be a single line: newline characters are not rendered.
Null characters ('x00') raise a TypeError. Both Unicode and char (byte)
strings are accepted. For Unicode strings only UCS-2 characters
('u0001' to 'uFFFF') were previously supported and any greater unicode
codepoint would raise a UnicodeError. Now, characters in the UCS-4 range
are supported. For char strings a <code class="docutils literal notranslate"><span class="pre">LATIN1</span></code> encoding is assumed. The
antialias argument is a boolean: if true the characters will have smooth
edges. The color argument is the color of the text
[e.g.: (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>
<p>The Surface returned will be of the dimensions required to hold the text.
(the same as those returned by Font.size()). If an empty string is passed
for the text, a blank surface will be returned that is zero pixel wide and
the height of the font.</p>
<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 8-bit image with a two-color palette. If the
background is transparent a colorkey will be set. Antialiased images are
rendered to 24-bit <code class="docutils literal notranslate"><span class="pre">RGB</span></code> images. If the background is transparent a
pixel alpha will be included.</p>
<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>
<p>If you render '\n' an unknown char will be rendered. Usually a
rectangle. Instead you need to handle new lines yourself.</p>
<p>Font rendering is not thread safe: only a single thread can render text
at any time.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in pygame 2.0.3: </span>Rendering UCS_4 unicode works and does not
raise an exception. Use <cite>if hasattr(pygame.font, 'UCS_4'):</cite> to see if
pygame supports rendering UCS_4 unicode including more languages and
emoji.</p>
</div>
</dd></dl>

<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.font.Font.size">
<span class="sig-name descname"><span class="pre">size</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.Font.size" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">determine the amount of space needed to render text</span></div>
<div class="line"><span class="signature">size(text) -&gt; (width, height)</span></div>
</div>
<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>
<p>Be aware that most fonts use kerning which adjusts the widths for
specific letter pairs. For example, the width for &quot;ae&quot; will not always
match the width for &quot;a&quot; + &quot;e&quot;.</p>
</dd></dl>

<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.font.Font.set_underline">
<span class="sig-name descname"><span class="pre">set_underline</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.Font.set_underline" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">control if text is rendered with an underline</span></div>
<div class="line"><span class="signature">set_underline(bool) -&gt; None</span></div>
</div>
<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>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This is the same as the <a class="reference internal" href="#pygame.font.Font.underline" title="pygame.font.Font.underline"><code class="xref py py-attr docutils literal notranslate"><span class="pre">underline</span></code></a> attribute.</p>
</div>
</dd></dl>

<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.font.Font.get_underline">
<span class="sig-name descname"><span class="pre">get_underline</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.Font.get_underline" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">check if text will be rendered with an underline</span></div>
<div class="line"><span class="signature">get_underline() -&gt; bool</span></div>
</div>
<p>Return True when the font underline is enabled.</p>
<blockquote>
<div><div class="admonition note">
<p class="admonition-title">Note</p>
<p>This is the same as the <a class="reference internal" href="#pygame.font.Font.underline" title="pygame.font.Font.underline"><code class="xref py py-attr docutils literal notranslate"><span class="pre">underline</span></code></a> attribute.</p>
</div>
</div></blockquote>
</dd></dl>

<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.font.Font.set_bold">
<span class="sig-name descname"><span class="pre">set_bold</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.Font.set_bold" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">enable fake rendering of bold text</span></div>
<div class="line"><span class="signature">set_bold(bool) -&gt; None</span></div>
</div>
<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>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This is the same as the <a class="reference internal" href="#pygame.font.Font.bold" title="pygame.font.Font.bold"><code class="xref py py-attr docutils literal notranslate"><span class="pre">bold</span></code></a> attribute.</p>
</div>
</dd></dl>

<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.font.Font.get_bold">
<span class="sig-name descname"><span class="pre">get_bold</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.Font.get_bold" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">check if text will be rendered bold</span></div>
<div class="line"><span class="signature">get_bold() -&gt; bool</span></div>
</div>
<p>Return True when the font bold rendering mode is enabled.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This is the same as the <a class="reference internal" href="#pygame.font.Font.bold" title="pygame.font.Font.bold"><code class="xref py py-attr docutils literal notranslate"><span class="pre">bold</span></code></a> attribute.</p>
</div>
</dd></dl>

<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.font.Font.set_italic">
<span class="sig-name descname"><span class="pre">set_italic</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.Font.set_italic" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">enable fake rendering of italic text</span></div>
<div class="line"><span class="signature">set_italic(bool) -&gt; None</span></div>
</div>
<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>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This is the same as the <a class="reference internal" href="#pygame.font.Font.italic" title="pygame.font.Font.italic"><code class="xref py py-attr docutils literal notranslate"><span class="pre">italic</span></code></a> attribute.</p>
</div>
</dd></dl>

<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.font.Font.metrics">
<span class="sig-name descname"><span class="pre">metrics</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.Font.metrics" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">gets the metrics for each character in the passed string</span></div>
<div class="line"><span class="signature">metrics(text) -&gt; list</span></div>
</div>
<p>The list contains tuples for each character, which contain the minimum
<code class="docutils literal notranslate"><span class="pre">X</span></code> offset, the maximum <code class="docutils literal notranslate"><span class="pre">X</span></code> offset, the minimum <code class="docutils literal notranslate"><span class="pre">Y</span></code> offset, the
maximum <code class="docutils literal notranslate"><span class="pre">Y</span></code> offset and the advance offset (bearing plus width) of the
character. [(minx, maxx, miny, maxy, advance), (minx, maxx, miny, maxy,
advance), ...]. None is entered in the list for each unrecognized
character.</p>
</dd></dl>

<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.font.Font.get_italic">
<span class="sig-name descname"><span class="pre">get_italic</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.Font.get_italic" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">check if the text will be rendered italic</span></div>
<div class="line"><span class="signature">get_italic() -&gt; bool</span></div>
</div>
<p>Return True when the font italic rendering mode is enabled.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This is the same as the <a class="reference internal" href="#pygame.font.Font.italic" title="pygame.font.Font.italic"><code class="xref py py-attr docutils literal notranslate"><span class="pre">italic</span></code></a> attribute.</p>
</div>
</dd></dl>

<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.font.Font.get_linesize">
<span class="sig-name descname"><span class="pre">get_linesize</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.Font.get_linesize" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">get the line space of the font text</span></div>
<div class="line"><span class="signature">get_linesize() -&gt; int</span></div>
</div>
<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>
</dd></dl>

<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.font.Font.get_height">
<span class="sig-name descname"><span class="pre">get_height</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.Font.get_height" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">get the height of the font</span></div>
<div class="line"><span class="signature">get_height() -&gt; int</span></div>
</div>
<p>Return the height in pixels of the actual rendered text. This is the
average size for each glyph in the font.</p>
</dd></dl>

<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.font.Font.get_ascent">
<span class="sig-name descname"><span class="pre">get_ascent</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.Font.get_ascent" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">get the ascent of the font</span></div>
<div class="line"><span class="signature">get_ascent() -&gt; int</span></div>
</div>
<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>
</dd></dl>

<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.font.Font.get_descent">
<span class="sig-name descname"><span class="pre">get_descent</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.font.Font.get_descent" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">get the descent of the font</span></div>
<div class="line"><span class="signature">get_descent() -&gt; int</span></div>
</div>
<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>
</dd></dl>

</dd></dl>

</dd></dl>

</section>


<br /><br />
<hr />
<a href="https://github.com/pygame/pygame/edit/main/docs/reST/ref/font.rst" rel="nofollow">Edit on GitHub</a>
            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="freetype.html" title="pygame.freetype"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="fastevent.html" title="pygame.fastevent"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">pygame v2.1.2 documentation</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygame.font</span></code></a></li>
    <script type="text/javascript" src="https://www.pygame.org/comment/jquery.plugin.docscomments.js"></script>

      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2000-2021, pygame developers.
    </div>
  </body>
</html>