Don't optimize resume_at when splitting lines with trailing spaces

Fix #586.

For some reason I don't really understand, stripping trailing spaces that would
make the line too long can't be optimized when the space is at the end of the
block. Returning None instead of the index of the last letter should be
possible, but it breaks the rendering when the first letter of the next line
box starts with a character that doesn't allow line breaks after spaces (many
punctuation characters for example) and that doesn't allow line wrap.

This change shouldn't be harmful, as the removed code lines were just cleaning
the resume_at value without changing the logic of line breaking. I suppose that
there's a bug somewhere else.
This commit is contained in:
Guillaume Ayoub 2018-03-10 00:26:11 +01:00
parent f8993cacb0
commit a859d8d599
2 changed files with 12 additions and 3 deletions

View File

@ -738,7 +738,7 @@ def test_breaking_linebox():
assert line3.children[0].children[0].text == 'c'
assert line3.children[1].text == 'd'
# Regression test #1 for https://github.com/Kozea/WeasyPrint/issues/580
# Regression test for https://github.com/Kozea/WeasyPrint/issues/580
page, = parse(
'<div style="width: 5.5em; font-family: ahem">'
'<span>aaaa aaaa a a a</span><span>bc</span>')
@ -752,6 +752,17 @@ def test_breaking_linebox():
assert line4.children[0].children[0].text == 'a'
assert line4.children[1].children[0].text == 'bc'
# Regression test for https://github.com/Kozea/WeasyPrint/issues/586
page, = parse(
'<div style="width: 5.5em; font-family: ahem">'
'a a <span style="white-space: nowrap">/ccc</span>')
html, = page.children
body, = html.children
div, = body.children
line1, line2 = div.children
assert line1.children[0].text == 'a a'
assert line2.children[0].children[0].text == '/ccc'
@assert_no_logs
def test_linebox_text():

View File

@ -1001,8 +1001,6 @@ def split_first_line(text, style, context, max_width, justification_spacing,
if second_line is None and first_line_text:
# The next word fits in the first line, keep the layout
resume_at = len(new_first_line_text.encode('utf-8')) + 1
if resume_at == len(text.encode('utf-8')):
resume_at = None
return first_line_metrics(
first_line, text, layout, resume_at, space_collapse, style)
elif second_line: