From ecbacef14f03cd97dd6b3fa5857161430cc34449 Mon Sep 17 00:00:00 2001 From: Tontyna <35614937+Tontyna@users.noreply.github.com> Date: Thu, 3 Oct 2019 17:50:05 +0200 Subject: [PATCH] Sanitize simplified line breaking 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 #953 --- weasyprint/layout/inlines.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/weasyprint/layout/inlines.py b/weasyprint/layout/inlines.py index 4d3f9fdb..c0ebbb55 100644 --- a/weasyprint/layout/inlines.py +++ b/weasyprint/layout/inlines.py @@ -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 = ( @@ -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