Skip to content

Commit

Permalink
Fix a rounding error when detecting overflows
Browse files Browse the repository at this point in the history
Fix #2100.
  • Loading branch information
liZe committed Mar 18, 2024
1 parent 1ac1594 commit 40d8394
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion weasyprint/layout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,13 @@ def __init__(self, style_for, get_image_from_uri, font_config,
self.dictionaries = {}

def overflows_page(self, bottom_space, position_y):
return self.overflows(self.page_bottom - bottom_space, position_y)

@staticmethod
def overflows(bottom, position_y):
# Use a small fudge factor to avoid floating numbers errors.
# The 1e-9 value comes from PEP 485.
return position_y > (self.page_bottom - bottom_space) * (1 + 1e-9)
return position_y > bottom * (1 + 1e-9)

def create_block_formatting_context(self):
self.excluded_shapes = []
Expand Down
2 changes: 1 addition & 1 deletion weasyprint/layout/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def block_container_layout(context, box, bottom_space, skip_stack,
max_lines)
elif stop:
if box.height != 'auto':
if position_y > box.position_y + box.height:
if context.overflows(box.position_y + box.height, position_y):
# Box heigh is fixed and it doesn’t overflow page, forget
# overflowing children.
resume_at = None
Expand Down

0 comments on commit 40d8394

Please sign in to comment.