Repository navigation
fix(layout): cut a table row taller than a page between its lines - #661
Merged
Merged
Conversation
A row that did not fit the room left, and would not fit a page of its own either, made Save throw 'too tall' with no hint of the row. It is now cut between the lines of its cells and continues on the next page, with the repeated header rows above each slice. A row that fits a page still moves to the next page whole. Header rows, rows held by a RowSpan and rows with a cell that cannot hold one line stay refused, and the message names the rows or the cell. The document tells the renderer what a fresh page offers, so a renderer given a context it did not build never cuts. Closes #516
The Tagged PDF Best Practice Guide reserves TH for cells that head something and says an empty cell is always a TD. A cut header row can leave a cell with no line on a page, which was written as an empty TH.
# Conflicts: # src/VellumPdf.Layout/Rendering/Table/TableRenderer.cs
The rule that an empty cell is a TD, never a TH, is in the Tagged PDF Best Practice Guide's table checklist (4.2.6.2), not 3.5 (empty structure elements).
The shipped prose said a row that fits a page is never cut. It is cut when it fits neither fresh-page box, which a repeated header or the table margins can make true of a row that fits the page alone. Also corrects the TH/TD claim for header rows, the non-finite margin changelog entry, and what holds for a context the document did not build. Adds tests for the margin-deflated box and for resuming a cut row under a plain context.
Round 1 said a header row always names the header rows, that a cut row keeps cutting under any context, and that a table returns the rows that fit before an uncut row. Each is false under a header after data, another width, or a RowSpan group. Adds a test that kills a doubled margin deflation of the fresh page box.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #516
What changed
A table row taller than a page is cut between the lines of its cells and continues on the next page. On 2.3.3
SavethrewInvalidOperationException("An element is too tall to fit on a single page") for it, with no hint of the row or the cell.Marginsof 10, on a 300x600 page with 10 pt margins: 2.3.3 throws, this build saves 2 pages). A table whose rows each fit the area a fresh page leaves under its header rows and inside its margins cuts no row.nwithn * leading + vertical paddingfitting the room, by the same test the fit loop applies to a whole row. Every slice is drawn as a whole cell (background, border, padding); a cell with no line left draws an empty rectangle.Tableper page, oneTRper row and slice, one cell element per cell of each slice. A cell cut across pages is tagged on each page: a cell that holds a line is aTD, or aTHin a header row, and a slice cell with no line is an emptyTD, also in a header row (the Tagged PDF Best Practice Guide, 4.2.6.2, says "empty cells are always cells, never cells"). This is the per-page-fragment shape every split table already has.InvalidOperationException, whose message is the old text followed by a sentence naming what cannot be cut: header rows that do not fit a page; a row that declares aRowSpanor lies under one (rows named); a row with a cell whose vertical padding plus one line does not fit the page under the header rows (row and cell named).LayoutContextgets an internalFreshPageArea, set by the document on every layout call in both passes and copied byWithArea.LayoutResultgets an internalNothing(string reason)andReason; the retry throwsElementTooTall().Message + " " + reason. ATableRenderergiven a context built through the public constructor has no such box and does not start a cut; a row already cut keeps cutting in its overflow renderer under such a context only at the width it was cut at; at another width the saved lines are dropped and the row is laid out again from its first line, which without the box is not cut. No public API changes.TableElement,TableRenderer.Layout,Cell.RowSpan,Cell.Padding,Document.Add(TableElement),LayoutContextandLayoutResult; CHANGELOG entry under Fixed.Deliberate output changes
Cell.BackgroundorTableElement.BorderColorchannel, a NaN left margin, a NaN right margin or a-Infinityleft margin (table or document) used to throwInvalidOperationExceptionbefore anything was drawn. The row is now drawn, so the canvas throwsArgumentException(ParamNamenull), as it does for the same value in any row that fits. (Row.Backgroundis not in this list:TableElement.Add(Row)refuses a non-finite channel at the call.) A NaN text colour or negative border width in such a row keepsInvalidOperationExceptionbut the message is replaced, not extended. A+Infinitytable bottom margin keepsInvalidOperationException; its message gains the cell sentence.-Infinityand whose row is too tall for a page now saves (2 pages for 48 lines, 3 for 100; the same table with a short row already saved on 2.3.3). Listed in the CHANGELOG.The existing test that pinned the refusal of a hard-broken 300-character cell on a 200pt page now pins the continuation (16 lines on page 1, 14 on page 2). The test pinning the too-tall message for a
RowSpangroup taller than the page now expects the same text plus the sentence naming rows 0 to 39.2.3.3 against this build
Page 300x600, 10pt margins (content 580pt), Helvetica 10 (leading 12), columns 40pt and 100pt, default padding; a row of n one-word lines is
12 n + 8pt tall. The 2.3.3 column is2.3.3+1c61fa6; the build column is this branch. Bytes are for the whole file.RowSpangroup taller than the pageEvery "same" row is from one probe run printing both assembly versions; the probe runs on 2.3.3 and on 7079efc gave identical outcomes and byte counts for every row above that 2.3.3 saved.
Differential fuzz of random tables (1 to 3 columns, up to 70 rows, row and cell backgrounds,
RowSpan,ColSpan, header rows, footer, tagged or not, four page heights), this branch against 7079efc:In the last run every one of the 1,257 saved files without a footer draws exactly the characters its cells hold (counted from the
Tjstrings). qpdf 12.4.2--checkpasses on the first 120 newly saved files of the second run.Non-finite geometry, measured on origin/main 5aea9ff and on this branch with one probe built against each (each run printed its Layout assembly path): a table margin and a document margin edge of NaN, +Infinity or -Infinity on each of the four edges, for a 5-, 48- and 100-line row, plus a NaN cell background, an infinite border colour, a NaN text colour and a border width of -1 on a 48-line row. Every 5-line case behaves the same on both builds, except a +Infinity bottom table margin, which keeps
InvalidOperationExceptionand gains the sentence naming the cell. On the taller rows, a NaN left or right margin and a -Infinity left margin (table or document), a NaN cell background and an infinite border colour change fromInvalidOperationExceptionto the canvasArgumentException(deliberate output change 2); a -Infinity right margin saves (deliberate output change 3); the NaN text colour and the -1 border width keepInvalidOperationExceptionwith their message replaced by one naming the cause. Every other case behaves the same on both builds: for example a NaN top margin throwsArgumentException, a NaN bottom margin and a -Infinity top or bottom margin save, a +Infinity left or right table margin keeps the too-tall message, and a +Infinity document margin is refused byDocumentwithArgumentException(margins). A +Infinity bottom table margin keepsInvalidOperationExceptionon every row height and gains the cell sentence.Tests (Release, oracles required)
TableRowSplitTests(new, 44 cases): the boundary table above with exact rectangles and baselines per page, a header repeated on three pages, a 20pt row then a cut row (starts on the current page), 29 full rows then a cut row (starts on the next page), cells of different leading, a short cell beside a tall one, rows after a cut row, a footer with{pages}, the 6,000-character cell, row and cell backgrounds and the repeated header background per slice, tagged structure counts, each still-refused shape with the exact message (and the band wording first), a refusal after other rows, a non-finite background and text colour, a context without the box,WithArea, a cut row resumed at another width, a NaN width, an allocation-ratio pin (20,000 lines against 5,000, bound 6), qpdf--checkwithpdftotextpage order, veraPDFua1(with and without a header) and2u.veraPDF 1.30.4 on four cut-row files in an embedded font: PDF/UA-1 plain, PDF/UA-1 under a header, PDF/A-2u with a row background, PDF/A-2u under a header with a row background: each
isCompliant="true",failedRules="0", so the failed-rule list is empty for all four. qpdf--checkpasses on the same four.Gates at fbed88b (main at 2484e51 merged in), oracles required (veraPDF 1.30.4, qpdf 12.4.2,
poppler 26.08.0):
VellumPdf.Layout.Testsin Release, both TFMs together, 3,300 run, 3,296 passed,4 skipped (the Linux-only named-pipe and
/proctests), 0 failed. Release solution build: 0warnings, 0 errors.
dotnet format --verify-no-changes, the clean-room check and the roadmap checkeach exit 0.
Mutations
Each mutation was applied in a detached checkout of the commit, the test project rebuilt (the DLL timestamp checked), the three table test classes run, and the checkout restored with
git checkout -- src.CanCutfalse)ARowOneLineTooTall_isCutAfterTheLastLineThatFitsARowThatFitsAFreshPage_butNotTheRoomLeft_movesWholeACellOfManyLines_allocatesLinearlyInItsLinesRowsAfterACutRow_followItsLastSliceALineThatFitsOnlyWithoutTheHeader_isRefused_namingTheHeaderRowSpangroup may be cutARowUnderAHeaderRowSpan_isRefused_andTheRefusalTerminatesTDATaggedCutRow_underAHeader_repeatsTheThOnEveryPage==(NaN restarts the row)ACutRow_withANaNWidth_isRefusedByTheCanvas_notByTheContinuationLimitARowThatFitsThePageButNotInsideTheTableMargins_isCutACutRow_resumedInAnAreaThatHoldsNoLine_isNothingACutRow_thatBegan_isResumedUnderAContextWithoutTheBoxARendererWithoutAFreshPageBox_*)AHeaderAndARowTooTall_repeatTheHeaderAndCutTheRowWithAreadrops the boxWithArea_keepsTheFreshPageBoxbreakis a guardChecked against the specifications
Table/TR/TDtypes and attributes as any row.Tablefor a table that spans pages. This change does not do that for a cut cell, as no split table in the library does; the page-fragment shape is the existing one and is documented.q/Q(a search ofsrc/VellumPdf.Layout/Rendering/TableforSaveStateandRestoreStatefinds neither), so the nesting limit is untouched.Not done, and limits
TDelements, not one structure element with two marked-content sequences; see above.RowSpangroups, header rows and cells that cannot hold one line stay refused.