Skip to content

fix(layout): stop losing a table row and doubling its margins - #486

Merged
Tim81 merged 4 commits into
mainfrom
fix/table-row-axis
Sep 12, 2026
Merged

Tim81 merged 4 commits into
mainfrom
fix/table-row-axis

Conversation

@Tim81

@Tim81 Tim81 commented Sep 11, 2026 •

Copy link
Copy Markdown
Owner

Two defects from #480 on the table's row axis. Both measured on adf6acf and on this branch.

Fix Before After
The header window a data row before a later header row was drawn by neither loop: H0, D1, H2, D3 drew three of four and lost D1 all four
The table's own margins applied twice, so the table shifted by the margin again and drew nothing at all once that margin reached the row's height applied once

The rowspan work came out of this pull request

This branch previously also deleted the duplicated rowspan draw, emitted /RowSpan and /ColSpan,
and stopped tagging a row that draws no cell of its own. Those three commits are preserved on
wip/table-span-attrs and come back as their own pull request. Three reviews plus my own
reproduction found three problems that a further fix round inside this pull request would not have
settled. Every figure below is my own measurement, with veraPDF 1.30.2 -f ua1 and the artifact
under test expanded by qpdf --qdf --object-streams=disable to confirm the change is actually in it.

The attributes break PDF/UA-1 on a paginating table with a header span. A 300x170pt page at 20pt
margins, PdfUA1 and Tagged, an embedded Arial, a header row whose first cell carries
RowSpan = 2, and twelve two-cell data rows:

adf6acf   PASS   no /RowSpan emitted anywhere
head      FAIL   failedChecks="2"
                 "Table rows shall have the same number of columns (taking into account column spans)"

Draw repeats the header run on every continuation page, and the header cell registers its span
slot at (1, col) while dataStartRow on a continuation page is the split row, so the slot is never
consumed. The expanded structure tree shows it directly. On page 1 the header declares two columns
and the row below draws one cell, which is consistent. On pages 2 and 3 the header still declares two
columns with a RowSpan of 2 while the row below draws both of its own cells, so that row spans
three and its header spans two.

The emitted span is the declared span, not the span the renderer applied. The renderer already
clamps the height it paints to the rows that exist; the attribute is written from cell.RowSpan
unclamped. A two-row table whose header cell declares more rows than the table has:

Declared RowSpan Emitted attribute veraPDF
2 /RowSpan 2 PASS
5 /RowSpan 5 FAIL
50 /RowSpan 50 FAIL
int.MaxValue /RowSpan 2147483647 no verdict at all

At int.MaxValue veraPDF does not report a failure. It tries to allocate a row array of that size
and aborts the job: "OutOfMemory caught when validating item caused by exception: Requested array
size exceeds VM limit", which arrives as a task exception with outOfMemory="1" in the batch
summary. The oracle test helper has no case for that shape, so it would not read as a failure either.

The test for the structure-hygiene fix does not discriminate it, because its fixture's covered
row has no cell of its own, so the loop never reaches the path the fix changed.

Clamping the emitted value to the rows the renderer actually covered on that page is the obvious fix
for the first two, but a repeated header cell is still painted two row heights tall on a
continuation page, so clamping the attribute alone makes the tag and the paint disagree in a way no
validator can see. Correcting that means changing the draw geometry for repeated headers, which moves
bytes for documents that render correctly today. That is a decision rather than a fix round, and this
repository has a standing note about pressing a fourth round into a pull request instead of splitting
it.

One note for whoever writes that pull request: the clause="7.2" veraPDF prints on this rule is
veraPDF's own rule identifier, not an ISO clause. In ISO 14289-1:2014 clause 7.2 is Text; tables are
clause 7.5, which requires table headers to be tagged according to ISO 32000-1:2008 Table 337 and
Table 349, and Table 349 is where /RowSpan and /ColSpan are defined.

What this moves for a document that renders today

Every table with a non-zero left or top margin shifts by exactly that margin, because Draw now
reads _occupied directly. A right or bottom margin moves nothing, since neither took part in
positioning. A caller who compensated for the doubling by halving their own table margin will see
their table move.

Below the row's height the doubled margin shifted the table down as its horizontal half shifted it
right. At or above the row's height the row was lost. The threshold is exact rather than
approximate: sweeping integer table margins from 0 to 60, the first that draws no text is 20, 32 and
44 at font sizes 10, 20 and 30, which is the emitted row height in each case. After the fix every
margin in that sweep draws its row.

