Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some docs about text rendering #454

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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