From 8f725e24ad229f6ccb923d091e02ad47b543be46 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 27 Feb 2018 01:16:27 +0100 Subject: [PATCH] Fix inline box breaking function Fix #580. --- weasyprint/layout/inlines.py | 46 +++++++++++++++++++-------------- weasyprint/tests/test_layout.py | 22 +++++++++++++--- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/weasyprint/layout/inlines.py b/weasyprint/layout/inlines.py index 3c93b81b..525de409 100644 --- a/weasyprint/layout/inlines.py +++ b/weasyprint/layout/inlines.py @@ -792,23 +792,6 @@ def split_inline_box(context, box, position_x, max_x, skip_stack, # let's break it! break_found = True - # We have to check whether the child we're breaking - # is the one broken by the initial skip stack. - broken_child = bool( - initial_skip_stack and - initial_skip_stack[0] == child_index and - initial_skip_stack[1]) - if broken_child: - # This child is already broken by the original - # skip stack, let's skip the already rendered - # part before rendering the waiting child - # again. - current_skip, child_skip = ( - initial_skip_stack[1]) - else: - # This child has to be rendered from its start. - child_skip = None - # We break the waiting child at its last possible # breaking point. # TODO: The dirty solution chosen here is to @@ -819,7 +802,7 @@ def split_inline_box(context, box, position_x, max_x, skip_stack, child_new_child, child_resume_at, _, _, _ = ( split_inline_level( context, child, child.position_x, max_x, - child_skip, box, device_size, + None, box, device_size, absolute_boxes, fixed_boxes, line_placeholders, waiting_floats, line_children)) @@ -830,14 +813,37 @@ def split_inline_box(context, box, position_x, max_x, skip_stack, else: children += [(child_index, child_new_child)] + # We have to check whether the child we're breaking + # is the one broken by the initial skip stack. + broken_child = bool( + initial_skip_stack and + initial_skip_stack[0] == child_index and + initial_skip_stack[1]) if broken_child: # As this child has already been broken # following the original skip stack, we have to # add the original skip stack to the partial # skip stack we get after the new rendering. + + # We have to do: + # child_resume_at += initial_skip_stack[1] + # but adding skip stacks is a bit complicated + current_skip, grandchild_skip = ( + initial_skip_stack[1]) + current_resume_at, grandchild_resume_at = ( + child_resume_at) + if grandchild_skip is None: + grandchild_resume_at = child_resume_at[1] + elif grandchild_resume_at is None: + grandchild_resume_at = grandchild_skip + else: + grandchild_resume_at = ( + grandchild_skip[0] + + grandchild_resume_at[0], + None) child_resume_at = ( - child_resume_at[0] + current_skip, - child_resume_at[1]) + current_resume_at + current_skip, + grandchild_resume_at) resume_at = (child_index, child_resume_at) break diff --git a/weasyprint/tests/test_layout.py b/weasyprint/tests/test_layout.py index 19e1cfed..fe315592 100644 --- a/weasyprint/tests/test_layout.py +++ b/weasyprint/tests/test_layout.py @@ -715,8 +715,8 @@ def test_breaking_linebox(): 'aaaa aaaa a [aaa]') html, = page.children body, = html.children - pre, = body.children - line1, line2, line3, line4 = pre.children + div, = body.children + line1, line2, line3, line4 = div.children assert line1.children[0].text == line2.children[0].text == 'aaaa' assert line3.children[0].text == 'a' text1, span, text2 = line4.children @@ -730,14 +730,28 @@ def test_breaking_linebox(): 'aaaa a b cd') html, = page.children body, = html.children - pre, = body.children - line1, line2, line3 = pre.children + div, = body.children + line1, line2, line3 = div.children assert line1.children[0].text == 'aaaa' assert line2.children[0].text == 'a ' assert line2.children[1].children[0].text == 'b' 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 + page, = parse( + '
' + 'aaaa aaaa a a abc') + html, = page.children + body, = html.children + div, = body.children + line1, line2, line3, line4 = div.children + assert line1.children[0].children[0].text == 'aaaa' + assert line2.children[0].children[0].text == 'aaaa' + assert line3.children[0].children[0].text == 'a a' + assert line4.children[0].children[0].text == 'a' + assert line4.children[1].children[0].text == 'bc' + @assert_no_logs def test_linebox_text():