Repository navigation
fix(layout): name the input a renderer refuses, instead of the page size - #497
Merged
Merged
Conversation
Five inputs, in two groups, neither of which touches a document that renders correctly today. Three were refused by a message about something else. A renderer that cannot place an element reports placing nothing, and DocumentRenderer reads that as "this element can never fit" and raises the too-tall message. For an oversized element that is the right answer. For a font size of NaN or a ColSpan of zero it is not: the element is not too tall, and the remedy the message offers, reducing its content or enlarging the page, cannot help. The exception type and the site are unchanged, so only the wording moves (#481). Two more saved without complaint and wrote content a reader cannot render. A zero image extent emitted "0 0 0 0 10 390 cm", a singular matrix ISO 32000-2 leaves undefined for a painted XObject; a non-finite one emitted "NaN 0 0 NaN 10 NaN cm", where the token is not a PDF number at all. A zero width also collapsed the height, since the height derives from the width through the aspect ratio and the height check passes trivially at zero (#478). The boundary was measured rather than assumed, and the first attempt got it wrong. Rejecting a whole class at once broke the mirrored-image case in OffPagePlacementTests, which exists to record that a negative extent renders on purpose. Reading the emitted stream for each neighbouring input settled it: a font size of zero gives "/F1 0 Tf", a valid operator; a non-finite leading gives a valid text matrix; a RowSpan below one renders; a negative width gives "-40 0 0 -40 10 430 cm", a valid matrix that mirrors; and a positive-infinity width is clamped to the content box by the off-page fix before anything else sees it. All five keep rendering, and a test pins that, because refusing any of them would turn a working document into an exception and belongs in the next major with the rest of the contract tightening. Nine of the ten new cases fail when the validation is removed. The tenth is the guard that the neighbours still render, which passes either way by design. Refs #478, #481
Four reviewers, four highs between them, all mine. This closes every medium and high, plus the lows worth acting on. The extent guard tested the wrong thing. PdfCanvas formats coordinates to five decimals, so a width of 4e-6 was written as 0 and produced the identical singular matrix the guard's own comment quoted as the thing it refuses. It now tests the written token, with the boundary measured: 5e-6 writes 0.00001, 4.9e-6 writes 0. The running band was the one path to a font operator that reaches no renderer, so it reached no validation either, and saved documents containing /F1 NaN Tf. It had no test in any suite. The comment in DocumentRenderer had already asked for this check. The two table messages counted cells in different index spaces, so a row of two cells could be reported as "cell 3". Both single-cell fixtures were blind to it. The style check now names the authoring index, and a case with a preceding span of two makes the indices diverge. The change was incomplete against its own rule: cell padding, table border width and separator line width all still wrote NaN into the stream, two of them in the renderer it had just guarded. A positive-infinity leading still raised the too-tall message, because it was taken by the positive branch while NaN fell through to the font size. I measured NaN and wrote "a non-finite leading renders" in six places. Every non-finite leading is now treated as automatic. #481 is now actually closed rather than claimed: its third refusal, a table resolving to no columns, says so instead of blaming the page, and all six pie chart refusals name the property set rather than _chart, a private field of the renderer. #478's test rename is done too; the old name promised a zero-dimension refusal its own body said it could not construct. Section (c) asserted Assert.NotEmpty, which a PDF always satisfies. Deleting the image paint operator, or returning early from paragraph drawing, left all ten cases passing. It now asserts the operator each neighbour emits, and the file went from 10 cases to 37. Several prose corrections of the same shape, measuring one value and writing the claim for the class: a negative font size emits /F1 -12 Tf, not /F1 0 Tf; a zero height emits 280 0 0 0 10 390 cm, not the width case's matrix; the ISO citation is 8.3.4 NOTE 3, informative, about painting graphics objects generally, not an "undefined" scoped to XObjects; and "no document that renders correctly today is affected" was false for two inputs. Closes #478, closes #481
Tim81
force-pushed
the
fix/layout-validation
branch
from
September 12, 2026 07:09
2c0aab0 to
4fc2c9f
Compare
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.
Five inputs, in two groups. Neither group touches a document that renders correctly today, which is
what keeps this inside the patch. Closes #478 and #481.
NaNColSpanof 0Two different defects, not one
Three refusals described something else. A renderer that cannot place an element reports placing
nothing, and
DocumentRendererreads that as "this element can never fit" and raises the too-tallmessage. For a genuinely oversized element that is the right answer. For a font size that is not a
number, or a cell covering zero columns, it is not: the element is not too tall, and the remedy the
message offers cannot help. The exception type and the site are unchanged, so only the wording moves.
Two more saved silently and wrote invalid content. Read off the emitted stream:
ISO 32000-2 leaves an uninvertible matrix undefined for a painted XObject. A zero width also
collapses the height, because the height is derived from the width through the aspect ratio and the
height check passes trivially at zero. There was no message to correct here, because there was no
message.
The boundary was measured, after the first attempt got it wrong
My first version rejected whole classes: any non-positive font size, any non-positive extent, any
span below one. That broke
OffPagePlacementTests.Image_negativeDeflatedWidth_emitsTheMirroredMatrixUnclamped,which exists to record that a negative extent renders as a mirrored image on purpose, decided in
an earlier pull request. The failing test was right and the change was wrong.
So each neighbouring input was rendered and its content stream read, rather than reasoned about:
/F1 0 Tf1 0 0 1 10 380 TmRowSpanbelow one-40 0 0 -40 10 430 cmAll five keep rendering. Refusing any of them would turn a working document into an exception, which
this release defers to the next major, and section (c) of the new test file pins that they were left
alone. The positive-infinity case is the one I would not have predicted: it never reaches validation
because the over-wide clamp fires first.
Evidence
the ten. The tenth is the guard that the neighbours still render, which passes either way by
design, since it exists to catch over-reach rather than to prove the fix.
Format and clean-room clean.
What is not here
#476, a list indent at or beyond the content width, which discards every item's text and keeps
the marker. Measured on
5e4c93d: a 180pt content box keeps the text at an indent of 179 and losesit at 180. It is left out because reporting a silent drop needs a diagnostics channel, the two that
exist are narrow one-offs, and inventing a third inside a patch is the decision #496 was filed to
prevent. It is content loss rather than a wrong message, so it does not belong with these.