From ce41f4acb53b9995ecdd24a2cf7ef0fe7ed74b5f Mon Sep 17 00:00:00 2001 From: kygoh Date: Mon, 4 Mar 2024 12:11:41 +0000 Subject: [PATCH] fix computation for outer min content-width of a table cell --- tests/layout/test_table.py | 28 ++++++++++++++++++++++++++++ weasyprint/layout/preferred.py | 16 ++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/tests/layout/test_table.py b/tests/layout/test_table.py index 00fbaac19..bfd097dae 100644 --- a/tests/layout/test_table.py +++ b/tests/layout/test_table.py @@ -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(''' + + + + + +
abcde
+ ''') + 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 diff --git a/weasyprint/layout/preferred.py b/weasyprint/layout/preferred.py index bd783b292..8c965fe7f 100644 --- a/weasyprint/layout/preferred.py +++ b/weasyprint/layout/preferred.py @@ -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':