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>
This commit is contained in:
parent
86cc4844b6
commit
402801c538
1 changed files with 9 additions and 5 deletions
|
@ -370,15 +370,19 @@ class Draw565(object):
|
||||||
if i >= len(s):
|
if i >= len(s):
|
||||||
break
|
break
|
||||||
ch = s[i]
|
ch = s[i]
|
||||||
if ch == '\n':
|
|
||||||
end = i+1
|
|
||||||
break
|
|
||||||
if ch == ' ':
|
|
||||||
end = i+1
|
|
||||||
(_, h, w) = font.get_ch(ch)
|
(_, h, w) = font.get_ch(ch)
|
||||||
l += w + 1
|
l += w + 1
|
||||||
if l > width:
|
if l > width:
|
||||||
break
|
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
|
||||||
if end <= start:
|
if end <= start:
|
||||||
end = i
|
end = i
|
||||||
chunks.append(end)
|
chunks.append(end)
|
||||||
|
|
Loading…
Reference in a new issue