Skip to content

Commit

Permalink
Merge pull request #1899 from MWedl/1897-named-pages-inheritance
Browse files Browse the repository at this point in the history
Fix named pages inheritence
  • Loading branch information
liZe authored Aug 19, 2023
2 parents a9e08bb + e530a5e commit 1ffe534
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
36 changes: 36 additions & 0 deletions tests/layout/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,42 @@ def test_page_names_9():
assert article.element_tag == 'article'


@assert_no_logs
def test_page_names_10():
pages = render_pages('''
<style>
#running { position: running(running); }
#fixed { position: fixed; }
@page { size: 200px 200px; @top-center { content: element(header); }}
section { page: small; }
@page small { size: 100px 100px; }
.pagebreak { break-after: page; }
</style>
<div id="running">running</div>
<div id="fixed">fixed</div>
<section>
<h1>text</h1>
<div class="pagebreak"></div>
<article>text</article>
</section>
''')
page1, page2 = pages

assert (page1.width, page1.height) == (100, 100)
html, runing = page1.children
body, = html.children
fixed, section, = body.children
h1, pagebreak = section.children
assert h1.element_tag == 'h1'

assert (page2.width, page2.height) == (100, 100)
html, running = page2.children
fixed, body = html.children
section, = body.children
article, = section.children
assert article.element_tag == 'article'


@assert_no_logs
@pytest.mark.parametrize('style, line_counts', (
('orphans: 2; widows: 2', [4, 3]),
Expand Down
12 changes: 8 additions & 4 deletions weasyprint/formatting_structure/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,17 @@ def get_wrapped_table(self):

def page_values(self):
start_value, end_value = super().page_values()
if self.children:
if len(self.children) == 1:
page_values = self.children[0].page_values()
children = [
c for c in self.children
if not (c.is_absolutely_positioned() or c.is_running())
]
if children:
if len(children) == 1:
page_values = children[0].page_values()
start_value = page_values[0] or start_value
end_value = page_values[1] or end_value
else:
start_box, end_box = self.children[0], self.children[-1]
start_box, end_box = children[0], children[-1]
start_value = start_box.page_values()[0] or start_value
end_value = end_box.page_values()[1] or end_value
return start_value, end_value
Expand Down

0 comments on commit 1ffe534

Please sign in to comment.