File: sdl2_sdlttf.rst

package info (click to toggle)
pysdl2 0.9.17%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,328 kB
  • sloc: python: 24,685; makefile: 36; sh: 8
file content (434 lines) | stat: -rw-r--r-- 10,559 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
.. currentmodule:: sdl2.sdlttf

sdl2.sdlttf - Python bindings for SDL_ttf
=========================================

py-sdl2 provides bindings for SDL2_ttf, a library designed for use with SDL2
that provides high quality TrueType font rendering.

SDL2_ttf supports a wide range of font formats, including TrueType (.ttf) and
OpenType (.otf) fonts. It also supports different font styles, font hinting
modes, and font outlines.

The SDL2_ttf library provides functions for rendering three main formats of
text, denoted by the suffix of the function. Functions ending in ``Text`` can only
render plain ASCII text, whereas functions ending in ``UTF8`` or ``UNICODE`` can
render most unicode characters provided that a font supports them. In general,
you should always use the ``UTF8`` rendering functions unless you have a strong
reason to do otherwise.

.. contents:: Table Of Contents
   :depth: 2
   :local:

.. note::
   This module handles font sizes in units of points (pt) instead of pixels. To
   obtain a font with a given pixel height, you can use the
   :func:`TTF_GlyphMetrics` function to get the pixel heights of different
   glyphs in the font at a given pt size and use the px/pt ratio to figure out
   the pt size needed to render text at a given height in px.

.. note::
   The surface sizes and contents of rendered text may vary slightly between
   systems depending on the version of FreeType used by SDL2_ttf.


Initialization functions
------------------------

.. autofunction:: TTF_Init

.. autofunction:: TTF_Quit

.. autofunction:: TTF_WasInit

.. function:: TTF_GetError()

   Returns the most recently encountered SDL2 error message, if any.

   This function is a simple wrapper around :func:`SDL_GetError`.

   :retuns: A UTF-8 encoded string describing the most recent SDL2 error.
   :rtype: bytes

.. function:: TTF_SetError(fmt)

   Sets the most recent SDL2 error message to a given string.

   This function is a simple wrapper around :func:`SDL_SetError`.

   :param fmt: A UTF-8 encoded string containing the error message to set.
   :type fmt: bytes

   :retuns: Always returns ``-1``.
   :rtype: int

.. autofunction:: TTF_ByteSwappedUNICODE

.. autofunction:: TTF_Linked_Version

.. autofunction:: TTF_GetFreeTypeVersion

.. autofunction:: TTF_GetHarfBuzzVersion


Font loading functions
----------------------

.. autofunction:: TTF_OpenFont

.. autofunction:: TTF_OpenFontIndex

.. autofunction:: TTF_OpenFontRW

.. autofunction:: TTF_OpenFontIndexRW

.. autofunction:: TTF_OpenFontDPI

.. autofunction:: TTF_OpenFontIndexDPI

.. autofunction:: TTF_OpenFontDPIRW

.. autofunction:: TTF_OpenFontIndexDPIRW

.. autofunction:: TTF_CloseFont


Font attribute functions
------------------------

Sizing functions
^^^^^^^^^^^^^^^^

.. autofunction:: TTF_SetFontSize

.. autofunction:: TTF_SetFontSizeDPI

.. autofunction:: TTF_FontHeight

.. autofunction:: TTF_FontAscent

.. autofunction:: TTF_FontDescent

.. autofunction:: TTF_FontLineSkip

Style functions
^^^^^^^^^^^^^^^

.. autofunction:: TTF_SetFontStyle

.. autofunction:: TTF_GetFontStyle

.. autofunction:: TTF_FontFaceIsFixedWidth

.. autofunction:: TTF_FontFaceFamilyName

.. autofunction:: TTF_FontFaceStyleName


Glyph information functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: TTF_GlyphIsProvided

.. autofunction:: TTF_GlyphIsProvided32

.. autofunction:: TTF_GlyphMetrics

.. autofunction:: TTF_GlyphMetrics32


