Skip to content

Commit

Permalink
Define monolithic boxes
Browse files Browse the repository at this point in the history
Related to #1936.
  • Loading branch information
liZe committed Aug 20, 2023
1 parent 0ffeb82 commit 2326bcc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
10 changes: 10 additions & 0 deletions weasyprint/formatting_structure/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ def is_in_normal_flow(self):
self.is_floated() or self.is_absolutely_positioned() or
self.is_running() or self.is_footnote())

def is_monolithic(self):
"""Return whether this box is monolithic."""
# https://www.w3.org/TR/css-break-3/#monolithic
return (
isinstance(self, AtomicInlineLevelBox) or
isinstance(self, ReplacedBox) or
self.style['overflow'] in ('auto', 'scroll') or
(self.style['overflow'] == 'hidden' and
self.style['height'] != 'auto'))

# Start and end page values for named pages

def page_values(self):
Expand Down
22 changes: 12 additions & 10 deletions weasyprint/layout/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,11 @@ def _out_of_flow_layout(context, box, index, child, new_children,
# New page if overflow
page_overflow = context.overflows_page(
bottom_space, new_child.position_y + new_child.height)
if box.style['overflow'] == 'hidden' and box.style['height'] != 'auto':
page_overflow = False
if (page_is_empty and not new_children) or not page_overflow:
add_child = (
(page_is_empty and not new_children) or
not page_overflow or
box.is_monolithic())
if add_child:
new_child.index = index
new_children.append(new_child)
else:
Expand Down Expand Up @@ -501,19 +503,19 @@ def _in_flow_layout(context, box, index, child, new_children, page_is_empty,
new_child.content_box_y() + new_child.height)
new_position_y = (
new_child.border_box_y() + new_child.border_height())
page_overflow = context.overflows_page(
content_page_overflow = context.overflows_page(
bottom_space, new_content_position_y)
if (box.style['overflow'] == 'hidden' and
box.style['height'] != 'auto'):
page_overflow = False
if page_overflow and not page_is_empty_with_no_children:
border_page_overflow = context.overflows_page(
bottom_space, new_position_y)
can_break = not (
page_is_empty_with_no_children or box.is_monolithic())
if can_break and content_page_overflow:
# The child content overflows the page area, display it on the
# next page.
remove_placeholders(
context, [new_child], absolute_boxes, fixed_boxes)
new_child = None
elif not page_is_empty_with_no_children and context.overflows_page(
bottom_space, new_position_y):
elif can_break and border_page_overflow:
# The child border/padding overflows the page area, do the
# layout again with a higher bottom_space value.
remove_placeholders(
Expand Down

0 comments on commit 2326bcc

Please sign in to comment.