Skip to content

Commit

Permalink
Fix a linebox breaking corner case
Browse files Browse the repository at this point in the history
Fix #660.

As said in the (very helpful) comment at the beginning of the modified block,
we have to add "child_resume_at" and "initial_skip_stack[1]" skip stacks, but
the old algorithm was obviously wrong when the stacks had more than one level
of depth.

The fix is shorter, easier to read and right (until next bug). A regression
test has been added too.
  • Loading branch information
liZe committed Jul 31, 2018
1 parent d07ac58 commit 81b3ee6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
28 changes: 13 additions & 15 deletions weasyprint/layout/inlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,22 +856,20 @@ def split_inline_box(context, box, position_x, max_x, skip_stack,
# 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)
current_skip_stack = initial_skip_stack[1]
current_resume_at = child_resume_at
stack = []
while current_skip_stack and current_resume_at:
skip_stack, current_skip_stack = (
current_skip_stack)
resume_at, current_resume_at = (
current_resume_at)
stack.append(skip_stack + resume_at)
child_resume_at = (
current_resume_at + current_skip,
grandchild_resume_at)
current_skip_stack or current_resume_at)
while stack:
child_resume_at = (
stack.pop(), child_resume_at)

resume_at = (child_index, child_resume_at)
break
Expand Down
17 changes: 17 additions & 0 deletions weasyprint/tests/test_layout/test_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,23 @@ def test_breaking_linebox_regression_6():
assert line2.children[0].children[0].text == '/ccc'


@assert_no_logs
def test_breaking_linebox_regression_7():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/660
page, = parse(
'<style>@font-face { src: url(AHEM____.TTF); font-family: ahem }</style>'
'<div style="width: 3.5em; font-family: ahem">'
'<span><span>abc d e</span></span><span>f')
html, = page.children
body, = html.children
div, = body.children
line1, line2, line3 = div.children
assert line1.children[0].children[0].children[0].text == 'abc'
assert line2.children[0].children[0].children[0].text == 'd'
assert line3.children[0].children[0].children[0].text == 'e'
assert line3.children[1].children[0].text == 'f'


@assert_no_logs
def test_linebox_text():
page, = parse('''
Expand Down

0 comments on commit 81b3ee6

Please sign in to comment.