Skip to content

feat(layout): build Heading and ListItem from runs - #654

Merged
Tim81 merged 4 commits into
mainfrom
feat/runs-heading-listitem
Nov 21, 2026
Merged

Tim81 merged 4 commits into
mainfrom
feat/runs-heading-listitem

Conversation

@Tim81

@Tim81 Tim81 commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Part of #367

Heading and ListItem take a sequence of TextRuns, as Paragraph does, so a heading can hold a bold word and a list item can hold a link.

What changed

  • new Heading(IEnumerable<TextRun>), Heading.Runs, new ListItem(IEnumerable<TextRun>), ListItem.Runs.
  • Heading.Text is the concatenation of the run texts and is the outline title unless BookmarkTitle is set. Heading.Style is the first run's style. In a tagged document the heading is one Hn element and one marked-content sequence, whatever the number of runs.
  • A run is a link only through its own LinkUri. The annotation covers that run and a space that opens the next run, as in a Paragraph (the same behaviour, pinned by a test). On a list item built from runs, ListItem.Style styles the marker and the children that set no style of their own, not the item's runs. A string-built item keeps its two annotations (marker and content) when its style has a link.
  • A run that draws no text (empty, or only white space) has its style unchecked by the save, as in a Paragraph; the new constructors still refuse a null style on any run.
  • The list's gutter widening reads a word that continues over a run boundary as one word, summing the pieces, so a run-built item is not hard-broken by a gutter widened for a long marker.
  • The new constructors refuse a null sequence and a null run (ArgumentNullException) and a run with a null style (ArgumentException), naming the run's index. An empty sequence is accepted, as an empty string is.
  • Runs returns a read-only view. The string constructors build one run; documents built through them are byte-identical (pins recorded in the first commit, on the commit before the change).

Deliberate output changes

None. No input that saved before changes its output.

Overload resolution

Both run constructors carry [OverloadResolutionPriority(-1)], so new Heading(null), new ListItem(null!), default! and (null!, null) keep binding to the string constructors, as on 2.3.3. Arrays, collection expressions, List<TextRun> and TextRun[] bind to the run constructors. Tests compile each null-literal form and assert the string constructor's behaviour, and the existing null-text tests are unchanged from main. The attribute adds no public symbol.

Not in this PR

Per-run language (/Lang on a run) needs a marked-content property list or a Span child element, which is tagging work. Heading.Runs and ListItem.Runs say it is not written.

Evidence

Value-level tests (RunsHeadingListItemTests): one BDC/EMC pair with /H1, the Tf switch between runs, the outline title bytes, the link /Rect x-range (including the space that opens the next run), the overload binding of null literals and run collections, a read-only Runs, Style from the first run, the refusals and their indices, empty sequences. Oracles: qpdf --check clean, pdftotext -layout prints De Save-methode and 1. Zie Instellingen., veraPDF 1.30.4 2u compliant, on a fixture asserted to contain the font switch and the link.

Mutations

Each mutant was applied to a detached copy of the head commit and the whole Layout test project run in Release on both TFMs; the same tests failed on both.

Mutant Failing tests (examples)
OverloadResolutionPriority removed from Heading(IEnumerable<TextRun>) Heading_everyNullLiteralForm_bindsToTheStringConstructor, NullArgument_isRefusedByTheCallThatTookIt
OverloadResolutionPriority removed from ListItem(IEnumerable<TextRun>) ListItem_everyNullLiteralForm_bindsToTheStringConstructor, NullText_isStoredAsAnEmptyString (+ 44 more per TFM, mostly list diagnostics tests)
Heading.Style from the last run Heading_style_isTheFirstRunsStyle_notTheLast
Heading.Runs returns the internal list Runs_cannotBeChangedThroughACast
ListItem.Runs returns the internal list Runs_cannotBeChangedThroughACast
Null-style refusal dropped Heading_refusesARunWithANullStyle_namingTheIndex, Heading_refusesANullStyleEvenOnAnEmptyRun, ListItem_refusesANullSequence_aNullRun_andANullStyle
Widest word is the widest piece, not the sum ListItem_gutterWidening_readsAWordThatContinuesOverARunBoundaryAsOne
Heading drawn from Text and Style, not the runs Heading_runs_runsPositionsFollowTheMeasuredWidths, Heading_wordSplitBetweenStyles_drawsNoSpace, LinkRect_coversASpaceThatOpensTheNextRun, EmbeddedRuns_oracles_qpdfPdftotextVeraPdf (+ more)
String list item content ignores the inherited style Lists_pinTheBytes, EmbeddedLists_pinTheBytes (+ 30 more per TFM)

Gates

Release, oracles required (REQUIRE_ORACLES, REQUIRE_VERAPDF, veraPDF 1.30.4, qpdf 12.4.2, poppler):

Check Result
VellumPdf.Layout.Tests, net10.0 1370 passed, 0 failed, 2 skipped
VellumPdf.Layout.Tests, net11.0 1370 passed, 0 failed, 2 skipped
dotnet build VellumPdf.slnx -c Release 0 warnings, 0 errors
dotnet format --verify-no-changes, clean-room check, roadmap --check exit 0 each

The two skipped cases are the named-pipe saves in SaveLifecycleTests, which skipped on this machine.

Records the normalised bytes of documents built only through them, on the
commit before runs are added, so a later difference shows an existing
input's output moved.
A heading could not hold a bold word and a list item could not hold a
link, because both took one string in one style. Both now take a
sequence of runs, as Paragraph does, and the string constructors build a
single run so their output is unchanged. A null run or a run with a null
style is refused at the constructor, since these are new members.
A null literal bound to the new runs constructors and threw at
construction, where 2.3.3 saved a ListItem and threw from Heading with
another parameter name. Lowering the runs constructors' overload
priority sends those calls back to the string constructors. Runs now
returns a read-only view, and the docs state what a run's link covers,
what ListItem.Style styles, and that a run drawing no text is not
checked.
@Tim81
Tim81 merged commit 8f76b73 into main Nov 21, 2026
4 checks passed
Tim81 added a commit that referenced this pull request Nov 21, 2026
Golden pins for embedded-font run-built headings and lists: #654 pinned them before #656 changed every embedded TrueType font program.

Re-pinned on the merged result. A qpdf --qdf diff between the two commits shows only #656's deliberate changes: /FontBBox in the font descriptor, the FontFile2 program without cmap and with /Length1, and its /Length; the trailer /ID and offsets follow.
@Tim81
Tim81 deleted the feat/runs-heading-listitem branch November 26, 2026 20:21
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