Skip to content

Commit

Permalink
Merge pull request #2087 from kygoh/css-tables-3-width
Browse files Browse the repository at this point in the history
Use CSS Table Module Level 3 to compute widths
  • Loading branch information
liZe authored Mar 6, 2024
2 parents 2c09a86 + 7930746 commit 3eaadd0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
6 changes: 3 additions & 3 deletions tests/layout/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def test_layout_table_auto_8():
@assert_no_logs
def test_layout_table_auto_9():
page, = render_pages('''
<table style="border-spacing: 10px; width: 110px; margin: 5px">
<table style="border-spacing: 10px; width: 120px; margin: 5px">
<tr>
<td style="width: 60px"></td>
<td></td>
Expand Down Expand Up @@ -1113,8 +1113,8 @@ def test_layout_table_auto_31():
def test_layout_table_auto_32():
# Table with a cell larger than the table's width
page, = render_pages('''
<table style="width: 300px; margin: 100px">
<td style="width: 400px"></td>
<table style="width: 400px; margin: 100px">
<td style="width: 500px"></td>
</table>
''')
html, = page.children
Expand Down
8 changes: 1 addition & 7 deletions weasyprint/layout/preferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,7 @@ def table_cell_min_content_width(context, box, outer):
outer,
max(children_widths) if children_widths else 0)

width = box.style['width']
if width != 'auto' and width.unit == 'px':
cell_min_width = adjust(box, outer, width.value)
else:
cell_min_width = 0

return max(children_min_width, cell_min_width)
return children_min_width


def table_cell_max_content_width(context, box, outer):
Expand Down
5 changes: 4 additions & 1 deletion weasyprint/layout/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ def auto_table_layout(context, box, containing_block):
guesses = (
min_content_guess, min_content_percentage_guess,
min_content_specified_guess, max_content_guess)
# https://www.w3.org/TR/css-tables-3/#width-distribution-algorithm
for i in range(len(grid)):
if column_intrinsic_percentages[i]:
min_content_percentage_guess[i] = max(
Expand All @@ -761,7 +762,9 @@ def auto_table_layout(context, box, containing_block):
min_content_specified_guess[i] = min_content_percentage_guess[i]
max_content_guess[i] = min_content_percentage_guess[i]
elif constrainedness[i]:
min_content_specified_guess[i] = column_min_content_widths[i]
# any other column that is constrained is assigned
# its max-content width
min_content_specified_guess[i] = column_max_content_widths[i]

if assignable_width <= sum(max_content_guess):
# Default values shouldn't be used, but we never know.
Expand Down

0 comments on commit 3eaadd0

Please sign in to comment.