Skip to content

Commit

Permalink
Don’t append useless tracks when grid elements are positioned
Browse files Browse the repository at this point in the history
Fix #2187.
  • Loading branch information
liZe committed Jun 21, 2024
1 parent fb9d1f8 commit 39208b0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
32 changes: 32 additions & 0 deletions tests/layout/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,3 +988,35 @@ def test_grid_template_areas_extra_span_column_dense():
assert div_e.height == 4
assert article.height == 4
assert article.width == 12


@assert_no_logs
def test_grid_gap_explicit_grid_column():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/2187
page, = render_pages('''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
article {
display: grid;
font-family: weasyprint;
font-size: 2px;
gap: 2px;
grid-template-columns: 1fr;
line-height: 1;
width: 12px;
}
</style>
<article>
<div>a</div>
<div style="grid-column: 1">b</div>
</article>
''')
html, = page.children
body, = html.children
article, = body.children
div_a, div_b = article.children
assert div_a.position_x == div_b.position_x == 0
assert div_a.position_y == 0
assert div_b.position_y == 4
assert article.height == 6
assert article.width == 12
10 changes: 2 additions & 8 deletions weasyprint/layout/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,7 @@ def grid_layout(context, box, bottom_space, skip_stack, containing_block,
break
first_diff = first_i + first_size - implicit_first_2
if first_diff > 0:
for _ in range(first_diff):
first_tracks.append(next(auto_tracks))
first_tracks.append([])
implicit_first_2 = first_i + first_size
implicit_first_2 += first_diff
# 3. Set the item’s row-start line.
if first_flow == 'row':
x, y = second_i, first_i
Expand Down Expand Up @@ -912,10 +909,7 @@ def grid_layout(context, box, bottom_space, skip_stack, containing_block,
break
first_diff = first_i + first_size - implicit_first_2
if first_diff > 0:
for _ in range(first_diff):
first_tracks.append(next(auto_tracks))
first_tracks.append([])
implicit_first_2 = y + height
implicit_first_2 += first_diff
# 3. Set the item’s row-start line.
children_positions[child] = (x, y, width, height)
else:
Expand Down

0 comments on commit 39208b0

Please sign in to comment.