Repository navigation
feat(layout): add a {chapter} token for running bands - #681
Merged
Merged
Conversation
A handbook header wants the title of the chapter the page is in. The band
resolved only {page} and {pages}, so a caller had no way to get it.
RunningBand.ChapterToken turns on {chapter}. It is opt-in because 2.3.x
printed that text literally, and an existing template must keep its bytes.
The title is the first level-0 heading that starts on the page, else the
last one drawn earlier, else empty. It is followed in the drawing pass
only, from the renderers that were accepted, so the page count and the
number of layout runs are unchanged.
The title a band prints comes from Heading.BookmarkTitle, so a surrogate pair split in it, or a template repeating the token past int.MaxValue characters, makes a save throw from members that said nothing. Document both on the band, the heading and the header and footer. State which pages show which chapter, and add tests for the empty title, no-break spaces, a footer-only token and negative levels.
# Conflicts: # CHANGELOG.md # src/VellumPdf.Layout/PublicAPI.Unshipped.txt
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 #603
What changed
A running band could print the page number and the page count and nothing that depends on the content.
RunningBand.ChapterTokenturns on a{chapter}token that prints the title of the chapter the page is in.ChapterTokenisfalseby default. A template that holds{chapter}without it prints that text, as 2.3.3 did, so no existing document changes. This is a new public member (PublicAPI.Unshipped.txt).Heading. A page shows the first one whose first line is on the page, else the last one drawn on an earlier page, else no text where the token stands (the rest of the template is drawn as written). A heading that splits over a page break counts on the page it starts on, because only the piece that holds its first line is a heading renderer; the overflow is a plain paragraph renderer.BookmarkTitlewhen set, otherwiseText. A tab, line break, form feed or other control white space in it is drawn as a space, so none reaches glyph lookup. The title is copied as it is and never scanned again, so a{page}inside it prints as text.{chapter}alone never triggers a measuring pass. A document without the token pays onebooltest per drawn element (DocumentRenderer.cs:1126) and one null test per finished page (:622).BandTruncationsandBandTruncated. A character the band font lacks is reported asNotdefGlyphas for any band text.RunningBand.ChapterToken,Heading.BookmarkTitleandDocument.Header/Footer: an unpaired surrogate in the title when the band font is embedded (ArgumentException, even when the heading is set in Helvetica), and a template that repeats{chapter}until the text passesint.MaxValuecharacters (InvalidOperationException; 250,000 tokens of a 10,000-character title throw, 200,000 save).RunningBand.Resolve(int, int)knows no headings and leaves{chapter}as given; its docs say so.Document.HeaderandFooterdocs name the token.IRendererdraws start no chapter (documented).Deviations from the plan
RunningBand.ChapterTokenis a new public property. The plan had no new public member; it is needed so that an existing template holding the text{chapter}keeps printing it literally.Resolveoverload is dropped.BandText.Resettakes the chapter title beside the page label, and the compiled template carries the token.2.3.3 against this build
{chapter},ChapterTokenunset{chapter}printed{chapter},ChapterTokenset{chapter} | {page}Hoofdstuk één: Inleiding | 1,... | 2, then the second chapter on pages 3 and 4, the third on 5 and 6, read back withpdftotext -layoutin an embedded font with non-ASCII titlesBandTruncatedThere is no deliberate output change: a document that does not set the property saves to the same bytes.
Differential
3,000 random documents saved on origin/main (2.3.3+2316dee) and on this branch (2.3.3+cc80703), assembly paths printed by both runs. Each had a random page size and margins, a header and footer from eight templates (some with
{chapter}or a malformed one,ChapterTokenunset), Helvetica or embedded DejaVu Sans, page-label ranges, mirrored margins, tagging, level 0 to 2 headings with page breaks, recto page breaks and paragraphs. SHA-256 of the saved bytes, truncation reports and diagnostics count: all 3,000 lines identical, including the 48 that throw (same exception type) and the 131 that report diagnostics.Existing behaviour the title follows
A title glyph that the band font lacks is reported as
NotdefGlyph(severity error) and fails veraPDF 6.2.11.8 under PDF/A-2u, as a literal template character the font lacks already does on main. The title inherits that, and this PR does not change it.Tests
ChapterTokenTests(and one change toRunningBandTemplateTests, which iterated every entry of the token table and now leaves{chapter}aside). Release,REQUIRE_ORACLES=1,REQUIRE_VERAPDF=1: net10.0 and net11.0 each 1,963 passed, 0 failed, 2 skipped (Linux-only pipe tests). Release build 0 warnings;dotnet format --verify-no-changes,eng/clean-room-check.ps1andgenerate-roadmap.py --checkclean. The oracle tests run qpdf--check,pdftotext -layoutpage by page, and veraPDF 1.30.4 PDF/A-2u.Mutations
Each applied in a detached worktree, built, and run against
ChapterTokenTestsandRunningBandTemplateTests.AChapterThatStartsMidPage_isTheOneThatPageShowsASplitChapterHeading_countsOnThePageItStartsOn_notWhereItsOverflowLandsWithTheToken_theTrackerSeesTheDrawingPassOnly_andTheLayoutIsUnchangedand 2 more{chapter}always recognisedWithoutChapterToken_theTextStaysLiteral_asItAlwaysDidAControlCharacterInATitle_isDrawnAsASpace_andNeverReachesTheFontOtherLevels_startNoChapter_andABookmarkTitleIsUsedWhenThereIsOneBookmarkTitleignoredOtherLevels_...TheTwoPassesAgree_soAChapterAndThePageCountPrintTogetherTheFirstChapterOnAPage_winsOverALaterOneWithoutTheToken_theTrackerIsNeverCalledint.MaxValuelength guard removedATemplateThatRepeatsTheTokenPastIntMaxValue_isRefusedAtTheSave_andOneBelowItSavesBookmarkTitlefalls back to the heading textAnEmptyBookmarkTitle_isAnEmptyChapter_notTheHeadingTextANoBreakSpaceInATitle_isNotReplacedByAnOrdinarySpaceAFooterAlone_holdsTheToken_whenTheHeaderDoesNotANegativeLevel_startsNoChapter(both cases)Not done
{section}token for level 1 headings.