Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix computation for outer min content-width of a table cell #2085

Merged
merged 1 commit into from
Mar 4, 2024
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
28 changes: 28 additions & 0 deletions tests/layout/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -3009,6 +3009,34 @@ def test_min_width_with_overflow():
assert table1_td1.width == table2_td1.width


@assert_no_logs
def test_table_cell_max_width():
page, = render_pages('''
<style>
td {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
max-width: 45px;
}
</style>
<table>
<tr>
<td>abcde</td>
</tr>
</table>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
tbody, = table.children
tr, = tbody.children
td, = tr.children
assert td.max_width == 45
assert td.width == 45


black = (0, 0, 0, 1)
red = (1, 0, 0, 1)
green = (0, 1, 0, 1) # lime in CSS
Expand Down
16 changes: 8 additions & 8 deletions weasyprint/layout/preferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,17 @@ def column_group_content_width(context, box):
def table_cell_min_content_width(context, box, outer):
"""Return the min-content width for a ``TableCellBox``."""
# See https://www.w3.org/TR/css-tables-3/#outer-min-content
min_width = box.style['min_width']
if min_width == 'auto':
min_width = 0
else:
min_width = min_width.value
# The outer min-content width of a table-cell is
# max(min-width, min-content width) adjusted by
# the cell intrinsic offsets.
children_widths = [
max(min_width, min_content_width(context, child))
min_content_width(context, child)
for child in box.children
if not child.is_absolutely_positioned()]
children_min_width = margin_width(
box, max(children_widths) if children_widths else 0)
children_min_width = adjust(
box,
outer,
max(children_widths) if children_widths else 0)

width = box.style['width']
if width != 'auto' and width.unit == 'px':
Expand Down
Loading