Skip to content

Commit

Permalink
Fix same_broken_child
Browse files Browse the repository at this point in the history
The old code assumed that both skip stacks were absolute, but for the second
one previous children have already been skipped. We now check that we're in
the first child at each level, meaning that we're still breaking the same
child.

Related to #923.
  • Loading branch information
grewn0uille committed Sep 12, 2019
1 parent 16912bf commit 9581407
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
15 changes: 10 additions & 5 deletions weasyprint/layout/inlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,12 +1294,17 @@ def can_break_inside(box):
return False


def same_broken_child(skip_stack_1, skip_stack_2):
def same_broken_child(original_skip_stack, relative_skip_stack):
"""Check that the skip stacks design the same text box."""
while isinstance(skip_stack_1, tuple) and isinstance(skip_stack_2, tuple):
if skip_stack_1[1] is None and skip_stack_2[1] is None:
while (isinstance(original_skip_stack, tuple) and
isinstance(relative_skip_stack, tuple)):
if original_skip_stack[1] is None and relative_skip_stack[1] is None:
# The last levels of the two skip_stack are the same
return True
if skip_stack_1[0] != skip_stack_2[0]:
if relative_skip_stack[0] != 0:
# If at the current level the skip_stack is not 0, it means that
# it is not the first child that has been cut
return False
skip_stack_1, skip_stack_2 = skip_stack_1[1], skip_stack_2[1]
original_skip_stack = original_skip_stack[1]
relative_skip_stack = relative_skip_stack[1]
return False
21 changes: 21 additions & 0 deletions weasyprint/tests/test_layout/test_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,27 @@ def test_breaking_linebox_regression_9():
assert line2.children[1].text == 'ddd'


@assert_no_logs
def test_breaking_linebox_regression_10():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/923
page, = parse(
'<style>@font-face {src: url(AHEM____.TTF); font-family: ahem}</style>'
'<p style="width:195px; font-family: ahem">'
' <span>'
' <span>xxxxxx YYY yyyyyy yyy</span>'
' ZZZZZZ zzzzz'
' </span> )x '
'</p>')
html, = page.children
body, = html.children
p, = body.children
line1, line2, line3, line4 = p.children
assert line1.children[0].children[0].children[0].text == 'xxxxxx YYY'
assert line2.children[0].children[0].children[0].text == 'yyyyyy yyy'
assert line3.children[0].children[0].text == 'ZZZZZZ zzzzz'
assert line4.children[0].text == ')x'


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

0 comments on commit 9581407

Please sign in to comment.