summaryrefslogtreecommitdiff
path: root/wasp/draw565.py
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2021-07-22 19:03:59 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2021-07-22 19:04:50 (GMT)
commit0831f79a105329f0dd7cd252b9fcd327415e4f82 (patch)
tree7aa811f39ff53dd1ae6702615966d2d137da25ad /wasp/draw565.py
parent586507753b7ad38b8bfd5ed233929c835a72c878 (diff)
draw565: Improve line wrapping
Currently the final word of wrapped text will always appear as a single word on its own line. Fix this by rearranging the break cases to avoid searching for the most recent space when we get to the end of the text. Fixes: #230 Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
Diffstat (limited to 'wasp/draw565.py')
-rw-r--r--wasp/draw565.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/wasp/draw565.py b/wasp/draw565.py
index 50f5547..c6982ff 100644
--- a/wasp/draw565.py
+++ b/wasp/draw565.py
@@ -366,12 +366,15 @@ class Draw565(object):
l = 0
for i in range(start, max+1):
- if i >= len(s):
+ if i >= max:
+ end = i
break
ch = s[i]
(_, h, w) = font.get_ch(ch)
l += w + 1
if l > width:
+ if end <= start:
+ end = i
break
# Break the line immediately if requested
@@ -382,8 +385,6 @@ class Draw565(object):
# Remember the right-most place we can cleanly break the line
if ch == ' ':
end = i+1
- if end <= start:
- end = i
chunks.append(end)
return chunks