Evidence

  • Byte identity. 237 documents rendered on both sides and hashed over their decompressed content
    streams, each row also carrying a text-run count so a hash difference says whether text moved or
    was lost. Exactly four rows moved, each attributable:

    Fixture Runs before Runs after Reading
    table header at index 2 3 4 the lost data row now draws
    table margin 20 at row height 0 1 the row that drew nothing now draws
    table margin 5 under row height 1 1 offset only
    table margin 6 paginating 20 20 offset only

    The two rowspan fixtures are byte-identical to adf6acf again now that the span commits are gone,
    which is the check that the split is clean rather than merely smaller.

  • The geometric stop test drops no row. The plan paired the double deflate with replacing
    Layout's geometric stop test with an explicit end-row field, on the grounds that the test loses a
    row once the geometry drifts. Sweeping page heights from 60 to 400 in quarter-point steps against
    table margins 0 to 19.75 in the same steps, 108,880 documents holding a twelve-row table: 107,320
    rendered and drew all twelve rows, 1,560 raised the too-tall exception because a 20pt row does not
    fit what a large table margin leaves of a short page, and none drew a wrong number of rows. So the
    refactor has no measured defect behind it, and a refactor does not belong in a patch. A reviewer
    who finds a losing input reverses that, and the input becomes its test.

  • Gates. 6937 tests, no failures, in Debug and in Release. With the oracle gates required rather
    than skipped, the Layout project is 347 with none skipped and the Conformance project 1300 with
    none skipped, so the veraPDF and poppler verdicts in them are part of the suite rather than a
    local run. Build, format, clean-room and the three AOT smoke jobs are green on CI.

  • Discrimination, measured by mutation in a detached worktree. Reverting
    FindHeaderRowIndices to collecting every IsHeader row fails three tests: its own named case
    and both property sweeps. Restoring the second deflate fails six: all five cases of the
    origin theory and the row-height boundary case. Nothing else fails in either run.

  • The property sweep reaches these inputs now, and catches one of them. LayoutGen never set a
    table margin and never varied the header flag, so neither defect was reachable by it at all. It
    now generates both, within the range that renders: the margin is bounded at 5pt, measured against
    the generator's most adverse corner, where the cell word draws whole through 7.5pt and hard-breaks
    from 8pt. The header mutation above is what that buys. The margin mutation is not caught by the
    sweep, and should not be claimed as such: at a margin this small the doubling is a pure offset that
    keeps the table inside the page and keeps every placement count, so neither invariant sees it. Its
    own theory is what covers it.

Two pre-existing defects found on the way, filed rather than fixed

Both checked against the base so they are not attributed to this branch.

#487. A covered row's own declared cell is never drawn, because the draw loop advances its column
past a span-occupied column without advancing its cell index. On the fixture, two rows each declare
two cells and draw only the first. The fix is a contract decision rather than a patch.

#488. A table whose every row is a header refuses to render on a 600pt page with room to spare,
while a mixed table renders. The message blames the page size, which is the one thing that is not
wrong, so it also belongs to #481's family.

Refs #365, #480

FindHeaderRowIndices collected every IsHeader row wherever it sat, so
dataStartRow (headerRowIndices[^1] + 1) always started past the last
header while the header loop only drew the rows that list held. A
header after a data row left the data row between them reached by
neither loop. Restrict the repeatable header to the leading contiguous
run so a later header draws as an ordinary row instead.
Layout deflated context.Area by _table.Margins and stored the result
in _occupied; Draw deflated _occupied by the left, top and right
margins again, so a table with a non-zero margin drew twice as far in
from the document margin. The vertical half of the double deflate was
outright loss rather than an offset: _occupied's height already holds
exactly the rows that fit with no margin allowance in it, so a second
top deflate ate into that height directly, and once a table margin
reached its single row's own height the table drew nothing at all.
Draw now uses _occupied as its area, matching the deflate Layout
already applied.
LayoutGen never set TableElement.Margins and never varied IsHeader, so
the sweep in PropertyTests could not reach either defect #480 fixes:
every sample had one row, never a header, and nothing to double a table
margin against. It now generates two rows with an independent header
shape and a bounded table margin.

