From cc094894b0fefbdaa410fac78fa08c099dc6f96d Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Sun, 7 Mar 2021 19:10:58 -0600 Subject: [PATCH 1/2] clip glyphs that exceed ascent property --- adafruit_display_text/bitmap_label.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index bb5c723..6a470aa 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -478,13 +478,31 @@ def _place_text( ) # for type BuiltinFont, this creates the x-offset in the glyph bitmap. # for BDF loaded fonts, this should equal 0 + y_blit_target = yposition - my_glyph.height - my_glyph.dy + + # Clip glyph y-direction if outside the font ascent/descent metrics. + # Note: bitmap.blit will automatically clip the bottom of the glyph. + y_clip = 0 + if (y_blit_target) < 0: + y_clip = -(y_blit_target) # clip this amount from top of bitmap + y_blit_target = 0 # draw the clipped bitmap at y=0 + + print( + 'Warning: Glyph exceeds Ascent/Descent properties: "{}"'.format( + char + ) + ) + self._blit( bitmap, xposition + my_glyph.dx, - yposition - my_glyph.height - my_glyph.dy, + y_clip + + yposition + - my_glyph.height + - my_glyph.dy, ##### ****** my_glyph.bitmap, x_1=glyph_offset_x, - y_1=0, + y_1=y_clip, x_2=glyph_offset_x + my_glyph.width, y_2=0 + my_glyph.height, skip_index=skip_index, # do not copy over any 0 background pixels From c1451ddc8e016e50020406107e29c002fb310558 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Sun, 7 Mar 2021 19:24:15 -0600 Subject: [PATCH 2/2] add separate check for descent clipping --- adafruit_display_text/bitmap_label.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index 6a470aa..00b96bc 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -488,7 +488,14 @@ def _place_text( y_blit_target = 0 # draw the clipped bitmap at y=0 print( - 'Warning: Glyph exceeds Ascent/Descent properties: "{}"'.format( + 'Warning: Glyph clipped, exceeds Ascent property: "{}"'.format( + char + ) + ) + + if (y_blit_target + my_glyph.height) > bitmap.height: + print( + 'Warning: Glyph clipped, exceeds descent property: "{}"'.format( char ) ) @@ -496,15 +503,12 @@ def _place_text( self._blit( bitmap, xposition + my_glyph.dx, - y_clip - + yposition - - my_glyph.height - - my_glyph.dy, ##### ****** + y_blit_target, my_glyph.bitmap, x_1=glyph_offset_x, y_1=y_clip, x_2=glyph_offset_x + my_glyph.width, - y_2=0 + my_glyph.height, + y_2=my_glyph.height, skip_index=skip_index, # do not copy over any 0 background pixels )