Skip to content

Commit 188b239

Browse files
committed
adding support for custom fonts
1 parent e9d4c67 commit 188b239

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

adafruit_slideshow.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
import displayio
4848

4949
try:
50-
# text slides are an optional feature and require
51-
# adafruit_display_text
50+
# text slides are an optional feature and require adafruit_display_text
5251
from adafruit_display_text import bitmap_label
5352
import terminalio
5453

@@ -57,6 +56,15 @@
5756
print("Warning: adafruit_display_text not found. No support for text slides.")
5857
TEXT_SLIDES_ENABLED = False
5958

59+
try:
60+
# custom fonts are an optional feature and require adafruit_bitmap_font
61+
from adafruit_bitmap_font import bitmap_font
62+
63+
CUSTOM_FONTS = True
64+
except ImportError:
65+
print("Warning: adafruit_bitmap_font not found. No support for custom fonts.")
66+
CUSTOM_FONTS = False
67+
6068
__version__ = "0.0.0-auto.0"
6169
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Slideshow.git"
6270

@@ -341,6 +349,7 @@ def _fade_down(self):
341349
time.sleep(0.01)
342350

343351
def _create_label(self, file):
352+
# pylint: disable=too-many-branches
344353
"""Creates and returns a label from a file object that contains
345354
valid valid json describing the text to use.
346355
See: examples/sample_text_slide.json
@@ -350,9 +359,15 @@ def _create_label(self, file):
350359
if "scale" in json_data:
351360
_scale = int(json_data["scale"])
352361

353-
label = bitmap_label.Label(
354-
terminalio.FONT, text=json_data["text"], scale=_scale
355-
)
362+
if CUSTOM_FONTS:
363+
if "font" in json_data:
364+
_font = bitmap_font.load_font(json_data["font"])
365+
else:
366+
_font = terminalio.FONT
367+
else:
368+
_font = terminalio.FONT
369+
370+
label = bitmap_label.Label(_font, text=json_data["text"], scale=_scale)
356371
if "h_align" not in json_data or json_data["h_align"] == "LEFT":
357372
x_anchor_point = 0.0
358373
x_anchored_position = 0

0 commit comments

Comments
 (0)