47
47
import displayio
48
48
49
49
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
52
51
from adafruit_display_text import bitmap_label
53
52
import terminalio
54
53
57
56
print ("Warning: adafruit_display_text not found. No support for text slides." )
58
57
TEXT_SLIDES_ENABLED = False
59
58
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
+
60
68
__version__ = "0.0.0-auto.0"
61
69
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Slideshow.git"
62
70
@@ -341,6 +349,7 @@ def _fade_down(self):
341
349
time .sleep (0.01 )
342
350
343
351
def _create_label (self , file ):
352
+ # pylint: disable=too-many-branches
344
353
"""Creates and returns a label from a file object that contains
345
354
valid valid json describing the text to use.
346
355
See: examples/sample_text_slide.json
@@ -350,9 +359,15 @@ def _create_label(self, file):
350
359
if "scale" in json_data :
351
360
_scale = int (json_data ["scale" ])
352
361
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 )
356
371
if "h_align" not in json_data or json_data ["h_align" ] == "LEFT" :
357
372
x_anchor_point = 0.0
358
373
x_anchored_position = 0
0 commit comments