adafruit / Adafruit_CircuitPython_Display_Text

Library to display text using displayio
MIT License
57 stars 38 forks source link

Ignore characters that are not printable in wrap_text_to_pixels #179

Closed Neradoc closed 1 year ago

Neradoc commented 1 year ago

Setting a label's text to a string containing unprintable characters doesn't error but has the character ignored. Calling wrap_text_to_pixels() on the same string however raises an error.

Test code:

import board
import displayio
import terminalio
import time
from adafruit_display_text.label import Label
from adafruit_display_text import wrap_text_to_pixels

# setup the display if not built-in
display = board.DISPLAY

label = Label(x=0, y=20, font=terminalio.FONT, color=0xFFFFFF, scale=4)
display.show(label)

TEST_STRING = "--§§--\r\n--"
label.text = TEST_STRING
time.sleep(1)
out = wrap_text_to_pixels(
    TEST_STRING,
    font=terminalio.FONT,
    max_width=64
)
label.text = "\n".join(out)
while True: pass

Before:

Traceback (most recent call last):
  File "code.py", line 19, in <module>
  File "adafruit_display_text/__init__.py", line 69, in wrap_text_to_pixels
  File "adafruit_display_text/__init__.py", line 59, in measure
  File "adafruit_display_text/__init__.py", line 59, in <genexpr>
AttributeError: 'NoneType' object has no attribute 'shift_x'

After:

dashdashdash

Also fixes #177