4747import displayio
4848
4949try :
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
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