Skip to content

fix: insert rowspan placeholders in column order - #1949

Open
swimmingbrain wants to merge 2 commits into
py-pdf:masterfrom
swimmingbrain:fix/rowspan-placeholder-order
Open

swimmingbrain wants to merge 2 commits into
py-pdf:masterfrom
swimmingbrain:fix/rowspan-placeholder-order

Conversation

@swimmingbrain

Copy link
Copy Markdown

convert_spans walks active_rowspans in dict order and calls cells.insert(k, None) for each one. The keys arrive in the order the rowspans started, which is not the column order, and every insert shifts whatever sits to its right. Insert a placeholder for a later column first and the next insert pushes it one column further, so the row ends up with a cell under the wrong heading. Sorting the keys keeps every insert to the right of the ones already placed.

Smallest table I could get it out of, three rows and four columns:

with pdf.table(first_row_as_headings=False) as table:
    row = table.row()
    row.cell("A1"); row.cell("B1"); row.cell("C1", rowspan=3); row.cell("D1")
    row = table.row()
    row.cell("A2", rowspan=2); row.cell("B2"); row.cell("D2")
    row = table.row()
    row.cell("B3"); row.cell("D3")

The last row comes out as . | B3 | D3 | ., so D3 is drawn in the third column, under C1, and the fourth is left empty. With the sort it is . | B3 | . | D3.

The new test asserts that row's cells and compares the rendered page. It fails on master with [None, 'B3', 'D3', None]. Every other table test is untouched, so nothing that renders correctly today changes: 86 pass here, and the only failures in test/table are the tabula ones, which want a Java runtime I do not have.

Closes #1948

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

problem with table spans

1 participant