Skip to content
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

Ignore characters that are not printable in wrap_text_to_pixels #179

Merged
merged 1 commit into from
Dec 31, 2022

Conversation

Neradoc
Copy link
Contributor

@Neradoc Neradoc commented Dec 30, 2022

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

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for the fix @Neradoc.

Tested successfully on PyPortal Titano with 8.0.0 beta6

@FoamyGuy FoamyGuy merged commit 4039615 into adafruit:main Dec 31, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jan 1, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.22.13 from 2.22.12:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#179 from Neradoc/wrap_text_to_pixels-no-bad-char
  > Add .venv to .gitignore
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrap_text_to_pixels() cannot handle Windows line endings
2 participants