The header shape excludes both-rows-header. A table with no data rows
reports LayoutResult.Nothing unconditionally from TableRenderer.Layout
regardless of how much page is free, and DocumentRenderer reads that as
ElementTooTall; widening the generator to include that shape broke both
properties on documents with hundreds of points to spare. That is a real
defect, filed as #488, and outside this pull request.

The margin is bounded to 5pt rather than to the row height, because the
binding constraint is column width: the cell word hard-breaks once its
column shrinks enough, which would fail this file's own placement-count
invariant for an unrelated reason. Measured at the generator's most
adverse corner, page width 400, page margin 60, font size 24, in 0.5pt
steps: "Wgggg" draws whole through a table margin of 7.5pt and
hard-breaks from 8pt.
Two entries. A new one for the header window and the doubly applied
table margin, and a correction to the merged column-axis entry, which
called the too-tall fixture's explicit 10pt "the default"; TextStyle
FontSize defaults to 12, and at 12 that row is 22.4pt rather than 20pt,
so the arithmetic the sentence invites does not work out.

The new entry states what a currently-correct document loses, which the
release rule for this patch requires: a non-zero left or top table
margin shifts the table by exactly that margin, a right or bottom one
moves nothing, and a caller who halved their margin to compensate for
the doubling will see their table move.

Three figures in it are measured rather than inherited. The loss
threshold is the emitted row height exactly, 20, 32 and 44 at font
sizes 10, 20 and 30, from a 0..60 integer sweep that draws the row at
every margin after the fix. The x origin is 36 rather than 26 at a 10pt
table margin, which is the document margin plus the table margin twice
plus the cell's own 6pt left padding, a term the first draft omitted.
And the geometric stop test drops no row: 108,880 documents over page
heights 60..400 and table margins 0..19.75 in quarter-point steps,
107,320 rendered drawing all twelve rows, 1,560 raising the too-tall
exception, none with a wrong row count.

Also corrects the comments and public documentation the two fixes made
stale. Two comments in TableRenderer still described the pre-fix
behaviour. FindHeaderRowIndices claimed the leading contiguous run was
"the only reading" under which the two loops partition the rows, which
a prefix of any length equally satisfies. AddRow and AddHeaderRow still
documented every header row as repeating. And the row-axis test class
doc called the margin defect content loss, when it is an offset below
the row height and loss only at or above it.
@Tim81
Tim81 force-pushed the fix/table-row-axis branch from ef45573 to 3b9f439 Compare September 11, 2026 15:07
@Tim81 Tim81 changed the title fix(layout): stop losing a table row, a margin and a span to the row loop fix(layout): stop losing a table row and doubling its margins Sep 11, 2026
@Tim81
Tim81 merged commit 5e4c93d into main Sep 12, 2026
4 checks passed
Tim81 added a commit that referenced this pull request Sep 12, 2026
…red (#493)

The rowspan half of #480, split out of #486 after review found the
attributes as first written introduced a PDF/UA-1 regression.

A spanning cell was drawn twice: once at its origin row across the
combined height of the rows it covers, then again when the span map
reached the last covered row. Untagged that emitted duplicate operators;
tagged it also emitted a second structure element parented to the wrong
row, because the second call passed the span's origin row.

Nothing in the layout package wrote /RowSpan or /ColSpan. ISO 32000-1
Table 349 defaults an absent value to 1, so a spanning cell claimed a
one-by-one slot and the row it covered read one column short. The
duplicate draw had been accidentally supplying that slot for a span of
exactly two, so deleting it without the attributes would have turned a
compliant document non-compliant; a span of three or more was already
refused. Measured with veraPDF 1.30.2 on both sides.

The emitted value is the span the renderer applied, not the span the
caller declared. A cell declaring more rows than the table holds used to
claim them, and a repeated header claimed a row the continuation page
draws in full, which took a three-page document from compliant to two
failed checks. Both the painted rectangle and the attribute now come
from one number: the run of rows the page actually draws.

ColSpan is bounded too, for a narrower reason. A span from an earlier row
advances the column past this row's own accounting, so a cell can start
where fewer columns remain than it asks for.

A row every column of which is covered contributes no cell and now gets
no row element.

Measured over 238 corpus documents hashed on their decompressed content
streams: seven moved, each attributable, and the header rectangle on a
continuation page goes from 40pt to 20pt where it used to overlap the
first data row.

Refs #365, #480
@Tim81
Tim81 deleted the fix/table-row-axis branch November 21, 2026 06:37
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.

1 participant