From 6a3e7bf4f87d334cbb15a072cb61c1306ebdf5eb Mon Sep 17 00:00:00 2001 From: Neradoc Date: Fri, 30 Dec 2022 03:30:16 +0100 Subject: [PATCH] Ignore characters that are not printable in wrap_text_to_pixels to match Label --- adafruit_display_text/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) mode change 100644 => 100755 adafruit_display_text/__init__.py diff --git a/adafruit_display_text/__init__.py b/adafruit_display_text/__init__.py old mode 100644 new mode 100755 index a3814e7..6586857 --- a/adafruit_display_text/__init__.py +++ b/adafruit_display_text/__init__.py @@ -56,7 +56,12 @@ def measure(text): font.load_glyphs(string) def measure(text): - return sum(font.get_glyph(ord(c)).shift_x for c in text) + total_len = 0 + for char in text: + this_glyph = font.get_glyph(ord(char)) + if this_glyph: + total_len += this_glyph.shift_x + return total_len lines = [] partial = [indent0]