Skip to content

Commit 62c06ca

Browse files
authored
Merge pull request #2853 from jurriaan/fix-float-clear-after-page-break
Fix cleared float layout after page breaks
2 parents de5f88a + ef89adf commit 62c06ca

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

tests/draw/test_float.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,44 @@ def test_float_split_clear(assert_pixels):
871871
<article>aa</article>''')
872872

873873

874+
@assert_no_logs
875+
def test_float_split_clear_float(assert_pixels):
876+
assert_pixels('''
877+
BBBB
878+
BBBB
879+
BBBB
880+
BBBB
881+
BBBB
882+
BBBB
883+
BBBB
884+
BBBB
885+
BBBB
886+
BBBB
887+
rrrr
888+
rrrr
889+
''', '''
890+
<style>
891+
@page {
892+
size: 4px;
893+
}
894+
body {
895+
color: red;
896+
font: 2px / 1 weasyprint;
897+
}
898+
div {
899+
color: blue;
900+
float: left;
901+
}
902+
article {
903+
clear: left;
904+
float: left;
905+
text-decoration: underline;
906+
}
907+
</style>
908+
<div>bb bb bb bb bb</div>
909+
<article>aa</article>''')
910+
911+
874912
@assert_no_logs
875913
def test_float_split_clear_empty(assert_pixels):
876914
assert_pixels('''

weasyprint/layout/float.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Layout for floating boxes."""
22

3-
from math import inf
3+
from sys import maxsize
44

55
from ..formatting_structure import boxes
66
from .min_max import handle_min_max_width
@@ -135,7 +135,7 @@ def clear(clear_value, float_value):
135135
for broken_shape in context.broken_out_of_flow:
136136
if broken_shape.is_floated():
137137
if clear(box.style['clear'], broken_shape.style['float']):
138-
return inf
138+
return maxsize
139139
# Hypothetical position is the position of the top border edge
140140
clearance = None
141141
hypothetical_position = box.position_y + collapsed_margin
@@ -155,7 +155,7 @@ def avoid_collisions(context, box, containing_block, outer=True):
155155
box_height = box.margin_height() if outer else box.border_height()
156156

157157
if box.border_height() == 0 and box.is_floated():
158-
return 0, 0, containing_block.width
158+
return 0, position_y, containing_block.width
159159

160160
left_keywords = ['left']
161161
right_keywords = ['right']

0 commit comments

Comments
 (0)