Skip to content

Commit

Permalink
Merge #454
Browse files Browse the repository at this point in the history
454: Some docs about text rendering r=pathunstrom a=astronouth7303

Right up some quick API docs about text

Co-authored-by: Jamie Bliss <jamie@ivyleav.es>
  • Loading branch information
bors[bot] and AstraLuma authored Apr 30, 2020
2 parents 8253c00 + ce4c66c commit 27a837f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ decisions are made, see the :doc:`/discussion/index` section.
assets
scenes
sprites
text
engine
sound
camera
Expand Down
18 changes: 18 additions & 0 deletions docs/reference/text.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
==============
Text Rendering
==============

ppb supports basic text rendering: single font, single style, no wrapping. Rendered fonts are graphical Assets that can be used any place you'd use :py:class:`ppb.Image`

.. code-block:: python
class Label(ppb.sprite):
image = ppb.Text("Hello, World", font=ppb.Font("resources/noto.ttf", size=12))
TrueType and OpenType fonts (both ``.ttf``) are supported, but must be shipped with your game. (System fonts are not supported.)

Note that fonts require a size in points. This controls the size the text is rendered at, but the size on screen is still controlled by :py:attr:`Sprite.size`.

.. autoclass:: ppb.Font

.. autoclass:: ppb.Text
15 changes: 10 additions & 5 deletions ppb/systems/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@

class Font(ChainingMixin, FreeingMixin, AbstractAsset):
"""
A True-Type/OpenType Font
A TrueType/OpenType Font
"""
def __init__(self, name, *, size, index=None):
"""
* name: the filename to load
* size: the size in points
* index: the index of the font in a multi-font file (rare)
:param name: the filename to load
:param size: the size in points
:param index: the index of the font in a multi-font file (rare)
"""
# We do it this way so that the raw data can be cached between multiple
# invocations, even though we have to reparse it every time.
Expand Down Expand Up @@ -104,9 +104,14 @@ def _style_name(self):

class Text(ChainingMixin, FreeingMixin, AbstractAsset):
"""
A bit of rendered text
A bit of rendered text.
"""
def __init__(self, txt, *, font, color=(0, 0, 0)):
"""
:param txt: The text to display.
:param font: The font to use (a :py:class:`ppb.Font`)
:param color: The color to use.
"""
self.txt = txt
self.font = font
self.color = color
Expand Down

0 comments on commit 27a837f

Please sign in to comment.