Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions tests/layout/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from math import isclose

import pytest

from ..testing_utils import assert_no_logs, render_pages


Expand Down Expand Up @@ -1863,3 +1865,77 @@ def test_grid_in_flex_after_full_height():
grid, = flex.children
grid_item, = grid.children
assert not grid_item.children


@assert_no_logs
def test_grid_in_columns():
# Regression test for #2691.
page1, page2, = render_pages('''
<style>
@page { size: 12cm }
section { height: 10cm }
</style>
<div style="columns: 2">
<div style="display: grid">
<div>
<section></section>
<section></section>
<section></section>
</div>
</div>
</div>
''')
html, = page1.children
body, = html.children
div, = body.children
column1, column2 = div.children
grid, = column1.children
assert len(grid.children) == 1
grid, = column2.children
assert len(grid.children) == 1

html, = page2.children
body, = html.children
div, = body.children
column1, column2 = div.children
grid, = column1.children
assert len(grid.children) == 1
grid, = column2.children
assert len(grid.children) == 0


@pytest.mark.xfail
@assert_no_logs
def test_grid_in_columns_with_break():
# Regression test for #2695.
page1, page2, = render_pages('''
<style>
@page { size: 12px }
section { height: 4px }
</style>
<div style="columns: 1">
<div style="display: grid; margin-top: 6px">
<div>
<section></section>
<section></section>
<section></section>
</div>
</div>
</div>
''')
html, = page1.children
body, = html.children
div, = body.children
column1, = div.children
grid, = column1.children
section1, = grid.children
assert section1.position_y == 6

html, = page2.children
body, = html.children
div, = body.children
column1, = div.children
grid, = column1.children
section2, section3 = grid.children
assert section2.position_y == 0
assert section3.position_y == 4
10 changes: 6 additions & 4 deletions weasyprint/layout/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,6 @@ def _add_page_children(max_row=inf):
context, child, bottom_space, child_skip_stack, parent,
page_is_empty, absolute_boxes, fixed_boxes)[:3]
if new_child:
page_is_empty = False
broken_child = False
span = _get_span(child.style['grid_row_start'])
if child_resume_at:
Expand All @@ -1337,7 +1336,10 @@ def _add_page_children(max_row=inf):
# last child.
assert isinstance(new_child, boxes.ParentBox)
previous_skip_child = max(child_skip_stack) if child_skip_stack else 0
resume_at[y][i] = {previous_skip_child + len(new_child.children): None}
if not page_is_empty:
resume_at[y][i] = {
previous_skip_child + len(new_child.children): None}
page_is_empty = False
else:
if resume_at is None:
resume_at = {}
Expand Down Expand Up @@ -1418,10 +1420,10 @@ def _add_page_children(max_row=inf):
broken_child = y + span >= next_page_last_row + 1
if broken_child and child.style['box_decoration_break'] != 'clone':
child.remove_decoration(start=False, end=True)
child.height = (
child.height = max(0, (
context.page_bottom - bottom_space - child.position_y -
child.margin_top - child.border_top_width - child.padding_top -
child.margin_bottom - child.border_bottom_width - child.padding_bottom)
child.margin_bottom - child.border_bottom_width - child.padding_bottom))
if broken_child:
# Child not fully drawn, keep advancement.
advancements[x, y] = child.margin_height()
Expand Down
Loading