diff --git a/adafruit_display_text/__init__.py b/adafruit_display_text/__init__.py index 3919dbb..246f54e 100644 --- a/adafruit_display_text/__init__.py +++ b/adafruit_display_text/__init__.py @@ -220,6 +220,7 @@ def __init__( super().__init__(max_size=1, x=x, y=y, scale=1, **kwargs) self._font = font + self._ascent, self._descent = self._get_ascent_descent() self.palette = Palette(2) self._color = color self._background_color = background_color @@ -244,7 +245,7 @@ def __init__( if self.base_alignment: self._y_offset = 0 else: - self._y_offset = self._get_ascent() // 2 + self._y_offset = self._ascent // 2 def _get_ascent_descent(self) -> Tuple[int, int]: """ Private function to calculate ascent and descent font values """ @@ -267,9 +268,6 @@ def _get_ascent_descent(self) -> Tuple[int, int]: descender_max = max(descender_max, -this_glyph.dy) return ascender_max, descender_max - def _get_ascent(self) -> int: - return self._get_ascent_descent()[0] - @property def font(self) -> None: """Font to use for text display.""" diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index a9daedd..5769325 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -265,7 +265,7 @@ def _reset_text( if self.base_alignment: label_position_yoffset = 0 else: - label_position_yoffset = self._get_ascent() // 2 + label_position_yoffset = self._ascent // 2 self.tilegrid = displayio.TileGrid( self.bitmap, @@ -325,7 +325,7 @@ def _line_spacing_ypixels(font, line_spacing: float) -> int: def _text_bounding_box( self, text: str, font, line_spacing: float ) -> Tuple[int, int, int, int, int, int]: - ascender_max, descender_max = self._get_ascent_descent() + ascender_max, descender_max = self._ascent, self._descent lines = 1 @@ -337,7 +337,7 @@ def _text_bounding_box( right = x_start top = bottom = y_start - y_offset_tight = self._get_ascent() // 2 + y_offset_tight = self._ascent // 2 newline = False diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 3fbd0fb..f10f19b 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -150,7 +150,7 @@ def _create_background_box(self, lines: int, y_offset: int) -> None: y_box_offset = self._bounding_box[1] else: # draw a "loose" bounding box to include any ascenders/descenders. - ascent, descent = self._get_ascent_descent() + ascent, descent = self._ascent, self._descent if ( self._label_direction == "UPR" @@ -225,7 +225,7 @@ def _update_background_color(self, new_color: int) -> None: self._background_color = new_color lines = self._text.rstrip("\n").count("\n") + 1 - y_offset = self._get_ascent() // 2 + y_offset = self._ascent // 2 if not self._added_background_tilegrid: # no bitmap is in the self Group # add bitmap if text is present and bitmap sizes > 0 pixels @@ -279,7 +279,7 @@ def _update_text( if self.base_alignment: self._y_offset = 0 else: - self._y_offset = self._get_ascent() // 2 + self._y_offset = self._ascent // 2 if self._label_direction == "RTL": left = top = bottom = 0