Kerning functions
^^^^^^^^^^^^^^^^^
.. autofunction:: TTF_GetFontKerning

.. autofunction:: TTF_SetFontKerning

.. autofunction:: TTF_GetFontKerningSizeGlyphs

.. autofunction:: TTF_GetFontKerningSizeGlyphs32


Render settings functions
^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: TTF_SetFontHinting

.. autofunction:: TTF_GetFontHinting

.. autofunction:: TTF_SetFontSDF

.. autofunction:: TTF_GetFontSDF

.. autofunction:: TTF_SetFontWrappedAlign

.. autofunction:: TTF_GetFontWrappedAlign

.. autofunction:: TTF_SetFontDirection

.. autofunction:: TTF_SetFontScriptName


Text rendering functions
------------------------

Size calculation functions
^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: TTF_MeasureText

.. autofunction:: TTF_MeasureUTF8

.. autofunction:: TTF_MeasureUNICODE

.. autofunction:: TTF_SizeText

.. autofunction:: TTF_SizeUTF8

.. autofunction:: TTF_SizeUNICODE


Solid rendering functions
^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: TTF_RenderText_Solid

.. autofunction:: TTF_RenderUTF8_Solid

.. autofunction:: TTF_RenderUNICODE_Solid

.. autofunction:: TTF_RenderGlyph_Solid

.. autofunction:: TTF_RenderGlyph32_Solid

.. autofunction:: TTF_RenderText_Solid_Wrapped

.. autofunction:: TTF_RenderUTF8_Solid_Wrapped

.. autofunction:: TTF_RenderUNICODE_Solid_Wrapped


Shaded rendering functions
^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: TTF_RenderText_Shaded

.. autofunction:: TTF_RenderUTF8_Shaded

.. autofunction:: TTF_RenderUNICODE_Shaded

.. autofunction:: TTF_RenderGlyph_Shaded

.. autofunction:: TTF_RenderGlyph32_Shaded

.. autofunction:: TTF_RenderText_Shaded_Wrapped

.. autofunction:: TTF_RenderUTF8_Shaded_Wrapped

.. autofunction:: TTF_RenderUNICODE_Shaded_Wrapped


Blended rendering functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: TTF_RenderText_Blended

.. autofunction:: TTF_RenderUTF8_Blended

.. autofunction:: TTF_RenderUNICODE_Blended

.. autofunction:: TTF_RenderGlyph_Blended

.. autofunction:: TTF_RenderGlyph32_Blended

.. autofunction:: TTF_RenderText_Blended_Wrapped

.. autofunction:: TTF_RenderUTF8_Blended_Wrapped

.. autofunction:: TTF_RenderUNICODE_Blended_Wrapped


LCD rendering functions
^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: TTF_RenderText_LCD

.. autofunction:: TTF_RenderUTF8_LCD

.. autofunction:: TTF_RenderUNICODE_LCD

.. autofunction:: TTF_RenderGlyph_LCD

.. autofunction:: TTF_RenderGlyph32_LCD

.. autofunction:: TTF_RenderText_LCD_Wrapped

.. autofunction:: TTF_RenderUTF8_LCD_Wrapped

.. autofunction:: TTF_RenderUNICODE_LCD_Wrapped


Renderer configuration functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: TTF_SetDirection

.. autofunction:: TTF_SetScript


Data types
----------

.. autoclass:: TTF_Font


Module constants
----------------

.. data:: TTF_MAJOR_VERSION

    Latest SDL2_ttf library major number supported by PySDL2.

.. data:: TTF_MINOR_VERSION

    Latest SDL2_ttf library minor number supported by PySDL2. 

.. data:: TTF_PATCHLEVEL

    Latest SDL2_ttf library patch level number supported by PySDL2.

.. data:: UNICODE_BOM_NATIVE

    This allows you to switch byte-order of UNICODE (UCS-2) text data to
    native order, meaning the mode of your CPU. This is meant to be used
    in UNICODE strings that you are using with the SDL2_ttf API. Not needed
    for UTF8 strings.

