Skip to content

Commit

Permalink
Make items overflowing grid wrap to the next row/column
Browse files Browse the repository at this point in the history
Fix #2184.
  • Loading branch information
liZe committed Jun 17, 2024
1 parent e7c44e5 commit 76fca69
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
34 changes: 34 additions & 0 deletions tests/layout/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,40 @@ def test_grid_template_areas_overlap():
assert article.width == 10


@assert_no_logs
def test_grid_template_areas_span_overflow():
page, = render_pages('''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
article {
display: grid;
font-family: weasyprint;
font-size: 2px;
grid-template-columns: 50% 50%;
line-height: 1;
width: 10px;
}
</style>
<article>
<div style="">a</div>
<div style="grid-column: span 2">a</div>
<div style="">a</div>
</article>
''')
html, = page.children
body, = html.children
article, = body.children
div_a1, div_a2, div_a3 = article.children
assert div_a1.position_x == div_a2.position_x == div_a3.position_x == 0
assert div_a1.position_y == 0
assert div_a2.position_y == 2
assert div_a3.position_y == 4
assert div_a1.width == div_a3.width == 5
assert div_a2.width == 10
assert div_a1.height == div_a2.height == div_a3.height == 2
assert article.width == 10


@assert_no_logs
def test_grid_template_areas_extra_span():
page, = render_pages('''
Expand Down
10 changes: 6 additions & 4 deletions weasyprint/layout/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,9 @@ def grid_layout(context, box, bottom_space, skip_stack, containing_block,
width, height = first_size, second_size
intersect = _intersect_with_children(
x, y, width, height, children_positions.values())
if intersect:
# Child intersects with a positioned child.
overflow = second_i + second_size > implicit_second_2
if intersect or overflow:
# Child intersects with a positioned child or overflows.
continue
else:
# Free place found.
Expand Down Expand Up @@ -947,8 +948,9 @@ def grid_layout(context, box, bottom_space, skip_stack, containing_block,
width, height = first_size, second_size
intersect = _intersect_with_children(
x, y, width, height, children_positions.values())
if intersect:
# Child intersects with a positioned child.
overflow = second_i + second_size > implicit_second_2
if intersect or overflow:
# Child intersects with a positioned child or overflows.
continue
else:
# Free place found.
Expand Down

0 comments on commit 76fca69

Please sign in to comment.