Skip to content

Commit 6357cf9

Browse files
committed
Initial version of the new FontTTF class
1 parent 67cfdad commit 6357cf9

File tree

6 files changed

+745
-47
lines changed

6 files changed

+745
-47
lines changed

doc/modules/ext/ttf.rst

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
.. currentmodule:: sdl2.ext
22

3-
TrueType Text rendering routines
4-
================================
3+
`sdl2.ext.ttf` - Rendering Text With TrueType Fonts
4+
===================================================
5+
6+
The :mod:`sdl2.ext.ttf` module provides the :class:`~sdl2.ext.FontTTF` class,
7+
which provides a friendly and Pythonic API for font rendering based around
8+
the **SDL_ttf** library. **SDL_ttf** can be installed as a Python dependency
9+
with ``pysdl2-dll`` on platforms that support it).
10+
11+
Additionally, this module provides the deprecated :class:`~sdl2.ext.FontManager`
12+
class, which provides a different (and less featureful) API for rendering text
13+
using **SDL_ttf**.
514

615
.. automodule:: sdl2.ext.ttf
716
:members:

doc/modules/sdl2ext.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ and/or unpleasant parts of the SDL2 API. At present, these modules include:
3434
ext/window.rst
3535
ext/renderer.rst
3636
ext/msgbox.rst
37-
ext/ttf.rst
3837

3938

4039
Utilities for working with SDL2 in Python
@@ -68,6 +67,7 @@ importing images, and more:
6867
ext/surface.rst
6968
ext/draw.rst
7069
ext/image.rst
70+
ext/ttf.rst
7171
ext/bitmapfont.rst
7272

7373

doc/news.rst

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ New Features:
5353
widths and heights for each mapped character in a bitmap font.
5454
* Added a new argument ``line_h`` to :meth:`sdl2.ext.BitmapFont.render_on` to
5555
allow specifying custom line heights.
56+
* Added a new :class:`~sdl2.ext.FontTTF` class, providing a new and flexible
57+
Pythonic wrapper around the :mod:`~sdl2.sdlttf` module for opening and
58+
rendering text with TrueType and OpenType fonts. New features include custom
59+
line heights for multi-line text, left/right/center justification operations
60+
for multiline text, and specifying font sizes in units of pixels in addition
61+
to pt.
5662

5763
API Changes:
5864

@@ -114,6 +120,8 @@ Deprecation Notices:
114120
:meth:`sdl2.ext.BitmapFont.render_text`, which returns an SDL surface instead
115121
of a SoftwareSprite and ensures the output surface is in ARGB8888 format by
116122
default.
123+
* The :class:`~sdl2.ext.FontManager` class has been deprecated in favor of the
124+
new and more flexible :class:`~sdl2.ext.FontTTF` class.
117125

118126

119127
0.9.9

sdl2/ext/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def quit():
7474
# TODO: More subsystems? Also, is TTF_WasInit always 1?
7575
SDL_QuitSubSystem(SDL_INIT_VIDEO)
7676
if SDL_WasInit(0) != 0:
77-
if _HASSDLTTF and sdlttf.TTF_WasInit() == 1:
77+
if _HASSDLTTF and sdlttf.TTF_WasInit() > 0:
7878
sdlttf.TTF_Quit()
7979
if _HASSDLIMAGE:
8080
sdlimage.IMG_Quit()

0 commit comments

Comments
 (0)