.. data:: UNICODE_BOM_SWAPPED

    This allows you to switch byte-order of UNICODE (UCS-2) text data to
    swapped order, meaning the reversed mode of your CPU. Thus, if your CPU
    is LSB, then the data will be interpretted as MSB. This is meant to be
    used in UNICODE strings that you are using with the SDL2_ttf API. Not
    needed for UTF8 strings.

.. data:: TTF_STYLE_NORMAL

    Indicates normal (i.e. regular) rendering style. 

.. data:: TTF_STYLE_BOLD

    Indicates bold rendering style. This is used in a bitmask along
    with other styles.

.. data:: TTF_STYLE_ITALIC

    Indicates italicized rendering style. This is used in a bitmask
    along with other styles.

.. data:: TTF_STYLE_UNDERLINE

    Indicates underlined rendering style. This is used in a bitmask
    along with other styles.

.. data:: TTF_STYLE_STRIKETHROUGH

    Indicates strikethrough rendering style. This is used in a bitmask
    along with other styles.

.. data:: TTF_HINTING_NORMAL

    Indicates normal font hinting.
    This corresponds to the default hinting algorithm, optimized for standard
    gray-level rendering.                              

.. data:: TTF_HINTING_LIGHT

    Indicates light font hinting.
    A lighter hinting algorithm for non-monochrome modes. Many generated
    glyphs are more fuzzy but better resemble its original shape. A bit like
    rendering on macOS.

.. data:: TTF_HINTING_MONO

    Indicates monochrome font hinting.
    Strong hinting algorithm that should only be used for monochrome output.
    The result is probably unpleasant if the glyph is rendered in
    non-monochrome modes.

.. data:: TTF_HINTING_NONE

    Indicates disabled font hinting.
    No hinting is used, so the font may become very blurry or messy at
    smaller sizes.

.. data:: TTF_HINTING_LIGHT_SUBPIXEL

    Indicates light subpixel font hinting.
    This produces better results for small text sizes: glyph are rendered at
    subpixel positions, so they look blurrier but are uniformly positioned.
    This mode is slower than others since glyphs are rendered on the fly.

.. data:: TTF_WRAPPED_ALIGN_LEFT

    Indicates left-justified alignment for wrapped multi-line text.

.. data:: TTF_WRAPPED_ALIGN_CENTER

    Indicates centered alignment for wrapped multi-line text.

.. data:: TTF_WRAPPED_ALIGN_RIGHT

    Indicates right-justified alignment for wrapped multi-line text.

.. data:: TTF_DIRECTION_LTR

    Indicates left-to-right text rendering.

.. data:: TTF_DIRECTION_RTL

    Indicates right-to-left text rendering.

.. data:: TTF_DIRECTION_TTB

    Indicates top-to-bottom text rendering.

.. data:: TTF_DIRECTION_BTT

    Indicates bottom-to-top text rendering.


HarfBuzz functions and constants
--------------------------------

As of version 2.0.18, SDL2_ttf makes use of the HarfBuzz library for advanced
text rendering and shaping unless explicitly compiled without it. As a
consequence, some specific SDL2_ttf functions require HarfBuzz constants and
macros for input.

To make these easier to use, the ``sdlttf`` module defines and implements the
constants and macro functions necessary to make full use of the SDL2_ttf
library.

.. note:: In version 2.20.0, SDL2_ttf added new functions for configuring
          HarfBuzz settings that avoid the need for these macros and constants
          entirely. For new projects, please use those functions
          (``TTF_SetFontDirection`` and ``TTF_SetFontScriptName``) instead.

.. autofunction:: HB_TAG

.. data:: HB_DIRECTION_LTR

    A constant indicating left-to-right text rendering.

.. data:: HB_DIRECTION_RTL

    A constant indicating right-to-left text rendering.

.. data:: HB_DIRECTION_TTB

    A constant indicating top-to-bottom text rendering.

.. data:: HB_DIRECTION_BTT

    A constant indicating bottom-to-top text rendering.