Skip to content

Commit

Permalink
Don’t break pages when fixed-height elements don’t overflow page
Browse files Browse the repository at this point in the history
Fix #2026.

Bookmark tests have to be fixed because height set to all elements was also
set to html an body tags.
  • Loading branch information
liZe committed Dec 27, 2023
1 parent 05390c8 commit bc97131
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
24 changes: 24 additions & 0 deletions tests/draw/test_overflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,30 @@ def test_overflow_4(assert_pixels):
''')


@assert_no_logs
def test_overflow_5(assert_pixels):
# Regression test for https://github.com/Kozea/WeasyPrint/issues/2026
assert_pixels('''
BBBBBB__
BBBBBB__
BBBB____
BBBB____
BBBB____
________
________
________
''', '''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { size: 8px }
body { font-family: weasyprint; line-height: 1; font-size: 2px }
p { color: blue }
</style>
<p>abc</p>
<p style="height: 3px; overflow: hidden">ab<br>ab<br>ab<br>ab</p>
''')


@assert_no_logs
@pytest.mark.parametrize('number, css, pixels', (
(1, '5px, 5px, 9px, auto', '''
Expand Down
4 changes: 2 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def test_low_level_api(assert_pixels_equal):

@pytest.mark.parametrize('html, expected_by_page, expected_tree, round', (
('''
<style>* { height: 10px }</style>
<style>h1, h2, h3, h4 { height: 10px }</style>
<h1>a</h1>
<h4 style="page-break-after: always">b</h4>
<h3 style="position: relative; top: 2px; left: 3px">c</h3>
Expand All @@ -634,7 +634,7 @@ def test_low_level_api(assert_pixels_equal):
], False),
('''
<style>
* { height: 90px; margin: 0 0 10px 0 }
h1, h2, h3, span { height: 90px; margin: 0 0 10px 0 }
</style>
<h1>Title 1</h1>
<h1>Title 2</h1>
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_bookmarks_3():
def test_bookmarks_4():
pdf = FakeHTML(string='''
<style>
* { height: 90pt; margin: 0 0 10pt 0 }
h1, h2, h3, span { height: 90pt; margin: 0 0 10pt 0 }
</style>
<h1>1</h1>
<h1>2</h1>
Expand Down
5 changes: 5 additions & 0 deletions weasyprint/layout/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,11 @@ def block_container_layout(context, box, bottom_space, skip_stack,
None, None, {'break': 'any', 'page': page}, [], False,
max_lines)
elif stop:
if box.height != 'auto':
if position_y > box.position_y + box.height:
# Box heigh is fixed and it doesn’t overflow page, forget
# overflowing children.
resume_at = None
adjoining_margins = []
break

Expand Down

0 comments on commit bc97131

Please sign in to comment.