0 | |
From: Scott Kitterman <scott@kitterman.com>
|
1 | |
Date: Fri, 18 Oct 2019 11:57:19 -0400
|
2 | |
Subject: Revert upstream simplify line breaking
|
3 | |
|
4 | |
---
|
5 | |
weasyprint/layout/inlines.py | 68 ++++++++++++++++++++++++++++++--------------
|
6 | |
1 file changed, 46 insertions(+), 22 deletions(-)
|
7 | |
|
8 | |
diff --git a/weasyprint/layout/inlines.py b/weasyprint/layout/inlines.py
|
9 | |
index 4d3f9fd..e474e71 100644
|
10 | |
--- a/weasyprint/layout/inlines.py
|
11 | |
+++ b/weasyprint/layout/inlines.py
|
12 | |
@@ -853,28 +853,36 @@ def split_inline_box(context, box, position_x, max_x, skip_stack,
|
13 | |
else:
|
14 | |
children += [(child_index, child_new_child)]
|
15 | |
|
16 | |
- # As this child has already been broken
|
17 | |
- # following the original skip stack, we have to
|
18 | |
- # add the original skip stack to the partial
|
19 | |
- # skip stack we get after the new rendering.
|
20 | |
-
|
21 | |
- # We have to do:
|
22 | |
- # resume_at + initial_skip_stack
|
23 | |
- # but adding skip stacks is a bit complicated
|
24 | |
- current_skip_stack = initial_skip_stack
|
25 | |
- current_resume_at = (child_index, child_resume_at)
|
26 | |
- stack = []
|
27 | |
- while current_skip_stack and current_resume_at:
|
28 | |
- skip, current_skip_stack = (
|
29 | |
- current_skip_stack)
|
30 | |
- resume, current_resume_at = (
|
31 | |
- current_resume_at)
|
32 | |
- stack.append(skip + resume)
|
33 | |
- if resume != 0:
|
34 | |
- break
|
35 | |
- resume_at = current_resume_at
|
36 | |
- while stack:
|
37 | |
- resume_at = (stack.pop(), resume_at)
|
38 | |
+ # We have to check whether the child we're breaking
|
39 | |
+ # is the one broken by the initial skip stack.
|
40 | |
+ broken_child = same_broken_child(
|
41 | |
+ initial_skip_stack,
|
42 | |
+ (child_index, child_resume_at))
|
43 | |
+ if broken_child:
|
44 | |
+ # As this child has already been broken
|
45 | |
+ # following the original skip stack, we have to
|
46 | |
+ # add the original skip stack to the partial
|
47 | |
+ # skip stack we get after the new rendering.
|
48 | |
+
|
49 | |
+ # We have to do:
|
50 | |
+ # child_resume_at += initial_skip_stack[1]
|
51 | |
+ # but adding skip stacks is a bit complicated
|
52 | |
+ current_skip_stack = initial_skip_stack[1]
|
53 | |
+ current_resume_at = child_resume_at
|
54 | |
+ stack = []
|
55 | |
+ while current_skip_stack and current_resume_at:
|
56 | |
+ skip_stack, current_skip_stack = (
|
57 | |
+ current_skip_stack)
|
58 | |
+ resume_at, current_resume_at = (
|
59 | |
+ current_resume_at)
|
60 | |
+ stack.append(skip_stack + resume_at)
|
61 | |
+ child_resume_at = (
|
62 | |
+ current_skip_stack or current_resume_at)
|
63 | |
+ while stack:
|
64 | |
+ child_resume_at = (
|
65 | |
+ stack.pop(), child_resume_at)
|
66 | |
+
|
67 | |
+ resume_at = (child_index, child_resume_at)
|
68 | |
break
|
69 | |
if break_found:
|
70 | |
break
|
71 | |
@@ -1284,3 +1292,19 @@ def can_break_inside(box):
|
72 | |
else:
|
73 | |
return False
|
74 | |
return False
|
75 | |
+
|
76 | |
+
|
77 | |
+def same_broken_child(original_skip_stack, relative_skip_stack):
|
78 | |
+ """Check that the skip stacks design the same text box."""
|
79 | |
+ while (isinstance(original_skip_stack, tuple) and
|
80 | |
+ isinstance(relative_skip_stack, tuple)):
|
81 | |
+ if original_skip_stack[1] is None and relative_skip_stack[1] is None:
|
82 | |
+ # The last levels of the two skip_stack are the same
|
83 | |
+ return True
|
84 | |
+ if relative_skip_stack[0] != 0:
|
85 | |
+ # If at the current level the skip_stack is not 0, it means that
|
86 | |
+ # it is not the first child that has been cut
|
87 | |
+ return False
|
88 | |
+ original_skip_stack = original_skip_stack[1]
|
89 | |
+ relative_skip_stack = relative_skip_stack[1]
|
90 | |
+ return False
|