Skip to content

Commit 43a4259

Browse files
authored
Merge pull request #213 from FoamyGuy/bmp_lbl_asc_desc_fix
fix bmp_lbl for ascenders and descenders
2 parents 156c13d + 9ebaf52 commit 43a4259

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

adafruit_display_text/bitmap_label.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,18 @@ def _line_spacing_ypixels(font: FontProtocol, line_spacing: float) -> int:
292292
def _text_bounding_box(
293293
self, text: str, font: FontProtocol
294294
) -> Tuple[int, int, int, int, int, int]:
295-
# pylint: disable=too-many-locals
295+
# pylint: disable=too-many-locals,too-many-branches
296296

297-
ascender_max, descender_max = self._ascent, self._descent
297+
bbox = font.get_bounding_box()
298+
if len(bbox) == 4:
299+
ascender_max, descender_max = bbox[1], -bbox[3]
300+
else:
301+
ascender_max, descender_max = self._ascent, self._descent
298302

299303
lines = 1
300304

301-
xposition = (
302-
x_start
303-
) = yposition = y_start = 0 # starting x and y position (left margin)
305+
# starting x and y position (left margin)
306+
xposition = x_start = yposition = y_start = 0
304307

305308
left = None
306309
right = x_start

0 commit comments

Comments
 (0)