Skip to content

Commit cc09489

Browse files
committed
clip glyphs that exceed ascent property
1 parent d91f5d3 commit cc09489

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

adafruit_display_text/bitmap_label.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,31 @@ def _place_text(
478478
) # for type BuiltinFont, this creates the x-offset in the glyph bitmap.
479479
# for BDF loaded fonts, this should equal 0
480480

481+
y_blit_target = yposition - my_glyph.height - my_glyph.dy
482+
483+
# Clip glyph y-direction if outside the font ascent/descent metrics.
484+
# Note: bitmap.blit will automatically clip the bottom of the glyph.
485+
y_clip = 0
486+
if (y_blit_target) < 0:
487+
y_clip = -(y_blit_target) # clip this amount from top of bitmap
488+
y_blit_target = 0 # draw the clipped bitmap at y=0
489+
490+
print(
491+
'Warning: Glyph exceeds Ascent/Descent properties: "{}"'.format(
492+
char
493+
)
494+
)
495+
481496
self._blit(
482497
bitmap,
483498
xposition + my_glyph.dx,
484-
yposition - my_glyph.height - my_glyph.dy,
499+
y_clip
500+
+ yposition
501+
- my_glyph.height
502+
- my_glyph.dy, ##### ******
485503
my_glyph.bitmap,
486504
x_1=glyph_offset_x,
487-
y_1=0,
505+
y_1=y_clip,
488506
x_2=glyph_offset_x + my_glyph.width,
489507
y_2=0 + my_glyph.height,
490508
skip_index=skip_index, # do not copy over any 0 background pixels

0 commit comments

Comments
 (0)