From ce4c66c586af8e1d44f0fa5be7672916e31d9c8b Mon Sep 17 00:00:00 2001 From: Jamie Bliss Date: Tue, 28 Apr 2020 23:41:57 -0400 Subject: [PATCH] Some docs about text rendering --- docs/reference/index.rst | 1 + docs/reference/text.rst | 18 ++++++++++++++++++ ppb/systems/text.py | 15 ++++++++++----- 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 docs/reference/text.rst diff --git a/docs/reference/index.rst b/docs/reference/index.rst index 447870b3..25eed3a2 100644 --- a/docs/reference/index.rst +++ b/docs/reference/index.rst @@ -22,6 +22,7 @@ decisions are made, see the :doc:`/discussion/index` section. assets scenes sprites + text engine sound camera diff --git a/docs/reference/text.rst b/docs/reference/text.rst new file mode 100644 index 00000000..80f35b07 --- /dev/null +++ b/docs/reference/text.rst @@ -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 diff --git a/ppb/systems/text.py b/ppb/systems/text.py index c8a2f380..59ad3a4b 100644 --- a/ppb/systems/text.py +++ b/ppb/systems/text.py @@ -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. @@ -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