mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-05 00:21:15 +03:00
Add page-break-inside: avoid
This commit is contained in:
parent
248e843a40
commit
f814dc0243
1
CHANGES
1
CHANGES
@ -2,6 +2,7 @@ Version 0.7, released on 2012-XX-XX
|
||||
===================================
|
||||
|
||||
* Support for the ``orphans`` and ``widows`` properties.
|
||||
* Support for ``page-break-inside: avoid``
|
||||
|
||||
|
||||
Version 0.6.1, released on 2012-03-01
|
||||
|
@ -629,9 +629,7 @@ def page_break(keyword):
|
||||
@single_keyword
|
||||
def page_break_inside(keyword):
|
||||
"""Validation for the ``page-break-inside`` property."""
|
||||
if keyword == 'avoid':
|
||||
raise InvalidValues('value not supported yet')
|
||||
return keyword ('auto',)
|
||||
return keyword in ('auto', 'avoid')
|
||||
|
||||
|
||||
@validator()
|
||||
|
@ -258,7 +258,7 @@ def block_level_height(document, box, max_position_y, skip_stack,
|
||||
if is_page_break:
|
||||
break
|
||||
else:
|
||||
if new_children and not page_is_empty:
|
||||
if new_children:
|
||||
# between siblings, but not before the first child
|
||||
# or after the last child.
|
||||
break_here, next_page = forced_page_break(
|
||||
@ -271,7 +271,8 @@ def block_level_height(document, box, max_position_y, skip_stack,
|
||||
(new_child, resume_at, next_page, next_adjoining_margins,
|
||||
collapsing_through) = block_level_layout(
|
||||
document, child, max_position_y, skip_stack,
|
||||
new_containing_block, device_size, page_is_empty,
|
||||
new_containing_block, device_size,
|
||||
page_is_empty and not new_children,
|
||||
adjoining_margins)
|
||||
skip_stack = None
|
||||
|
||||
@ -293,7 +294,8 @@ def block_level_height(document, box, max_position_y, skip_stack,
|
||||
new_position_y = (
|
||||
new_child.border_box_y() + new_child.border_height())
|
||||
|
||||
if (new_position_y > max_position_y and not page_is_empty
|
||||
if (new_position_y > max_position_y and (
|
||||
new_children or not page_is_empty)
|
||||
and not isinstance(child, boxes.BlockBox)):
|
||||
# The child overflows the page area, put it on the
|
||||
# next page. (But don’t delay whole blocks if eg.
|
||||
@ -314,7 +316,6 @@ def block_level_height(document, box, max_position_y, skip_stack,
|
||||
# Bottom borders may overflow here
|
||||
# TODO: back-track somehow when all lines fit but not borders
|
||||
new_children.append(new_child)
|
||||
page_is_empty = False
|
||||
if resume_at is not None:
|
||||
resume_at = (index, resume_at)
|
||||
break
|
||||
@ -322,6 +323,10 @@ def block_level_height(document, box, max_position_y, skip_stack,
|
||||
else:
|
||||
resume_at = None
|
||||
|
||||
if resume_at is not None and box.style.page_break_inside == 'avoid' \
|
||||
and not page_is_empty:
|
||||
return None, None, 'any', [], False
|
||||
|
||||
|
||||
if collapsing_with_children:
|
||||
if new_children and not isinstance(
|
||||
|
@ -641,16 +641,16 @@ def test_page_breaks():
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
def test_orphans_widows():
|
||||
def test_orphans_widows_avoid():
|
||||
"""Test orphans and widows control."""
|
||||
def line_distribution(orphans, widows):
|
||||
def line_distribution(css):
|
||||
pages = parse('''
|
||||
<style>
|
||||
@page { -weasy-size: 200px }
|
||||
h1 { height: 120px }
|
||||
p { line-height: 20px;
|
||||
width: 1px; /* line break at each word */
|
||||
orphans: %s; widows: %s }
|
||||
%s }
|
||||
</style>
|
||||
<h1>Tasty test</h1>
|
||||
<!-- There is room for 4 lines after h1 on the fist page -->
|
||||
@ -663,7 +663,7 @@ def test_orphans_widows():
|
||||
six
|
||||
seven
|
||||
</p>
|
||||
''' % (orphans, widows))
|
||||
''' % css)
|
||||
line_counts = []
|
||||
for i, page in enumerate(pages):
|
||||
html, = page.children
|
||||
@ -679,10 +679,13 @@ def test_orphans_widows():
|
||||
line_counts.append(0)
|
||||
return line_counts
|
||||
|
||||
assert line_distribution(orphans=2, widows=2) == [4, 3]
|
||||
assert line_distribution(orphans=5, widows=2) == [0, 7]
|
||||
assert line_distribution(orphans=2, widows=4) == [3, 4]
|
||||
assert line_distribution(orphans=4, widows=4) == [0, 7]
|
||||
assert line_distribution('orphans: 2; widows: 2') == [4, 3]
|
||||
assert line_distribution('orphans: 5; widows: 2') == [0, 7]
|
||||
assert line_distribution('orphans: 2; widows: 4') == [3, 4]
|
||||
assert line_distribution('orphans: 4; widows: 4') == [0, 7]
|
||||
|
||||
assert line_distribution(
|
||||
'orphans: 2; widows: 2; page-break-inside: avoid') == [0, 7]
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
|
Loading…
Reference in New Issue
Block a user