Permalink
Browse files

Add page-break-inside: avoid

  • Loading branch information...
1 parent 248e843 commit f814dc0243aa490ff93ca54cbf36e911a7d5f5d6 @SimonSapin SimonSapin committed Mar 16, 2012
Showing with 22 additions and 15 deletions.
  1. +1 −0 CHANGES
  2. +1 −3 weasyprint/css/validation.py
  3. +9 −4 weasyprint/layout/blocks.py
  4. +11 −8 weasyprint/tests/test_layout.py
View
@@ -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,14 +316,17 @@ 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
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 line_distribution(orphans, widows):
six
seven
</p>
- ''' % (orphans, widows))
+ ''' % css)
line_counts = []
for i, page in enumerate(pages):
html, = page.children
@@ -679,10 +679,13 @@ def line_distribution(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

0 comments on commit f814dc0

Please sign in to comment.