From c30285993a316683a42244a942f3477257b1d68b Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Tue, 18 Aug 2020 11:25:08 -0500 Subject: [PATCH 01/12] all: Correct right-side of bounding box for slanted fonts; correct y_offset by deleting impact of newlines, bitmap_label: fix anchored_position rounding error, add speedup with load_glyphs --- adafruit_display_text/bitmap_label.py | 42 +++++++++++----------- adafruit_display_text/label.py | 50 ++++++++++----------------- 2 files changed, 38 insertions(+), 54 deletions(-) mode change 100644 => 100755 adafruit_display_text/bitmap_label.py diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py old mode 100644 new mode 100755 index 98f9322..38f6586 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -181,11 +181,7 @@ def __init__( ) label_position_yoffset = int( # To calibrate with label.py positioning - ( - font.get_glyph(ord("M")).height - - text.count("\n") * font.get_bounding_box()[1] * self._line_spacing - ) - / 2 + (font.get_glyph(ord("M")).height) / 2 ) self.tilegrid = displayio.TileGrid( @@ -237,6 +233,9 @@ def _text_bounding_box( # (consistent with label.py) glyphs = "M j'" # choose glyphs with highest ascender and lowest # descender, will depend upon font used + + font.load_glyphs(text + glyphs) + ascender_max = descender_max = 0 for char in glyphs: this_glyph = font.get_glyph(ord(char)) @@ -252,13 +251,7 @@ def _text_bounding_box( left = right = x_start top = bottom = y_start - y_offset_tight = int( - ( - font.get_glyph(ord("M")).height - - text.count("\n") * self._line_spacing_ypixels(font, line_spacing) - ) - / 2 - ) + y_offset_tight = int((font.get_glyph(ord("M")).height) / 2) # this needs to be reviewed (also in label.py), since it doesn't respond # properly to the number of newlines. @@ -283,8 +276,10 @@ def _text_bounding_box( font, line_spacing ) # Add a newline lines += 1 + xright = xposition + my_glyph.width + my_glyph.dx xposition += my_glyph.shift_x - right = max(right, xposition) + + right = max(right, xposition, xright) if yposition == y_start: # first line, find the Ascender height top = min(top, -my_glyph.height - my_glyph.dy + y_offset_tight) @@ -297,7 +292,7 @@ def _text_bounding_box( label_calibration_offset = int( ( font.get_glyph(ord("M")).height - - text.count("\n") * self._line_spacing_ypixels(font, line_spacing) + # - text.count("\n") * self._line_spacing_ypixels(font, line_spacing) ) / 2 ) @@ -363,7 +358,11 @@ def _place_text( print("Glyph not found: {}".format(repr(char))) else: - right = max(right, xposition + my_glyph.shift_x) + right = max( + right, + xposition + my_glyph.shift_x, + xposition + my_glyph.width + my_glyph.dx, + ) if yposition == y_start: # first line, find the Ascender height top = min(top, -my_glyph.height - my_glyph.dy) bottom = max(bottom, yposition - my_glyph.dy) @@ -420,7 +419,6 @@ def line_spacing(self): bounding-box height. (E.g. 1.0 is the bounding-box height)""" return self._line_spacing - # pylint: disable=no-self-use @line_spacing.setter def line_spacing(self, new_line_spacing): raise RuntimeError( @@ -462,7 +460,6 @@ def text(self): """Text to displayed.""" return self._text - # pylint: disable=no-self-use @text.setter def text(self, new_text): raise RuntimeError( @@ -474,7 +471,6 @@ def font(self): """Font to use for text display.""" return self.font - # pylint: disable=no-self-use @font.setter def font(self, new_font): raise RuntimeError( @@ -509,12 +505,14 @@ def anchored_position(self, new_position): if (self._anchor_point is not None) and (self._anchored_position is not None): new_x = int( new_position[0] - - self._anchor_point[0] * (self._bounding_box[2] * self._scale) + - round(self._anchor_point[0] * (self._bounding_box[2] * self._scale)) ) new_y = int( - new_position[1] - - (self._anchor_point[1] * self._bounding_box[3] * self.scale) - + round((self._bounding_box[3] * self.scale) / 2.0) + round( + new_position[1] + - (self._anchor_point[1] * self._bounding_box[3] * self.scale) + + ((self._bounding_box[3] * self.scale) / 2.0) + ) ) self.x = new_x self.y = new_y diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 0f1caff..9a11f34 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -22,21 +22,14 @@ """ `adafruit_display_text.label` ==================================================== - Displays text labels using CircuitPython's displayio. - * Author(s): Scott Shawcroft - Implementation Notes -------------------- - **Hardware:** - **Software and Dependencies:** - * Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases - """ import displayio @@ -50,7 +43,6 @@ class Label(displayio.Group): properties will be the left edge of the bounding box, and in the center of a M glyph (if its one line), or the (number of lines * linespacing + M)/2. That is, it will try to have it be center-left as close as possible. - :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``. Must include a capital M for measuring character size. :param str text: Text to display @@ -185,13 +177,7 @@ def _update_background_color(self, new_color): self._background_palette[0] = new_color self._background_color = new_color - y_offset = int( - ( - self._font.get_glyph(ord("M")).height - - self.text.count("\n") * self.height * self.line_spacing - ) - / 2 - ) + y_offset = int((self._font.get_glyph(ord("M")).height) / 2) lines = self.text.count("\n") + 1 if not self._added_background_tilegrid: # no bitmap is in the self Group @@ -237,14 +223,7 @@ def _update_text( else: i = 0 tilegrid_count = i - self._font.load_glyphs(new_text + "M") - y_offset = int( - ( - self._font.get_glyph(ord("M")).height - - new_text.count("\n") * self.height * self.line_spacing - ) - / 2 - ) + y_offset = int((self._font.get_glyph(ord("M")).height) / 2) left = right = top = bottom = 0 lines = 1 for character in new_text: @@ -256,7 +235,7 @@ def _update_text( glyph = self._font.get_glyph(ord(character)) if not glyph: continue - right = max(right, x + glyph.shift_x) + right = max(right, x + glyph.shift_x, x + glyph.width + glyph.dx) if y == 0: # first line, find the Ascender height top = min(top, -glyph.height - glyph.dy + y_offset) bottom = max(bottom, y - glyph.dy + y_offset) @@ -386,11 +365,16 @@ def anchored_position(self): if self._anchor_point is None: return None return ( - int(self.x + (self._anchor_point[0] * self._boundingbox[2] * self._scale)), int( - self.y - + (self._anchor_point[1] * self._boundingbox[3] * self._scale) - - round((self._boundingbox[3] * self._scale) / 2.0) + self.x + + round(self._anchor_point[0] * self._boundingbox[2] * self._scale) + ), + int( + round( + self.y + + (self._anchor_point[1] * self._boundingbox[3] * self._scale) + - ((self._boundingbox[3] * self._scale) / 2.0) + ) ), ) @@ -400,12 +384,14 @@ def anchored_position(self, new_position): return # Note: anchor_point must be set before setting anchored_position new_x = int( new_position[0] - - self._anchor_point[0] * (self._boundingbox[2] * self._scale) + - round(self._anchor_point[0] * (self._boundingbox[2] * self._scale)) ) new_y = int( - new_position[1] - - (self._anchor_point[1] * self._boundingbox[3] * self._scale) - + round((self._boundingbox[3] * self._scale) / 2.0) + round( + new_position[1] + - (self._anchor_point[1] * self._boundingbox[3] * self._scale) + + ((self._boundingbox[3] * self._scale) / 2.0) + ) ) self.x = new_x self.y = new_y From 6862809305377a80f7615eb4b0ddfae73d452a6e Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Tue, 18 Aug 2020 11:59:35 -0500 Subject: [PATCH 02/12] all: Correct left-hand bounding box position, that was problematic for slanted fonts --- adafruit_display_text/bitmap_label.py | 41 ++++++++++++++++++--------- adafruit_display_text/label.py | 14 +++++++-- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index 38f6586..6578c46 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -144,7 +144,12 @@ def __init__( # Calculate tight box to provide bounding box dimensions to match label for # anchor_position calculations - (tight_box_x, tight_box_y, x_offset, tight_y_offset) = self._text_bounding_box( + ( + tight_box_x, + tight_box_y, + tight_x_offset, + tight_y_offset, + ) = self._text_bounding_box( text, font, self._line_spacing, background_tight=True, ) @@ -152,6 +157,7 @@ def __init__( box_x = tight_box_x box_y = tight_box_y y_offset = tight_y_offset + x_offset = tight_x_offset else: (box_x, box_y, x_offset, y_offset) = self._text_bounding_box( @@ -176,7 +182,7 @@ def __init__( text, font, self._line_spacing, - padding_left + x_offset, + padding_left - x_offset, padding_top + y_offset, ) @@ -192,7 +198,7 @@ def __init__( tile_width=box_x, tile_height=box_y, default_tile=0, - x=-padding_left, + x=-padding_left + x_offset, y=label_position_yoffset - y_offset - padding_top, ) @@ -248,7 +254,8 @@ def _text_bounding_box( xposition = x_start = 0 # starting x position (left margin) yposition = y_start = 0 - left = right = x_start + left = None + right = x_start top = bottom = y_start y_offset_tight = int((font.get_glyph(ord("M")).height) / 2) @@ -276,6 +283,11 @@ def _text_bounding_box( font, line_spacing ) # Add a newline lines += 1 + if xposition == x_start: + if left is None: + left = my_glyph.dx + else: + left = min(left, my_glyph.dx) xright = xposition + my_glyph.width + my_glyph.dx xposition += my_glyph.shift_x @@ -289,13 +301,10 @@ def _text_bounding_box( ascender_max + descender_max ) - label_calibration_offset = int( - ( - font.get_glyph(ord("M")).height - # - text.count("\n") * self._line_spacing_ypixels(font, line_spacing) - ) - / 2 - ) + label_calibration_offset = int((font.get_glyph(ord("M")).height) / 2) + + if left is None: + left = 0 y_offset_tight = -top + label_calibration_offset @@ -308,7 +317,7 @@ def _text_bounding_box( final_box_height = loose_height final_y_offset = ascender_max - return (final_box_width, final_box_height, 0, final_y_offset) + return (final_box_width, final_box_height, left, final_y_offset) # pylint: disable=too-many-nested-blocks def _place_text( @@ -339,7 +348,8 @@ def _place_text( x_start = xposition # starting x position (left margin) y_start = yposition - left = right = x_start + left = None + right = x_start top = bottom = y_start for char in text: @@ -357,6 +367,11 @@ def _place_text( if my_glyph is None: # Error checking: no glyph found print("Glyph not found: {}".format(repr(char))) else: + if xposition == x_start: + if left is None: + left = my_glyph.dx + else: + left = min(left, my_glyph.dx) right = max( right, diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 9a11f34..30e87e0 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -224,7 +224,9 @@ def _update_text( i = 0 tilegrid_count = i y_offset = int((self._font.get_glyph(ord("M")).height) / 2) - left = right = top = bottom = 0 + right = top = bottom = 0 + left = None + lines = 1 for character in new_text: if character == "\n": @@ -236,6 +238,11 @@ def _update_text( if not glyph: continue right = max(right, x + glyph.shift_x, x + glyph.width + glyph.dx) + if x == 0: + if left is None: + left = glyph.dx + else: + left = min(left, glyph.dx) if y == 0: # first line, find the Ascender height top = min(top, -glyph.height - glyph.dy + y_offset) bottom = max(bottom, y - glyph.dy + y_offset) @@ -271,10 +278,13 @@ def _update_text( i += 1 # Remove the rest + if left is None: + left = 0 + while len(self) > tilegrid_count: # i: self.pop() self._text = new_text - self._boundingbox = (left, top, left + right, bottom - top) + self._boundingbox = (left, top, right - left, bottom - top) if self.background_color is not None: self._update_background_color(self._background_color) From f37e66c2d338c7b44ecbcd2b4c717eb3bf9709fe Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Thu, 20 Aug 2020 11:37:11 -0500 Subject: [PATCH 03/12] Fix bugs with anchored_position and scaling --- adafruit_display_text/bitmap_label.py | 45 ++++++++++----------- adafruit_display_text/label.py | 57 ++++++++++++++++----------- 2 files changed, 53 insertions(+), 49 deletions(-) diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index 6578c46..8f57c75 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -88,6 +88,7 @@ class Label(displayio.Group): """ # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments + # pylint: disable=too-many-branches, no-self-use # Note: max_glyphs parameter is unnecessary, this is used for direct # compatibility with label.py @@ -231,16 +232,18 @@ def _line_spacing_ypixels(font, line_spacing): return_value = int(line_spacing * font.get_bounding_box()[1]) return return_value - def _text_bounding_box( - self, text, font, line_spacing, background_tight=False - ): # **** change default background_tight=False + def _text_bounding_box(self, text, font, line_spacing, background_tight=False): # This empirical approach checks several glyphs for maximum ascender and descender height # (consistent with label.py) glyphs = "M j'" # choose glyphs with highest ascender and lowest # descender, will depend upon font used - font.load_glyphs(text + glyphs) + try: + self._font.load_glyphs(text + glyphs) + except AttributeError: + # ignore if font does not have load_glyphs + pass ascender_max = descender_max = 0 for char in glyphs: @@ -251,8 +254,9 @@ def _text_bounding_box( lines = 1 - xposition = x_start = 0 # starting x position (left margin) - yposition = y_start = 0 + xposition = ( + x_start + ) = yposition = y_start = 0 # starting x and y position (left margin) left = None right = x_start @@ -297,24 +301,18 @@ def _text_bounding_box( top = min(top, -my_glyph.height - my_glyph.dy + y_offset_tight) bottom = max(bottom, yposition - my_glyph.dy + y_offset_tight) - loose_height = (lines - 1) * self._line_spacing_ypixels(font, line_spacing) + ( - ascender_max + descender_max - ) - - label_calibration_offset = int((font.get_glyph(ord("M")).height) / 2) - if left is None: left = 0 - y_offset_tight = -top + label_calibration_offset - final_box_width = right - left if background_tight: final_box_height = bottom - top - final_y_offset = y_offset_tight + final_y_offset = -top + y_offset_tight else: - final_box_height = loose_height + final_box_height = (lines - 1) * self._line_spacing_ypixels( + font, line_spacing + ) + (ascender_max + descender_max) final_y_offset = ascender_max return (final_box_width, final_box_height, left, final_y_offset) @@ -518,16 +516,13 @@ def anchored_position(self, new_position): # Set anchored_position if (self._anchor_point is not None) and (self._anchored_position is not None): - new_x = int( + self.x = int( new_position[0] + - (self._bounding_box[0] * self._scale) - round(self._anchor_point[0] * (self._bounding_box[2] * self._scale)) ) - new_y = int( - round( - new_position[1] - - (self._anchor_point[1] * self._bounding_box[3] * self.scale) - + ((self._bounding_box[3] * self.scale) / 2.0) - ) + self.y = int( + new_position[1] + - (self._bounding_box[1] * self._scale) + - round(self._anchor_point[1] * self._bounding_box[3] * self._scale) ) - self.x = new_x - self.y = new_y diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 30e87e0..0eb2cd5 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -91,11 +91,6 @@ def __init__( self.x = x self.y = y - self.palette = displayio.Palette(2) - self.palette[0] = 0 - self.palette.make_transparent(0) - self.palette[1] = color - self.height = self._font.get_bounding_box()[1] self._line_spacing = line_spacing self._boundingbox = None @@ -104,6 +99,12 @@ def __init__( background_tight # sets padding status for text background box ) + # Create the two-color text palette + self.palette = displayio.Palette(2) + self.palette[0] = 0 + self.palette.make_transparent(0) + self.color = color + self._background_color = background_color self._background_palette = displayio.Palette(1) self._added_background_tilegrid = False @@ -177,8 +178,8 @@ def _update_background_color(self, new_color): self._background_palette[0] = new_color self._background_color = new_color + lines = self._text.rstrip("\n").count("\n") + 1 y_offset = int((self._font.get_glyph(ord("M")).height) / 2) - lines = self.text.count("\n") + 1 if not self._added_background_tilegrid: # no bitmap is in the self Group # add bitmap if text is present and bitmap sizes > 0 pixels @@ -223,16 +224,22 @@ def _update_text( else: i = 0 tilegrid_count = i + + try: + self._font.load_glyphs(new_text + "M") + except AttributeError: + # ignore if font does not have load_glyphs + pass + y_offset = int((self._font.get_glyph(ord("M")).height) / 2) + right = top = bottom = 0 left = None - lines = 1 for character in new_text: if character == "\n": y += int(self.height * self._line_spacing) x = 0 - lines += 1 continue glyph = self._font.get_glyph(ord(character)) if not glyph: @@ -312,7 +319,13 @@ def color(self): @color.setter def color(self, new_color): - self.palette[1] = new_color + self._color = new_color + if new_color is not None: + self.palette[1] = new_color + self.palette.make_opaque(1) + else: + self.palette[1] = 0 + self.palette.make_transparent(1) @property def background_color(self): @@ -377,14 +390,13 @@ def anchored_position(self): return ( int( self.x - + round(self._anchor_point[0] * self._boundingbox[2] * self._scale) + + (self._boundingbox[0] * self._scale) + + +round(self._anchor_point[0] * self._boundingbox[2] * self._scale) ), int( - round( - self.y - + (self._anchor_point[1] * self._boundingbox[3] * self._scale) - - ((self._boundingbox[3] * self._scale) / 2.0) - ) + self.y + + (self._boundingbox[1] * self._scale) + + round(self._anchor_point[1] * self._boundingbox[3] * self._scale) ), ) @@ -392,16 +404,13 @@ def anchored_position(self): def anchored_position(self, new_position): if (self._anchor_point is None) or (new_position is None): return # Note: anchor_point must be set before setting anchored_position - new_x = int( + self.x = int( new_position[0] + - (self._boundingbox[0] * self._scale) - round(self._anchor_point[0] * (self._boundingbox[2] * self._scale)) ) - new_y = int( - round( - new_position[1] - - (self._anchor_point[1] * self._boundingbox[3] * self._scale) - + ((self._boundingbox[3] * self._scale) / 2.0) - ) + self.y = int( + new_position[1] + - (self._boundingbox[1] * self._scale) + - round(self._anchor_point[1] * self._boundingbox[3] * self._scale) ) - self.x = new_x - self.y = new_y From 7d70ca7a7f41ad4feff698b9bb36ddcb6f1e78e2 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Thu, 20 Aug 2020 12:05:35 -0500 Subject: [PATCH 04/12] Update spacing in doc string --- adafruit_display_text/label.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 0eb2cd5..08905ce 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -44,7 +44,7 @@ class Label(displayio.Group): glyph (if its one line), or the (number of lines * linespacing + M)/2. That is, it will try to have it be center-left as close as possible. :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``. - Must include a capital M for measuring character size. + Must include a capital M for measuring character size. :param str text: Text to display :param int max_glyphs: The largest quantity of glyphs we will display :param int color: Color of all text in RGB hex From 1421c5d57ecc2fed901f065964efbdd92487432d Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Thu, 20 Aug 2020 12:10:21 -0500 Subject: [PATCH 05/12] Update docs to try to solve unexpected-indentation --- adafruit_display_text/label.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 08905ce..2af8b9c 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -43,6 +43,7 @@ class Label(displayio.Group): properties will be the left edge of the bounding box, and in the center of a M glyph (if its one line), or the (number of lines * linespacing + M)/2. That is, it will try to have it be center-left as close as possible. + :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``. Must include a capital M for measuring character size. :param str text: Text to display From 704744f4171f324eaf961bd635be1465d3a318b7 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Thu, 20 Aug 2020 12:53:29 -0500 Subject: [PATCH 06/12] remove whitespace --- adafruit_display_text/label.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 2af8b9c..e68c47b 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -43,7 +43,7 @@ class Label(displayio.Group): properties will be the left edge of the bounding box, and in the center of a M glyph (if its one line), or the (number of lines * linespacing + M)/2. That is, it will try to have it be center-left as close as possible. - + :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``. Must include a capital M for measuring character size. :param str text: Text to display From ec28d2a8ecaedc5a790eea0ab4aba902cf86d1a1 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Thu, 20 Aug 2020 12:59:59 -0500 Subject: [PATCH 07/12] Update header docs to previous release --- adafruit_display_text/label.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index e68c47b..81509d5 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -22,14 +22,21 @@ """ `adafruit_display_text.label` ==================================================== + Displays text labels using CircuitPython's displayio. + * Author(s): Scott Shawcroft + Implementation Notes -------------------- + **Hardware:** + **Software and Dependencies:** + * Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases + """ import displayio @@ -45,7 +52,7 @@ class Label(displayio.Group): it will try to have it be center-left as close as possible. :param Font font: A font class that has ``get_bounding_box`` and ``get_glyph``. - Must include a capital M for measuring character size. + Must include a capital M for measuring character size. :param str text: Text to display :param int max_glyphs: The largest quantity of glyphs we will display :param int color: Color of all text in RGB hex From cf6d7130d0def801dd70aaa9755f47eddfe36bc5 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 21 Aug 2020 21:33:47 -0500 Subject: [PATCH 08/12] Delete redundant + sign --- adafruit_display_text/label.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 81509d5..e1e10d2 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -399,7 +399,7 @@ def anchored_position(self): int( self.x + (self._boundingbox[0] * self._scale) - + +round(self._anchor_point[0] * self._boundingbox[2] * self._scale) + + round(self._anchor_point[0] * self._boundingbox[2] * self._scale) ), int( self.y From 3f9ea73480d105ce1db6c769c117febcbcbc5102 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 21 Aug 2020 22:19:32 -0500 Subject: [PATCH 09/12] Add raise from for exception handling --- adafruit_display_text/label.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index e1e10d2..b9f18ea 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -355,8 +355,8 @@ def text(self, new_text): current_anchored_position = self.anchored_position self._update_text(str(new_text)) self.anchored_position = current_anchored_position - except RuntimeError: - raise RuntimeError("Text length exceeds max_glyphs") + except RuntimeError as e: + raise RuntimeError("Text length exceeds max_glyphs") from e @property def font(self): From 61dac4d83dbb3054f35e4ac6a7a8cb65518a18eb Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 21 Aug 2020 22:22:36 -0500 Subject: [PATCH 10/12] rename error variable name for pylint --- adafruit_display_text/label.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index b9f18ea..bc9e987 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -355,8 +355,8 @@ def text(self, new_text): current_anchored_position = self.anchored_position self._update_text(str(new_text)) self.anchored_position = current_anchored_position - except RuntimeError as e: - raise RuntimeError("Text length exceeds max_glyphs") from e + except RuntimeError as run_error: + raise RuntimeError("Text length exceeds max_glyphs") from run_error @property def font(self): From f83687c47a1132c3fcf6475a338760c1058fc077 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 21 Aug 2020 22:26:59 -0500 Subject: [PATCH 11/12] rearrange import statements for pylint --- examples/display_text_background_color_padding.py | 2 +- examples/display_text_textarea_boundingbox.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/display_text_background_color_padding.py b/examples/display_text_background_color_padding.py index 91b694b..476be9a 100755 --- a/examples/display_text_background_color_padding.py +++ b/examples/display_text_background_color_padding.py @@ -8,8 +8,8 @@ # from adafruit_st7789 import ST7789 from adafruit_ili9341 import ILI9341 -from adafruit_display_text import label from adafruit_bitmap_font import bitmap_font +from adafruit_display_text import label # Setup the SPI display diff --git a/examples/display_text_textarea_boundingbox.py b/examples/display_text_textarea_boundingbox.py index 7978abb..fc0cb5e 100644 --- a/examples/display_text_textarea_boundingbox.py +++ b/examples/display_text_textarea_boundingbox.py @@ -1,8 +1,9 @@ import os import board import displayio -from adafruit_display_text.label import Label from adafruit_bitmap_font import bitmap_font +from adafruit_display_text.label import Label + # the current working directory (where this file is) cwd = ("/" + __file__).rsplit("/", 1)[0] From 59c95446054473988d6777709cf098ace2e79182 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 21 Aug 2020 22:30:11 -0500 Subject: [PATCH 12/12] Update font filename --- examples/display_text_background_color_padding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/display_text_background_color_padding.py b/examples/display_text_background_color_padding.py index 476be9a..8e5bda9 100755 --- a/examples/display_text_background_color_padding.py +++ b/examples/display_text_background_color_padding.py @@ -55,7 +55,7 @@ # font=terminalio.FONT # this is the Builtin fixed dimension font -font = bitmap_font.load_font("fonts/BitstreamVeraSans-Roman-24.bdf") +font = bitmap_font.load_font("fonts/Helvetica-Bold-16.bdf") text = []