Skip to content

Commit

Permalink
Merge pull request #2085 from kygoh/fix-table-cell-text-overflow
Browse files Browse the repository at this point in the history
Fix computation for outer min content-width of a table cell
  • Loading branch information
liZe authored Mar 4, 2024
2 parents 6bcbd51 + ce41f4a commit 28be5bd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
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

0 comments on commit 28be5bd

Please sign in to comment.