From a859d8d599ef23dd15d51e9711e0aed2ff7dd654 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Sat, 10 Mar 2018 00:26:11 +0100 Subject: [PATCH] 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. --- weasyprint/tests/test_layout.py | 13 ++++++++++++- weasyprint/text.py | 2 -- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/weasyprint/tests/test_layout.py b/weasyprint/tests/test_layout.py index fe315592..5cbc3f59 100644 --- a/weasyprint/tests/test_layout.py +++ b/weasyprint/tests/test_layout.py @@ -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( '
' 'aaaa aaaa a a abc') @@ -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( + '
' + 'a a /ccc') + 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(): diff --git a/weasyprint/text.py b/weasyprint/text.py index 6e8a7c97..6a65743b 100644 --- a/weasyprint/text.py +++ b/weasyprint/text.py @@ -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: