Skip to content

Commit

Permalink
Sanitize simplified line breaking
Browse files Browse the repository at this point in the history
The special case that an already broken child must be split again confronts
us with two skip stacks: The initial (absolute) and the adjusted (partial)
stack. Often the new stack is a relative one and (carefully) adding both
stacks is ok. But the following must be observed:

- The first number of the combined stack has to be the index of the child
  we broke twice.
- A child index bigger than the starting index of the initial stack denotes
  that the new skip stack is an absolute stack. Don't add nothing.

Should fix Kozea#953
  • Loading branch information
Tontyna committed Oct 3, 2019
1 parent 0a403d9 commit ecbacef
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions weasyprint/layout/inlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,11 +858,27 @@ def split_inline_box(context, box, position_x, max_x, skip_stack,
# add the original skip stack to the partial
# skip stack we get after the new rendering.

# We have to do:
# resume_at + initial_skip_stack
# but adding skip stacks is a bit complicated
current_skip_stack = initial_skip_stack
current_resume_at = (child_index, child_resume_at)
# Combining skip stacks is a bit complicated
# We have to:
# - set `child_index` as the first number
# - append the new stack if it's an absolute one
# - otherwise append the combined stacks
# (resume_at + initial_skip_stack)

# extract the initial index
if initial_skip_stack is None:
current_skip_stack = None
initial_index = 0
else:
initial_index, current_skip_stack = (
initial_skip_stack)
# child_resume_at is an absolute skip stack
if child_index > initial_index:
resume_at = (child_index, child_resume_at)
break

# combine the stacks
current_resume_at = child_resume_at
stack = []
while current_skip_stack and current_resume_at:
skip, current_skip_stack = (
Expand All @@ -875,6 +891,8 @@ def split_inline_box(context, box, position_x, max_x, skip_stack,
resume_at = current_resume_at
while stack:
resume_at = (stack.pop(), resume_at)
# insert the child index
resume_at = (child_index, resume_at)
break
if break_found:
break
Expand Down

0 comments on commit ecbacef

Please sign in to comment.