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

Page break after avoid #201

Merged
merged 5 commits into from
Jun 19, 2014
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
14 changes: 14 additions & 0 deletions weasyprint/layout/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,20 @@ def block_container_layout(context, box, max_position_y, skip_stack,
new_child.index = index
new_children.append(new_child)
else:

for previous_child in reversed(new_children):
if previous_child.is_in_normal_flow():
last_in_flow_child = previous_child
break
if new_children and block_level_page_break(
last_in_flow_child,
child
) == 'avoid':
result = find_earlier_page_break(
new_children, absolute_boxes, fixed_boxes)
if result:
new_children, resume_at = result
break
resume_at = (index, None)
break
continue
Expand Down
106 changes: 106 additions & 0 deletions weasyprint/tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4583,6 +4583,112 @@ def test_floats_page_breaks():
for images in page_images]
assert positions_y == [[10, 40], [10, 40], [10]]

# last float does not fit, pushed to next page
pages = parse('''
<style>
@page{
size: 110px;
margin: 10px;
padding: 0;
}
.large {
width: 10px;
height: 60px;
}
.small {
width: 10px;
height: 20px;
}
</style>
<body>
<div class="large"></div>
<div class="small"></div>
<div class="large"></div>
''')

assert len(pages) == 2
page_divs = []
for page in pages:
divs = [div for div in page.descendants() if div.element_tag == 'div']
assert all([div.element_tag == 'div' for div in divs])
page_divs.append(divs)
del divs

positions_y = [[div.position_y for div in divs] for divs in page_divs]
assert positions_y == [[10, 70], [10]]

# last float does not fit, pushed to next page
# center div must not
pages = parse('''
<style>
@page{
size: 110px;
margin: 10px;
padding: 0;
}
.large {
width: 10px;
height: 60px;
}
.small {
width: 10px;
height: 20px;
page-break-after: avoid;
}
</style>
<body>
<div class="large"></div>
<div class="small"></div>
<div class="large"></div>
''')

assert len(pages) == 2
page_divs = []
for page in pages:
divs = [div for div in page.descendants() if div.element_tag == 'div']
assert all([div.element_tag == 'div' for div in divs])
page_divs.append(divs)
del divs

positions_y = [[div.position_y for div in divs] for divs in page_divs]
assert positions_y == [[10], [10, 30]]

# center div must be the last element,
# but float won't fit and will get pushed anyway
pages = parse('''
<style>
@page{
size: 110px;
margin: 10px;
padding: 0;
}
.large {
width: 10px;
height: 80px;
}
.small {
width: 10px;
height: 20px;
page-break-after: avoid;
}
</style>
<body>
<div class="large"></div>
<div class="small"></div>
<div class="large"></div>
''')

assert len(pages) == 3
page_divs = []
for page in pages:
divs = [div for div in page.descendants() if div.element_tag == 'div']
assert all([div.element_tag == 'div' for div in divs])
page_divs.append(divs)
del divs

positions_y = [[div.position_y for div in divs] for divs in page_divs]
assert positions_y == [[10], [10], [10]]


@assert_no_logs
def test_font_stretch():
Expand Down