Skip to content

Commit e6a1dde

Browse files
committed
Documentation for ev3dev.fonts module
1 parent 9da6ed7 commit e6a1dde

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

docs/_static/fonts.png

16.9 KB
Loading

docs/other.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,29 @@ Screen
9696
:members:
9797
:show-inheritance:
9898

99+
Bitmap fonts
100+
^^^^^^^^^^^^
101+
102+
The :py:class:`Screen` class allows to write text on the LCD using python
103+
imaging library (PIL) interface (see description of the ``text()`` method
104+
`here <http://pillow.readthedocs.io/en/3.1.x/reference/ImageDraw.html#PIL.ImageDraw.PIL.ImageDraw.Draw.text>`_).
105+
The ``ev3dev.fonts`` module contains bitmap fonts in PIL format that should
106+
look good on a tiny EV3 screen:
107+
108+
.. code-block:: py
109+
110+
import ev3dev.fonts as fonts
111+
screen.draw.text((10,10), 'Hello World!', font=fonts.load('luBS14'))
112+
113+
.. autofunction:: ev3dev.fonts.available
114+
115+
.. autofunction:: ev3dev.fonts.load
116+
117+
The following image lists all available fonts. The grid lines correspond
118+
to EV3 screen size:
119+
120+
.. image:: _static/fonts.png
121+
99122
Lego Port
100123
---------
101124

ev3dev/fonts/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import os.path
33
from PIL import ImageFont
44

5-
def list():
5+
def available():
6+
"""
7+
Returns list of available font names.
8+
"""
69
names = []
710
for f in pkg_resources.resource_listdir('ev3dev.fonts', ''):
811
name, ext = os.path.splitext(os.path.basename(f))
@@ -11,6 +14,11 @@ def list():
1114
return sorted(names)
1215

1316
def load(name):
17+
"""
18+
Loads the font specified by name and returns it as an instance of
19+
`PIL.ImageFont <http://pillow.readthedocs.io/en/latest/reference/ImageFont.html>`_
20+
class.
21+
"""
1422
pil_file = pkg_resources.resource_filename('ev3dev.fonts', '{}.pil'.format(name))
1523
pbm_file = pkg_resources.resource_filename('ev3dev.fonts', '{}.pbm'.format(name))
1624
return ImageFont.load(pil_file)

0 commit comments

Comments
 (0)