Skip to content

Commit

Permalink
Fix vertical alignment of out-of-flow elements in tables
Browse files Browse the repository at this point in the history
Fix #2216.
  • Loading branch information
liZe committed Aug 10, 2024
1 parent 50456df commit 9213f62
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
32 changes: 32 additions & 0 deletions tests/layout/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,38 @@ def test_table_vertical_align(assert_pixels):
''')


@assert_no_logs
def test_table_vertical_align_float():
# Test regression: https://github.com/Kozea/WeasyPrint/issues/2216
page, = render_pages('''
<style>
@page { size: 100px }
td { width: 50px; height: 100px }
div { width: 25px; height: 20px }
</style>
<table>
<tr>
<td style="vertical-align: middle"><div style="float: left"></div></td>
<td style="vertical-align: bottom"><div style="float: right"></div></td>
</tr>
</table>
''')
html, = page.children
body, = html.children
wrapper, = body.children
table, = wrapper.children
table, = wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
div, = td_1.children
assert div.position_x == 0
assert div.position_y == 40 # (100 - 20) / 2
div, = td_2.children
assert div.position_x == 75
assert div.position_y == 80 # 100 - 20


@assert_no_logs
def test_table_wrapper():
page, = render_pages('''
Expand Down
5 changes: 4 additions & 1 deletion weasyprint/layout/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ def group_layout(group, position_y, bottom_space, page_is_empty, skip_stack):
cell.computed_height - cell.content_height)
if vertical_align_shift > 0:
for child in cell.children:
child.translate(dy=vertical_align_shift)
child_shift = child.margin_height()
if cell.vertical_align == 'middle':
child_shift /= 2
child.translate(dy=vertical_align_shift - child_shift)

next_position_y = row.position_y + row.height
if resume_at is None:
Expand Down

0 comments on commit 9213f62

Please sign in to comment.