2828
2929
3030try :
31- from typing import Union , Optional , Tuple
32- from fontio import BuiltinFont
33- from adafruit_bitmap_font .bdf import BDF
34- from adafruit_bitmap_font .pcf import PCF
31+ from typing import Optional , Tuple
32+ from fontio import FontProtocol
3533except ImportError :
3634 pass
3735
@@ -56,7 +54,7 @@ class Label(LabelBase):
5654
5755 :param font: A font class that has ``get_bounding_box`` and ``get_glyph``.
5856 Must include a capital M for measuring character size.
59- :type font: ~BuiltinFont, ~BDF, or ~PCF
57+ :type font: ~FontProtocol
6058 :param str text: Text to display
6159 :param int color: Color of all text in RGB hex
6260 :param int background_color: Color of the background, use `None` for transparent
@@ -93,9 +91,7 @@ class Label(LabelBase):
9391 "RTL" : (False , False , False ),
9492 }
9593
96- def __init__ (
97- self , font : Union [BuiltinFont , BDF , PCF ], save_text : bool = True , ** kwargs
98- ) -> None :
94+ def __init__ (self , font : FontProtocol , save_text : bool = True , ** kwargs ) -> None :
9995
10096 self ._bitmap = None
10197 self ._tilegrid = None
@@ -116,7 +112,7 @@ def __init__(
116112
117113 def _reset_text (
118114 self ,
119- font : Optional [Union [ BuiltinFont , BDF , PCF ] ] = None ,
115+ font : Optional [FontProtocol ] = None ,
120116 text : Optional [str ] = None ,
121117 line_spacing : Optional [float ] = None ,
122118 scale : Optional [int ] = None ,
@@ -270,15 +266,13 @@ def _reset_text(
270266 self .anchored_position = self ._anchored_position
271267
272268 @staticmethod
273- def _line_spacing_ypixels (
274- font : Union [BuiltinFont , BDF , PCF ], line_spacing : float
275- ) -> int :
269+ def _line_spacing_ypixels (font : FontProtocol , line_spacing : float ) -> int :
276270 # Note: Scaling is provided at the Group level
277271 return_value = int (line_spacing * font .get_bounding_box ()[1 ])
278272 return return_value
279273
280274 def _text_bounding_box (
281- self , text : str , font : Union [ BuiltinFont , BDF , PCF ]
275+ self , text : str , font : FontProtocol
282276 ) -> Tuple [int , int , int , int , int , int ]:
283277 # pylint: disable=too-many-locals
284278
@@ -360,7 +354,7 @@ def _place_text(
360354 self ,
361355 bitmap : displayio .Bitmap ,
362356 text : str ,
363- font : Union [ BuiltinFont , BDF , PCF ] ,
357+ font : FontProtocol ,
364358 xposition : int ,
365359 yposition : int ,
366360 skip_index : int = 0 , # set to None to write all pixels, other wise skip this palette index
@@ -534,7 +528,7 @@ def _set_line_spacing(self, new_line_spacing: float) -> None:
534528 else :
535529 raise RuntimeError ("line_spacing is immutable when save_text is False" )
536530
537- def _set_font (self , new_font : Union [ BuiltinFont , BDF , PCF ] ) -> None :
531+ def _set_font (self , new_font : FontProtocol ) -> None :
538532 self ._font = new_font
539533 if self ._save_text :
540534 self ._reset_text (font = new_font , scale = self .scale )
0 commit comments