From 9ebaf52856b77de3e2db0e342e7a1e91a63c97c6 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 14 Nov 2024 14:58:51 -0600 Subject: [PATCH] fix bmp_lbl for ascenders and descenders --- adafruit_display_text/bitmap_label.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index ad6ea5f..997eb02 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -292,15 +292,18 @@ def _line_spacing_ypixels(font: FontProtocol, line_spacing: float) -> int: def _text_bounding_box( self, text: str, font: FontProtocol ) -> Tuple[int, int, int, int, int, int]: - # pylint: disable=too-many-locals + # pylint: disable=too-many-locals,too-many-branches - ascender_max, descender_max = self._ascent, self._descent + bbox = font.get_bounding_box() + if len(bbox) == 4: + ascender_max, descender_max = bbox[1], -bbox[3] + else: + ascender_max, descender_max = self._ascent, self._descent lines = 1 - xposition = ( - x_start - ) = yposition = y_start = 0 # starting x and y position (left margin) + # starting x and y position (left margin) + xposition = x_start = yposition = y_start = 0 left = None right = x_start