Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle float rounding when extending boxes over page breaks #1559

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/layout/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,40 @@ def test_page_breaks(html):
for page_child in page_children] == [[10, 40], [10, 40], [10]]


@assert_no_logs
def test_page_breaks_box_split():
# If floats round the wrong way, a block that gets filled to the end of a
# page due to breaking over the page may be forced onto the next page
# because it is slightly taller than can fit on the previous page, even if
# it wouldn't have been without being filled. These numbers aren't ideal,
# but they do seem to trigger the issue.
page_1, page_2 = render_pages('''
<style>
@page { size: 982.4146981627297px; margin: 0 }
div { font-size: 5px; height: 200.0123456789px; margin: 0; padding: 0 }
figure { margin: 0; padding: 0 }
</style>
<div>text</div>
<div>text</div><!-- no page break here -->
<section>
<div>line1</div>
<div>line2</div><!-- page break here -->
<div>line3</div>
<div>line4</div>
</section>
''')
html, = page_1.children
body, = html.children
assert len(body.children) == 3
div1, div2, section = body.children
assert len(section.children) == 2

html, = page_2.children
body, = html.children
section, = body.children
assert len(section.children) == 2


@assert_no_logs
def test_page_breaks_complex_1():
page_1, page_2, page_3, page_4 = render_pages('''
Expand Down
8 changes: 7 additions & 1 deletion weasyprint/layout/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,13 @@ def _in_flow_layout(context, box, index, child, new_children, page_is_empty,
new_position_y = (
new_child.border_box_y() + new_child.border_height())

if (new_content_position_y > context.page_bottom - bottom_space and
# Use a small fudge factor on this due to box splitting setting the
# height of some elements to the remaining height of the page:
# https://www.w3.org/TR/css-break-3/#box-splitting
# (Occasionally the order of this calculation would otherwise come
# out with unequal float values, forcing the box to the next page.)
if (new_content_position_y >
context.page_bottom - bottom_space + 0.001 and
not page_is_empty_with_no_children):
# The child content overflows the page area, display it on the
# next page.
Expand Down