Copy columns when copying tables

Backgrounds set on a column are applied to the column cells, and these cells
depend on the page we’re on. If we use the same column object for all pages,
the corresponding cells are only the ones of the last page.

Fix #2296.
This commit is contained in:
Guillaume Ayoub
2025-01-05 19:27:51 +01:00
parent 2884798331
commit 8a777cb2ab
2 changed files with 35 additions and 0 deletions
+33
View File
@@ -1620,3 +1620,36 @@ def test_tables_split_row(assert_pixels):
<td>a<br>a</td>
</tr>
</table>''')
@assert_no_logs
def test_tables_column_background(assert_pixels):
# Regression test: https://github.com/Kozea/WeasyPrint/issues/2296
assert_pixels('''
KKKKKKKK
KRRBBRRK
KRRBBRRK
KKKKKKKK
KKKKKKKK
KRRBBRRK
KRRBBRRK
KKKKKKKK
''', '''
<style>
@page { margin: 0; size: 8px 4px }
col { background: blue }
td { border: 1px solid black; color: red; vertical-align: top;
font-family: weasyprint; font-size: 2px; line-height: 1 }
</style>
<table>
<colgroup>
<col>
</colgroup>
<tr>
<td>a a</td>
</tr>
<tr>
<td>a a</td>
</tr>
</table>''')
+2
View File
@@ -566,6 +566,8 @@ def table_layout(context, table, bottom_space, skip_stack, containing_block,
([header] if header is not None else []) +
new_table_children +
([footer] if footer is not None else []))
table.column_groups = tuple(
column_group.deepcopy() for column_group in table.column_groups)
remove_end_decoration = resume_at is not None and not has_footer
table.remove_decoration(remove_start_decoration, remove_end_decoration)
if collapse: