Skip to content

Commit

Permalink
Don’t respect fr units for overconstrained sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed May 28, 2024
1 parent d335034 commit f29ff1c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
31 changes: 31 additions & 0 deletions tests/layout/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,37 @@ def test_grid_shorthand_auto_flow_rows_fr_size():
assert article.width == 10


@assert_no_logs
def test_grid_template_fr_too_large():
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: 1fr 1fr;
line-height: 1;
width: 10px;
}
</style>
<article>
<div>a</div><div>bbb</div>
</article>
''')
html, = page.children
body, = html.children
article, = body.children
div_a, div_b = article.children
assert div_a.position_x == 0
assert div_b.position_x == 4
assert div_a.position_y == div_b.position_y == 0
assert div_a.height == div_b.height == 2
assert div_a.width == 4
assert div_b.width == 6
assert article.width == 10


def test_grid_shorthand_auto_flow_columns_none_dense():
page, = render_pages('''
<style>
Expand Down
7 changes: 4 additions & 3 deletions weasyprint/layout/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,12 @@ def _resolve_tracks_sizes(sizing_functions, box_size, children_positions,
free_space -= distributed_free_space
# TODO: Respect max-width/-height.
# 1.4 Expand flexible tracks.
inflexible_tracks = set()
if free_space is not None and free_space <= 0:
# TODO: Respect min-content constraint.
flex_fraction = 0
elif free_space is not None:
stop = False
inflexible_tracks = set()
while not stop:
leftover_space = free_space
flex_factor_sum = 0
Expand All @@ -533,7 +533,8 @@ def _resolve_tracks_sizes(sizing_functions, box_size, children_positions,
if i not in inflexible_tracks and _is_fr(max_function):
if hypothetical_fr_size * max_function.value < sizes[0]:
inflexible_tracks.add(i)
stop = False
free_space -= sizes[0]
stop = free_space > 0
flex_fraction = hypothetical_fr_size
else:
flex_fraction = 0
Expand All @@ -549,7 +550,7 @@ def _resolve_tracks_sizes(sizing_functions, box_size, children_positions,
# TODO: Respect min-* constraint.
iterable = enumerate(zip(tracks_sizes, sizing_functions))
for i, (sizes, (_, max_function)) in iterable:
if _is_fr(max_function):
if _is_fr(max_function) and i not in inflexible_tracks:
if flex_fraction * max_function.value > sizes[0]:
if free_space is not None:
free_space -= flex_fraction * max_function.value
Expand Down

0 comments on commit f29ff1c

Please sign in to comment.