Spaces are deleted when word-wrapping
kmatch98 opened this issue · 1 comments
I noticed that some spaces are being deleted when word-wrapping text using the wrap_text_to_pixels
function in the adafruit_display_text
library. Library is pulled from bundle adafruit-circuitpython-bundle-7.x-mpy-20220131
.
I use a long string with long words and a narrow pixel width, and it causes some spaces to be deleted , such as in:
- simplifyexp - "simplify experimenting"
- low-costmic - "low-cost microcontroller boards"
Here's the output I'm getting:
code.py output:
width: 75
text_lines: ['CircuitPyth-', 'on is a', 'programming', 'language', 'designed to', 'simplifyexp-', 'erimenting',
'and learning', 'to code on', 'low-costmic-', 'rocontrolle-', 'r boards.', '', 'WithCircuit-', 'Python,', 'there are no',
'upfront', 'desktop', 'downloads', 'needed. Once', 'you get your', 'board set', 'up, open any', 'text editor,',
'and start', 'editing', "code. It's", 'that simple.']
Here's my code:
import terminalio
from adafruit_display_text import bitmap_label, wrap_text_to_pixels
text_string = "CircuitPython is a programming language designed to simplify experimenting and learning to code on low-cost microcontroller boards."
text_string=text_string+("\n\nWith CircuitPython, there are no upfront desktop downloads needed. Once you get your board set up, open any text editor, and start editing code. It's that simple.")
width=75
text_lines = wrap_text_to_pixels(text_string, width, terminalio.FONT)
print("width: {}".format(width))
print('text_lines: {}'.format(text_lines))
while True:
pass
At first glance, I think the issue is here
Adafruit_CircuitPython_Display_Text/adafruit_display_text/__init__.py
Lines 70 to 91 in 1a9edbd
This code should add a space before placing a word if it’s not the initial word in a line. This can be detected by seeing if partial == indent0
when firstword == True
or partial == indent1
when firstword==False
.