Skip to content

Commit 5f8931f

Browse files
committed
fix text bbox - shift text
1 parent 37bda92 commit 5f8931f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/lcd/lcd_comm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,13 @@ def DisplayText(
208208
# Draw text with specified color & font
209209
font = ImageFont.truetype("./res/fonts/" + font, font_size)
210210
d = ImageDraw.Draw(text_image)
211-
d.text((x, y), text, font=font, fill=font_color)
212211

213212
# Crop text bitmap to keep only the text (also crop if text overflows display)
214213
left, top, text_width, text_height = d.textbbox((0, 0), text, font=font)
214+
d.text((x-left, y-top), text, font=font, fill=font_color)
215+
215216
text_image = text_image.crop(box=(
216-
x + left, y + top,
217+
x, y,
217218
min(x + text_width, self.get_width()),
218219
min(y + text_height, self.get_height())
219220
))

0 commit comments

Comments
 (0)