Skip to content

Commit

Permalink
Avoid float collision with box establishing formatting context
Browse files Browse the repository at this point in the history
Related to #2019.
  • Loading branch information
liZe committed Sep 27, 2024
1 parent d5d71af commit af99050
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 0 additions & 2 deletions weasyprint/formatting_structure/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ def is_monolithic(self):
def establishes_formatting_context(self):
"""Return whether this box establishes a block formatting context."""
# See https://www.w3.org/TR/CSS2/visuren.html#block-formatting
# TODO: columns shouldn't be block boxes, this condition would then be
# useless when this is fixed
return (
self.is_floated() or
self.is_absolutely_positioned() or
Expand Down
7 changes: 5 additions & 2 deletions weasyprint/layout/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ def block_box_layout(context, box, bottom_space, skip_stack,
result = block_container_layout(
context, box, bottom_space, skip_stack, page_is_empty,
absolute_boxes, fixed_boxes, adjoining_margins, discard, max_lines)
new_box = result[0]
if new_box and new_box.is_table_wrapper:
# TODO: columns shouldn't be block boxes, this condition would then be
# useless when this is fixed.
if not (new_box := result[0]) or new_box.is_column:
return result
if new_box.is_table_wrapper or new_box.establishes_formatting_context():
# Don't collide with floats
# https://www.w3.org/TR/CSS21/visuren.html#floats
position_x, position_y, _ = avoid_collisions(
Expand Down
5 changes: 3 additions & 2 deletions weasyprint/layout/float.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,13 @@ def avoid_collisions(context, box, containing_block, outer=True):
# - line boxes
# - table wrappers
# - block-level replaced box
# - element establishing new formatting contexts (not handled)
# - element establishing new formatting contexts
assert (
(box.style['float'] in ('right', 'left')) or
isinstance(box, boxes.LineBox) or
box.is_table_wrapper or
isinstance(box, boxes.BlockReplacedBox))
isinstance(box, boxes.BlockReplacedBox) or
box.establishes_formatting_context())

# The x-position of the box depends on its type.
position_x = max_left_bound
Expand Down

0 comments on commit af99050

Please sign in to comment.