summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2021-03-22 08:29:06 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2021-03-22 08:29:06 (GMT)
commit402801c5388db59b16cdfcdbce0b429f91f61bbc (patch)
treea4ae28cedf9448f6d2e1c442bcbcb68acb2acfe0
parent86cc4844b6cb8278789971d9fb0afdb710e8d253 (diff)
draw565: Avoid over-long lines when handling space
Currently, if the line wrapper attempts to break a line on a space and that space character is outside the bounding box, then we generate an over-long line. Fix this by handling line break generation *after* we have checked the length of the current line. Fixes: #193 Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
-rw-r--r--wasp/draw565.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/wasp/draw565.py b/wasp/draw565.py
index f82a345..c84b1ec 100644
--- a/wasp/draw565.py
+++ b/wasp/draw565.py
@@ -370,15 +370,19 @@ class Draw565(object):
if i >= len(s):
break
ch = s[i]
+ (_, h, w) = font.get_ch(ch)
+ l += w + 1
+ if l > width:
+ break
+
+ # Break the line immediately if requested
if ch == '\n':
end = i+1
break
+
+ # Remember the right-most place we can cleanly break the line
if ch == ' ':
end = i+1
- (_, h, w) = font.get_ch(ch)
- l += w + 1
- if l > width:
- break
if end <= start:
end = i
chunks.append(end)