Skip to content

Commit

Permalink
Merge branch '56.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Jul 13, 2022
2 parents 11bc920 + adec43a commit 0a21cf9
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 3 deletions.
207 changes: 207 additions & 0 deletions tests/draw/test_footnotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,210 @@ def test_footnote_with_absolute(assert_pixels):
}
</style>
<div>a<span><mark>d</mark></span></div>''')


@assert_no_logs
def test_footnote_max_height_1(assert_pixels):
assert_pixels('''
RRRRRRRR_
RRRRRRRR_
RRRR_____
RRRR_____
_BBBBBB__
_BBBBBB__
_________
_________
_________
_________
_BBBBBB__
_BBBBBB__
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 9px 6px;
@footnote {
margin-left: 1px;
max-height: 3px;
}
}
div {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
div.footnote {
float: footnote;
color: blue;
}
</style>
<div>ab<div class="footnote">c</div><div class="footnote">d</div></div>
<div>ef</div>''')


@assert_no_logs
def test_footnote_max_height_2(assert_pixels):
assert_pixels('''
RRRRRRRR_
RRRRRRRR_
_________
_________
_BBBBBB__
_BBBBBB__
_________
_________
_________
_________
_BBBBBB__
_BBBBBB__
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 9px 6px;
@footnote {
margin-left: 1px;
max-height: 3px;
}
}
div {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
div.footnote {
float: footnote;
color: blue;
}
</style>
<div>ab<div class="footnote">c</div><div class="footnote">d</div></div>''')


@assert_no_logs
def test_footnote_max_height_3(assert_pixels):
# This case is crazy and the rendering is not really defined, but this test
# is useful to check that there’s no endless loop.
assert_pixels('''
RRRRRRRR_
RRRRRRRR_
_________
_________
_________
_________
_________
_________
_________
_________
_________
_BBBBBB__
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 9px 6px;
@footnote {
margin-left: 1px;
max-height: 1px;
}
}
div {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
div.footnote {
float: footnote;
color: blue;
}
</style>
<div>ab<div class="footnote">c</div><div class="footnote">d</div></div>''')


@assert_no_logs
def test_footnote_max_height_4(assert_pixels):
assert_pixels('''
RRRRRRRR_
RRRRRRRR_
RRRR_____
RRRR_____
_BBBBBB__
_BBBBBB__
RRRR_____
RRRR_____
_________
_________
_BBBBBB__
_BBBBBB__
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 9px 6px;
@footnote {
margin-left: 1px;
max-height: 3px;
}
}
div {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
div.footnote {
float: footnote;
color: blue;
}
</style>
<div>ab<div class="footnote">c</div><div class="footnote">d</div></div>
<div>ef</div>
<div>gh</div>''')


@assert_no_logs
def test_footnote_max_height_5(assert_pixels):
assert_pixels('''
RRRRRRRR__RR
RRRRRRRR__RR
_BBBBBB_____
_BBBBBB_____
_BBBBBB_____
_BBBBBB_____
RRRR________
RRRR________
____________
____________
_BBBBBB_____
_BBBBBB_____
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 12px 6px;
@footnote {
margin-left: 1px;
max-height: 4px;
}
}
div {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
div.footnote {
float: footnote;
color: blue;
}
</style>
<div>ab<div class="footnote">c</div><div class="footnote">d</div>
<div class="footnote">e</div></div>
<div>fg</div>''')
2 changes: 1 addition & 1 deletion tests/draw/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def test_otb_font(assert_pixels):
color: red;
font-family: weasyprint-otb;
font-size: 4px;
line-height: 1;
line-height: 0.8;
}
</style>
AaA''')
58 changes: 58 additions & 0 deletions tests/layout/test_footnotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,61 @@ def test_footnote_repagination():
assert footnote_marker.children[0].text == '1.'
assert footnote_textbox.text == 'de'
assert footnote_area.position_y == 5


@assert_no_logs
def test_footnote_max_height():
page1, page2 = render_pages('''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 12px 6px;
@footnote {
margin-left: 1px;
max-height: 4px;
}
}
div {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
div.footnote {
float: footnote;
color: blue;
}
</style>
<div>ab<div class="footnote">c</div><div class="footnote">d</div>
<div class="footnote">e</div></div>
<div>fg</div>''')
html1, footnote_area1 = page1.children
body1, = html1.children
div, = body1.children
div_textbox, footnote_call1, footnote_call2, space, footnote_call3 = (
div.children[0].children)
assert div_textbox.text == 'ab'
assert footnote_call1.children[0].text == '1'
assert footnote_call2.children[0].text == '2'
assert space.text == ' '
assert footnote_call3.children[0].text == '3'
footnote1, footnote2 = footnote_area1.children
footnote_line1, = footnote1.children
footnote_marker1, footnote_content1 = footnote_line1.children
assert footnote_marker1.children[0].text == '1.'
assert footnote_content1.text == 'c'
footnote_line2, = footnote2.children
footnote_marker2, footnote_content2 = footnote_line2.children
assert footnote_marker2.children[0].text == '2.'
assert footnote_content2.text == 'd'

html2, footnote_area2 = page2.children
body2, = html2.children
div2, = body2.children
div_textbox2, = div2.children[0].children
assert div_textbox2.text == 'fg'
footnote_line3, = footnote_area2.children[0].children
footnote_marker3, footnote_content3 = footnote_line3.children
assert footnote_marker3.children[0].text == '3.'
assert footnote_content3.text == 'e'
8 changes: 7 additions & 1 deletion weasyprint/layout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def layout_footnote(self, footnote):
"""Add a footnote to the layout for this page."""
self.footnotes.remove(footnote)
self.current_page_footnotes.append(footnote)
self._update_footnote_area()
return self._update_footnote_area()

def unlayout_footnote(self, footnote):
"""Remove a footnote from the layout and return it to the waitlist."""
Expand Down Expand Up @@ -361,5 +361,11 @@ def _update_footnote_area(self):
self.current_footnote_area.page)[0]
self.current_footnote_area.height = footnote_area.height
self.page_bottom -= footnote_area.margin_height()
last_child = footnote_area.children[-1]
overflow = (
last_child.position_y + last_child.margin_height() >
footnote_area.position_y + footnote_area.margin_height())
return overflow
else:
self.current_footnote_area.height = 0
return False
3 changes: 2 additions & 1 deletion weasyprint/layout/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,10 @@ def _linebox_layout(context, box, index, child, new_children, page_is_empty,
descendant.footnote for descendant in line.descendants()
if descendant.footnote in context.footnotes)
for footnote in footnotes:
context.layout_footnote(footnote)
overflow = context.layout_footnote(footnote)
new_footnotes.append(footnote)
overflow = (
overflow or
context.reported_footnotes or
context.overflows_page(
bottom_space, new_position_y + offset_y))
Expand Down

0 comments on commit 0a21cf9

Please sign in to comment.