Skip to content

Layout: four table defects that lose or duplicate content #480

Closed

Description

@Tim81

Four defects in TableRenderer and TableGridResolver that lose or duplicate content. Filed
together because they meet in the same two methods and the plan's own analysis found that fixing
them separately reintroduces one another. Each section below was measured on 4788c4b; none was
taken on trust from the audit that first listed them.

Related and separately filed: #468 auto-width columns never capped, #477 explicit widths applied
literally, #473 a cell wider than its column drawn off the page, #476 a list indent that discards
the item text.

1. The column count comes from the first row, so later rows lose their extra cells

TableGridResolver.Resolve sets ColCount from table.Rows.FirstOrDefault(), so a row with more
cells than the first row has nowhere to put them. Measured: a 400x300pt page, first row a0 a1,
second row b0 b1 b2. Text drawn: a0, a1, b0, b1. b2 is absent.

The fix is the column count as the maximum over all rows, which is also what makes the short
explicit-widths array in #477 fixable: both need the count and the widths array reconciled.

2. A data row before the last header row is never drawn

Draw computes dataStartRow = Math.Max(_startRow, headerRowIndices[^1] + 1), and
FindHeaderRowIndices collects every header row wherever it sits, not the leading contiguous run.
So with a header at index 2, dataStartRow is 3, and any non-header row before it is drawn by
neither the header loop nor the data loop.

Measured on one page, so this needs no page break to reproduce: rows H0 header, D1 data, H2
header, D3 data. Text drawn: H0, H2, D3. D1 is absent.

The fix is to restrict the repeatable header to the leading contiguous run of header rows, so no row
can fall between the two loops.

3. The table's own margins are applied twice, and past a threshold the table draws nothing

Layout deflates by _table.Margins and stores the result in _occupied; Draw then deflates
_occupied again by the left, top and right margins. So the horizontal offset is the document
margin plus twice the table margin, and the vertical space is taken twice out of a box only as tall
as the rows that fit.

Measured, a 400x300pt page at a 10pt document margin, one row, reading the first cell's re:

Table margin Cell x Expected if deflated once
0 10 10
5 20 15
9 28 19
10 30 20
15 40 25
19 48 29

The vertical half is worse than an offset. Once the table margin reaches the row's own height, the
whole table draws nothing at all: no rectangle, no text, no exception, an empty content stream. The
threshold follows the row height, which is what identifies the double deflate as the cause rather
than a coincidence:

Font size Row height Draws Vanishes
10 20 at margin 19 at margin 20
20 32 at margin 20 by margin 39
30 44 at margin 40 by margin 59

So a caller who sets a 24pt margin on a 10pt table gets an empty page and no diagnostic.

The plan's analysis of this is worth carrying over: the draw loop stops on a geometric test rather
than on an explicit end-row recorded during layout, which is why half a point of drift can delete a
row. Adding that field, as the list and paragraph renderers already have, is what turns the double
deflate from an offset into a correctness fix.

4. A cell with RowSpan has its text drawn twice

The origin row draws a spanning cell across its full combined height, and a second draw fires when
the span map runs down. Measured: a two-row table whose first cell has RowSpan = 2. Text drawn:
SPAN, x0, SPAN, x1. SPAN appears twice.

Untagged this is duplicate operators. Tagged it is a second structure element for one cell, attached
to the wrong row. The fix is to delete the redundant draw and keep only the slot cleanup, and then
to check the conformance suite, because a duplicated grid is the shape a table rule inspects.

The existing rowspan test asserts only that the text is present, so it passes with one copy or two.
It needs an occurrence count.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions