Permalink
Browse files

Fix corner cases about named pages

  • Loading branch information...
liZe committed Sep 11, 2017
1 parent 4990ad9 commit 1d1654c16c505851c1d579f5c495d558b416d6ca
Showing with 68 additions and 4 deletions.
  1. +9 −4 weasyprint/layout/blocks.py
  2. +59 −0 weasyprint/tests/test_layout.py
@@ -490,8 +490,9 @@ def block_container_layout(context, box, max_position_y, skip_stack,
if over_orphans < 0 and not page_is_empty:
# Reached the bottom of the page before we had
# enough lines for orphans, cancel the whole box.
page = child.page_values()[0]
return (
None, None, {'break': 'any', 'page': None}, [],
None, None, {'break': 'any', 'page': page}, [],
False)
# How many lines we need on the next page to satisfy widows
# -1 for the current line.
@@ -503,8 +504,9 @@ def block_container_layout(context, box, max_position_y, skip_stack,
break
if needed > over_orphans and not page_is_empty:
# Total number of lines < orphans + widows
page = child.page_values()[0]
return (
None, None, {'break': 'any', 'page': None}, [],
None, None, {'break': 'any', 'page': page}, [],
False)
if needed and needed <= over_orphans:
# Remove lines to keep them for the next page
@@ -548,6 +550,7 @@ def block_container_layout(context, box, max_position_y, skip_stack,
elif page_break not in ('left', 'right', 'recto', 'verso'):
assert page_name
page_break = 'any'
page_name = child.page_values()[0]
next_page = {'break': page_break, 'page': page_name}
resume_at = (index, None)
break
@@ -661,8 +664,9 @@ def block_container_layout(context, box, max_position_y, skip_stack,
# The page has content *before* this block:
# cancel the block and try to find a break
# in the parent.
page = child.page_values()[0]
return (
None, None, {'break': 'any', 'page': None}, [],
None, None, {'break': 'any', 'page': page}, [],
False)
# else:
# ignore this 'avoid' and break anyway.
@@ -673,8 +677,9 @@ def block_container_layout(context, box, max_position_y, skip_stack,
else:
# This was the first child of this box, cancel the box
# completly
page = child.page_values()[0]
return (
None, None, {'break': 'any', 'page': None}, [], False)
None, None, {'break': 'any', 'page': page}, [], False)
# Bottom borders may overflow here
# TODO: back-track somehow when all lines fit but not borders
@@ -1243,6 +1243,65 @@ def test_page_names():
assert p.element_tag == 'p'
assert section.element_tag == 'section'
pages = parse('''
<style>
@page small { size: 100px 100px }
section { page: small }
p { line-height: 80px }
</style>
<section>
<p>small</p>
<p>small</p>
</section>
''')
page1, page2 = pages
assert (page1.width, page1.height) == (100, 100)
html, = page1.children
body, = html.children
section, = body.children
p, = section.children
assert section.element_tag == 'section'
assert p.element_tag == 'p'
assert (page2.width, page2.height) == (100, 100)
html, = page2.children
body, = html.children
section, = body.children
p, = section.children
assert section.element_tag == 'section'
assert p.element_tag == 'p'
pages = parse('''
<style>
@page { size: 200px 200px }
@page small { size: 100px 100px }
section { break-after: page; page: small }
article { page: small }
</style>
<section>
<div>big</div>
<div>big</div>
</section>
<article>
<div>small</div>
<div>small</div>
</article>
''')
page1, page2, = pages
assert (page1.width, page1.height) == (100, 100)
html, = page1.children
body, = html.children
section, = body.children
assert section.element_tag == 'section'
assert (page2.width, page2.height) == (100, 100)
html, = page2.children
body, = html.children
article, = body.children
assert article.element_tag == 'article'
@assert_no_logs
def test_orphans_widows_avoid():

0 comments on commit 1d1654c

Please sign in to comment.