Skip to content

fix(layout): report 207 only where a clamp or a move was skipped - #713

Merged
Tim81 merged 8 commits into
mainfrom
fix/list-207-narrow
Nov 27, 2026
Merged

Tim81 merged 8 commits into
mainfrom
fix/list-207-narrow

Conversation

@Tim81

@Tim81 Tim81 commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Report ListIndentClampSkipped (207) only where a clamp or a move was skipped.

Since #682, every list with at least one entry that the document lays out as its twin (the layout it had before the clamp of #476 and the moving of #685) and draws from its first entry reported 207 with a Count of at least 1. 207 is an Error, so StrictDiagnostics refused every such document, including one where the twin and the new layout would have been identical. A one-entry list with no indent, followed by a renderer of yours, an entry in a font the document cannot draw, or an element near the continuation limit, was refused under strict mode. Main (1dc734d) refuses all three; before #682 all three saved.

The rule

A twin reports 207 only for an entry it left as it was that the new layout would have changed:

  • an entry whose gutter the clamp would have narrowed (the count BuildItems already kept), or
  • an entry whose marker or text does not fit what is left of a page, which the twin placed where it falls and the new layout would have moved to the next page (new: ListRenderer counts these in the twin's own layout walk).

Count is the number of those entries, and no entry is counted twice. BuildItems marks each entry it counts as a clamp (Entry.ClampCounted) and the move count skips marked entries. The mark is needed: the text of a clamped entry has no width in the twin, but PartUnplaced also reads a marker that wraps and is cut at the page end, without looking at the text, so the first version of this change counted such an entry twice (a 40 pt marker in a 25 pt column at the end of a page: Count 3 for two entries, measured before the rebase at c6f07e9, now 5c3ce7a; the test pins 2). The same rule holds for every placement that reported 207: the continuation limit and the three document-wide causes.

An entry counts unless drawing it in the new layout would draw text in a font the document cannot draw, which makes the save throw. The exemption is decided from what the wrap draws: ParagraphRenderer.WordWrap is split so that its tokenising step, which places the word pieces and line breaks of the runs with the style each is drawn in, is one method that both WordWrap and the count call. An entry is exempt when its marker, or a word that method places, is in such a font. A page reference holds no text and so yields no token; it is read as a word in its own style, because its label is what the pagination makes it, differs between passes and exists only inside a layout, and CanDrawEntry reads a reference the same way. The method measures nothing, so it records no glyph (an earlier attempt that laid the text out changed the bytes of an embedded font subset). The width the clamp gives the text does not change which styles the wrap places, so no width is needed. CanDrawEntry, which chooses the layout the document uses, keeps the body it has on the links branch (it skips a run by HoldsText). The count asks the question only for the entries it would otherwise count. Two earlier predicates read a hand-written list of what the draw shows and each missed a case (a run of white space, then a run of line feeds), which is why the exemption now reads the wrap itself. An entry whose marker alone is undrawable throws when the save draws the marker; strict mode publishes the diagnostics before the write, so a strict save shows it is not counted (the exception is the write's own, not a refusal for 207).

Three lists depart from the definition, and LayoutDiagnosticCode.ListIndentClampSkipped states them as the code has them: a list a renderer of yours holds reports neither 207 nor 208; a ListRenderer built to start at a later entry does not report 207 (it can report 208); a list that holds an entry no page holds reports 208 and not 207 on its own, and when the limit or a document-wide cause also lays it out as its twin it reports 207, counted as any other list's, and 208 only for a part it placed and could not draw (an entry whose text the clamp would have narrowed is counted under 207 instead).

The rule is stated once, on LayoutDiagnosticCode.ListIndentClampSkipped. ListElement, Document and ListRenderer point to it, and the CHANGELOG repeats it in short. The <b>Do/not</b> split and the "as that code describes" and empty-list sentences are rewritten with it.

Where a move is found

A move is found only by the piece that reaches the entry. A document without a header, footer or dependents lays out in one pass and draws each piece before it lays out the next, so the start piece cannot know about a later page. Each piece therefore counts the moves among the entries it begins (_moveSites, set by every Layout of the piece and read by Draw), the start piece adds the clamp count, and LayoutDiagnosticSink adds the counts of one list's pieces: it keys on code, element kind, element index and subject, not on page, so Count sums and the first page stays (LayoutDiagnosticSink.ReportCore). A measuring pass and a drawing pass lay out new pieces, so a move is counted once per save.

Message

The message names the causes that applied (AllListsMessage, unchanged in that respect: a list twinned only by the near-limit rule does not name a font, pinned by a test) and now says an entry was left as it was, instead of saying the list was laid out as before. The limit's message says the same.

Output

No PDF byte changes. Only the diagnostics and their Count change, and so which strict saves succeed.

  • Probe of the three refusals (one-entry list followed by a renderer of yours, an undrawable-font list, a 1,700-tab Preformatted), run on 1dc734d (the links branch) and on a7b878b: all three throw InvalidOperationException ("StrictDiagnostics refused the save: ListIndentClampSkipped") on 1dc734d, and all three save under strict on a7b878b. The bytes are equal with and without strict, and equal on both (CD3C042260C62474, 2A14935FA1E4A4E2, 4A9DF37CB9A0C79A).
  • The generators built for this change (15 sets compared by script plus one multi-line set compared by hand), against 1dc734d and a7b878b, loading VellumPdf.Layout 2.3.3+1dc734d and 2.3.3+a7b878b (each probe prints the assembly path it loaded): 285,038 rows in the scripted sets, 284,457 rows equal. The other 581 are strict-mode rows that 1dc734d refused for 207 (127 save now, 126 are refused for 207 on another list, page or count, 55 for another code, 273 throw the exception the document raises without strict, IndexOutOfRangeException). No row without strict differs. The multi-line set x10c has the same 12 hashes on both. The Layout.Tests goldens pass at a7b878b (below).

CHANGELOG

The #476 and #685 bullets (still under [Unreleased]) are rewritten: the "or 1" count and the "with it, a 207 refuses the save" sentences are gone.

Tests

ListSkippedReportTests (value-level: code, Count, page, element index, message, strict outcome) per cause (renderer of yours, undrawable font, element near the limit) and for the limit:

  • nothing differs: the list does not report 207 and the document saves under strict, with the same bytes;
  • a clamp skipped: Count is the entries narrowed, strict refuses;
  • a move skipped: Count is the entries moved, strict refuses;
  • a move on a later piece, with and without a header: counted once, on that piece's page;
  • the moves of several pieces add up in one report; a single-piece list counts its move once per save;
  • a clamp and a move in one list add up, with no entry twice;
  • an entry no page holds at a page top is not a move;
  • a clamped entry or child entry whose marker is cut at the page end is counted once (two tests, one for an item and one for a child);
  • a page reference in a style the document cannot draw is not counted at the clamp site, the move site or a child, and the same reference in a drawable style is counted (strict refuses);
  • a child whose text is in an undrawable font is not counted (a handle another document returned; a Standard 14 value the enumeration does not name measures nothing, so that row would reach no exemption);
  • spaces, tabs, line feeds, lone carriage returns and CRLF in both fonts at the clamp site, and a line feed at the move site and in a child;
  • a renderer built to start at a later entry does not report 207;
  • a document that holds a renderer of yours and a later-start list is refused under strict for 208, with no 207;
  • the message names the cause that applied and no other.

Seven existing tests asserted the removed "1 when none" behaviour or a 207 for an undrawable entry and are updated.

Mutants at a7b878b on the whole VellumPdf.Layout.Tests project (4,035 cases, net10.0, Release, oracles required; 0 failed unmutated), each a one-edit diff to ListRenderer.cs or ParagraphRenderer.cs:

Mutant (the edit) Cases failed Tests that fail (most)
a page reference is not read as a word (DrawsWordInStyle) 5 AReferenceInAnUndrawableStyle_isNotCounted (3), AReferenceInAnUndrawableStyleAtAMoveSite_isNotCounted (2)
the child site has no exemption (!DrawingWouldThrow removed) 2 AChildWhoseTextIsInAnUndrawableFont_isNotCounted, AReferenceInAnUndrawableStyle_isNotCounted (child)
the item site has no exemption 8 AnEntryWhoseUndrawableRunIsANoBreakSpace_isNotCounted (2), AnEntryWhoseMarkerIsInAnUndrawableFont_isNotCounted (2), AReferenceInAnUndrawableStyle_isNotCounted (2), AnEntryWhoseTextIsInAnUndrawableFont_isNotCounted, AnEntryWithARunThatCannotBeDrawn_isNotClamped
the move site has no exemption 7 AReferenceInAnUndrawableStyleAtAMoveSite_isNotCounted (2), AMarkerInAnUndrawableFontThatDoesNotFit_isNotCountedAsAMove (2), AnEntryWithARunThatCannotBeDrawn_isNotMoved (2), OnlyTheListThatWouldHaveMovedAnEntry_reportsTheFallback
the wrap step is skipped (DrawsWordInStyle term removed from DrawingWouldThrow) 13 the reference rows, AnEntryWhoseUndrawableRunIsANoBreakSpace_isNotCounted (2), AnEntryWithARunThatCannotBeDrawn_isNotMoved (2), AnEntryWhoseTextIsInAnUndrawableFont_isNotCounted, AChildWhoseTextIsInAnUndrawableFont_isNotCounted
the wrap step reads every non-empty run instead of the tokens 18 AnEntryWhoseOnlyUndrawableRunDrawsNothing_isCounted (14), the move-site rows (2), the child rows (2)
the marker term is removed from DrawingWouldThrow 4 AnEntryWhoseMarkerIsInAnUndrawableFont_isNotCounted (2), AMarkerInAnUndrawableFontThatDoesNotFit_isNotCountedAsAMove (2)
the move site is never counted 24 AMoveOnALaterPiece_isCountedOnceAndKeepsItsPage (6), EachEntryTheNewLayoutWouldHaveMoved_isCounted (3), TheMovesOfSeveralPieces_addUpInOneReport (2), and others
the child site is never counted 6 AChildWhoseOnlyUndrawableRunDrawsNothing_isCounted (2), AReferenceInADrawableStyle_isCounted (child), AClampAndAMoveInOneList_areCountedTogether_andNoEntryTwice, TheFallbackCount_isTheEntriesTheClampWouldHaveNarrowed, Decision_agreesWithTheUnclampedPlacement_forSeededLists

Rows measured earlier in this change, on the commits before the rebase (1fc9de9, 94251be and ee4a126 there, now 1b8b090, 07891d5 and 98c9e22), for the other mutants, were not rerun at a7b878b: no clamp mark (1 before the rebase at 1fc9de9; 2 at 94251be with the child test), no child mark (1 at 94251be), report with Count of at least 1 (25), moves from the start piece only (14), drop the clamp count (47 at 1fc9de9), count a move once per pass (2), count a move at a page top (3), report moves from a renderer built to start later (2).

Gates at a7b878b: Release build, 0 warnings; VellumPdf.Layout.Tests in Release on net10.0 and net11.0 with the oracles required, 8,070 cases, 0 failed, 4 skipped (two Linux-only pipe tests per framework); dotnet format --verify-no-changes; eng/clean-room-check.ps1; generate-roadmap.py --check.

Cost

No extra layout pass. A twin that reports pays one PartUnplaced call (a text wrap if the entry's text has not been wrapped) and one font check per entry it finds placed where it does not fit, and nothing for an entry that fits. Measured on a document with a 40,000-entry twin list followed by a renderer of yours, 200 by 50 pt pages, one run per cell after the probe's own warm-up, release build, net10.0, on a machine that other builds shared; the output hashes are equal on both builds:

Entries Shape 1dc734d ms / allocated KB a7b878b ms / allocated KB
10,000 all fit 172 / 86,423 151 / 86,757
40,000 all fit 636 / 345,267 675 / 346,603
10,000 all clamped 89 / 70,112 116 / 70,681
40,000 all clamped 468 / 279,346 449 / 281,627
10,000 every second entry moves 208 / 80,782 189 / 86,154
40,000 every second entry moves 880 / 323,612 638 / 345,105

The times go both ways between the two builds (10,000 entries all clamped 89 to 116 ms, 40,000 every second entry moves 880 to 638 ms) and one run per cell says nothing about their spread, so I do not read them. The allocation rises by 0.39% (40,000, all fit), 0.82% (40,000, all clamped) and 6.6% (40,000, every second entry moves; 21.5 MB over 20,000 moved entries, about 1.1 KB per moved entry for the tokenising step).

Not done, and why

  • A list that holds an entry no page holds, and that the limit or a document-wide cause also lays out as its twin, is placed where each entry falls by the new layout too, so the twin gave up nothing there, but it still reports what it counts. Telling needs the entries laid out on a page of their own. I built that check and it changed the bytes: it laid out the text of entries the twin never draws, which added the space glyph to an embedded font subset in one generator row (the file grew from 56,093 to 56,106 bytes, with the same text). I removed it. LayoutDiagnosticCode says so. On its own such a list reports only 208.
  • The clamp count does not read the width a clamped entry's text would have, only its gutter, for the same reason.
  • The move count has no continuation-start term. A continuation piece is laid out after the page advances, so AtPageTop is true and the page-top term covers it. I instrumented the old guard's condition (a continuation start, not at a page top, PartUnplaced true) and ran the 3,806 cases of the test project: 0 hits. The guard also did not match the new layout's moves, which has no such term, so if it could fire it would under-report. It is deleted.
  • Tables (Tracking: defects found while doing the v2.4 work (not yet fixed) #613 item 47) are out of scope.

Removed in 3.0

_moveSites and _fromFirstEntry exist for the twin and go with it (#688), with the rest of the 207 reporting. Nothing in this change is public API.

Where each figure was measured

The branch is rebased onto main (1dc734d). The figures below were measured at fa4aba4 on the links branch (1c6e44c), before a last rebase that changed no file: a7b878b and 1dc734d have the same trees, so the figures name those. The last commit, d7e72a5, changes three documentation sentences and nothing else. Nothing measured before the rebase is used here, except the mutation rows marked "earlier" under the table.

  • Probe, 285,038-row comparison, cost table, mutation table and gates: a7b878b against 1dc734d.

Strict mode also refuses a twin's 208: a document that holds a renderer of yours and a ListRenderer built to start at a later entry (added separately: the renderer does not hold the list) is refused for 208 with no 207 (test AStrictSaveIsRefusedFor208_whenTheDocumentHoldsARendererOfYoursAndAListBuiltToStartLater), so the CHANGELOG and ListElement say "207 or 208". Such a list never reports 207, so strict can save a document whose list differs from the new layout; LayoutDiagnosticCode says so.

@Tim81 Tim81 added the area/layout high-level document/layout engine label Nov 26, 2026
Every list the document laid out as its twin and drew from its first
entry reported 207 with a Count of at least 1. 207 is an Error, so
StrictDiagnostics refused every such document, including one where the
twin and the clamped and moved layout would have been identical.

A twin now reports 207 only for an entry it left as it was that the new
layout would have changed: an entry whose gutter the clamp would have
narrowed, or an entry that does not fit what is left of a page
and that the twin placed where it falls. Count is the number of
those entries and a list with none reports nothing. A moved entry is
counted by the piece that starts it, so a move on a later page is found
when no header or footer makes the document lay out twice, and the
diagnostic sink adds the pieces' counts. An entry in a font the document
cannot draw is not counted, because the new layout leaves it as it was.

The message of a twin placed by the continuation limit or by a
document-wide cause now says an entry was left as it was. No PDF bytes
change; only the reports, and so which strict saves succeed.
An entry the clamp would have narrowed was counted a second time as a
move when its marker wrapped and was cut at the page end, because
PartUnplaced reads the marker without the text. The twin now marks the
entries BuildItems counted as clamps and the move count skips them.

The move count's continuation-start guard is removed: a continuation is
laid out at a page top, and no case of the Layout test project reaches
the term. The strict sentences of the CHANGELOG and ListElement now name
208 as well as 207, and the code doc says a renderer built to start at
a later entry can save under strict mode.
The undrawable-font exclusion now gives its true reason: narrowing or
moving such an entry would draw text that makes the save throw. A list
that does not report 207 is no longer said to report nothing where it
reports 208, the entry-no-page-holds exception is in the summary, and
the rule is worded as "left as it was an entry that the clamp or the
moving would have changed".

Tests: a child entry whose clamp and cut marker are counted once, a
renamed later-start test, the strict 208 test described by what it
builds, and a bool where a code number was read as a flag.
The 207 count skipped an entry when CanDrawEntry said the document
cannot draw it. That check reads a run of white space alone, which the
wrap draws no fragment for, so an entry such as "abc" followed by a
space in an undrawable font lost its text with no report and a strict
save succeeded where it had been refused.

CanDrawEntry keeps choosing the layout the document uses, unchanged.
The count calls the same predicate with skipWhitespaceRuns, so an entry
is exempt only when drawing its marker or a run with text would make
the save throw.

The 207 remarks now list the exceptions as the code has them: a list a
renderer of yours holds, a list built to start at a later entry, and a
list with an entry no page holds, which reports 207 only when the limit
or a document-wide cause also lays it out as its twin.
The exemption read a hand-written list of what the draw shows, and each
version missed a case: a run of white space, then a line feed, in an
undrawable font still lost its text with no report. It is now decided
from the tokens ParagraphRenderer places for the entry's runs: an entry
is exempt only when its marker, or a word the wrap draws, is in a font
the document cannot draw. The tokenising step of WordWrap moves to a
method both call, which measures nothing and so records no glyph.

CanDrawEntry, which chooses the layout the document uses, keeps its body
and takes no flag. The 207 remarks give the rule in one sentence and the
three exceptions as the code has them.

Tests cover spaces, tabs, line feeds and CRLF in both fonts at the
clamp site, and a line feed at the move site and in a child, a no-break
space that stays exempt, and the marker through the strict path and
through a marker that does not fit the page end.
A page reference holds no text, so the tokenising step the exemption
reads yields nothing for it and an entry whose reference is in a font
the document cannot draw was counted, although the new layout would
draw the label in that font and the save would throw. A reference is now
read as a word in its own style. The label is not read: it is what the
pagination makes it, differs between passes, and exists only inside a
layout, and CanDrawEntry reads a reference the same way.

Tests put a reference in an undrawable style at the clamp site, the move
site and a child, and the same reference in a drawable style, which is
counted. A child whose text is in an undrawable font is now pinned too,
and a lone carriage return joins the white-space rows. The Tokenise
comment now says that a tab token carries a style and draws no text.
A list that holds an entry no page holds reports 208 only for a part the twin placed and could not draw, and counts an entry the clamp would have narrowed under 207 instead. The same entries can report 208 alone, and 207 alone once a renderer of yours joins the document.
…thing

The three sentences said such a document saves under strict mode. A list
in a font the document cannot draw loses nothing to the twin and still
throws, with or without strict mode, so they now say what strict mode
does rather than how the save ends.
@Tim81
Tim81 force-pushed the fix/list-207-narrow branch from 6e498d2 to d7e72a5 Compare November 27, 2026 07:43
@Tim81
Tim81 merged commit 31f1261 into main Nov 27, 2026
4 checks passed
@Tim81
Tim81 deleted the fix/list-207-narrow branch November 27, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/layout high-level document/layout engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant