Skip to content

clip glyphs that exceed ascent property #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions adafruit_display_text/bitmap_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,37 @@ 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 clipped, exceeds Ascent property: "{}"'.format(
char
)
)

if (y_blit_target + my_glyph.height) > bitmap.height:
print(
'Warning: Glyph clipped, exceeds descent property: "{}"'.format(
char
)
)

self._blit(
bitmap,
xposition + my_glyph.dx,
yposition - my_glyph.height - my_glyph.dy,
y_blit_target,
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,
y_2=my_glyph.height,
skip_index=skip_index, # do not copy over any 0 background pixels
)

Expand Down