Skip to content

feat(layout): a running band with three zones, a logo and a rule - #735

Merged
Tim81 merged 9 commits into
mainfrom
feat/layout-band-zones
Nov 28, 2026
Merged

Tim81 merged 9 commits into
mainfrom
feat/layout-band-zones

Conversation

@Tim81

@Tim81 Tim81 commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Closes #365.

What

A running header or footer can hold three zones on one line. new RunningBand(left, center, right) takes
three BandZone values. A zone holds styled TextRuns, a logo (BandZone.Logo(LayoutImage)), or nothing
(BandZone.Empty). Document.Header and Document.Footer keep their type, and the string constructor is
untouched.

New public types: BandZone, BandRule, BandRulePosition. New RunningBand members: the constructor,
Left, Center, Right, Rule, ZoneGap, MirrorZones.

Decisions

  • Tokens. Each run is compiled by BandTemplate and resolved by BandText, the machinery a string band
    uses. {chapter} still needs ChapterToken. RunningBand.CountOf sums token counts over the runs, so the
    chapter tracking and the page-label lookup see a zoned band.
  • Text box and baseline. All text of a band sits on one baseline. The text box is the largest ascent plus
    the largest descent over the band's runs, from each font's own bounding box (Adobe's published AFM FontBBox
    for the 14 faces, head.yMin and yMax for an embedded font) scaled by the run's size. It is centred in what
    the rule leaves of the band. The rule keeps 1 point clear of the text box and of a logo. The minimum height is
    the text box plus the rule width plus that point; the default height is the larger of that and the largest
    leading plus 4. An embedded font's head box encloses every glyph the font holds, so the rule never touches
    text drawn in it. A Standard 14 face is not embedded: its box is Adobe's, and a viewer that substitutes a font
    of its own can draw glyphs past it. A review measured this with poppler 26.08 on Windows:
    Courier Bold at 30 pt, at the minimum height with a rule below, put 947 dark pixels inside the rule's rows. The
    docs state this limit and recommend an embedded font where the rule must stay clear; the geometry does not
    change for it.
  • Collisions. Priority is a logo (never cut), then the right zone, the left, the centre. It follows the
    zone, not the side, so swapping on even pages does not change who is cut. The centre stays centred, so it gets
    twice the room of its nearer neighbour.
  • The cut. A zone is cut as one text, over all its runs, at the last literal space that fits, as the string
    band's cut does (a space that is itself the character that does not fit is not a boundary, as there). A
    boundary between two runs counts only where a space stands. A resolved token (page number, page count, chapter
    title) is never cut inside, and spaces inside it are not boundaries. When no space qualifies, the cut falls at
    the last position that fits outside a token, so one long literal word is cut mid-word as in a string band. A
    zone of which nothing fits is dropped and counted in the report.
  • A zone's place. A zone is placed at its side's edge (or the centre) whatever its text measures, so a zone in
    Symbol or ZapfDingbats (zero measured width) stays in the content box. Such a run cannot be cut or kept off the
    next run of its zone, which BandZone documents under "Do not pass", with Kernel: Symbol and ZapfDingbats have no advance-width tables, so every string in them measures zero #470 as the cause. The gap between two drawn zones is ZoneGap (6 pt by default). The cut is
    reported through BandTruncationWarning and BandTruncated, once per band, naming the page that lost the most;
    its counts add the characters of all zones of that page. No new warning type.
  • Refused at save, naming the band. Logos that cannot stand side by side with the gap, a logo wider than the
    content box, a logo written with no area, and a height below the text box plus the rule width plus its clearance. Swapping the left and right
    zones changes none of the logo sums, because the centre is centred, so one check covers both kinds of page.
  • Logo. Scaled to the band's height less the rule's width and clearance, width from its proportions, drawn in the same /Artifact marked content
    as band text when the document is tagged. No alternative text, no Figure. Input is a LayoutImage; only its
    Image is read, and the other properties are ignored (documented on BandZone.Image).
  • Even pages. MirrorZones swaps the left and right zones on even physical pages when
    Document.MirrorMargins is set, the parity the mirrored margins use. It is not the page label. Without
    MirrorMargins it does nothing.
  • Rule. BandRule lies inside the band, so the content area does not move. It works on a string band too
    (opt-in, no change when unset).
  • New API refuses from the start. At build, where the zone alone decides it: null zones, runs, styles and
    text; a page-reference run; a styled link; a Standard14 value the enumeration does not name; an unpaired
    surrogate; a font size that is not a finite number of at least 5e-6 (smaller is written as 0); a colour
    channel outside 0 to 1; an image with no area; a rule width that is negative or not finite; a zone gap that is
    negative or not finite; a zoned band's Height that is not finite and positive or is below its text box. At
    the save: a font handle from another document, a logo that does not fit or would be written with no area, and
    a height below the text box plus the rule. ZoneGap and MirrorZones on a string
    band, and Resolve on a zoned band, throw InvalidOperationException.
  • RS0027, a source break. The zoned constructor has the same parameter count as the shipped string
    constructor, which has optional parameters. A factory would not work because Height, Rule and MirrorZones
    are init-only, so the warning is suppressed on the shipped constructor with a comment. Four literal call shapes
    stop compiling (CS0121, ambiguous): new RunningBand(default, default, default),
    new RunningBand(null!, null, default), new RunningBand(null, null, default) and
    new RunningBand(null, default, default). The rule is that the first two arguments are each a literal null
    or default and the third is default. new RunningBand(null!, null!, null!) did not compile before and now
    binds to the zoned constructor. Compiled callers bind by signature and are unaffected, and a first argument that has a
    type compiles as before. The CHANGELOG says so.
  • CMYK logo under PDF/A. A DeviceCMYK logo without a CMYK output intent saves non-conformant, as the same
    image does as a body image (the class predates this change). BandZone.Logo says the image follows the image
    rules of the conformance claim.

Evidence

Check Test
Zones at exact x ThreeZones_standOnOneLine_atTheExactX, AFooter_stands_atTheFootersBaseline, RunsOfOneZone_followEachOther_withTheirOwnStyles_onOneBaseline
Tokens Tokens_resolveInEveryZone_onEveryPage (12 pages), Tokens_resolve_inADocumentWithPageReferences_whichMeasuresAgain, Page_printsTheLabel_whenTheDocumentDefinesLabelRanges
Mirror Zones_swapSides_onEvenPages_andNotOnOddOnes, EvenMeans_thePhysicalPage_notTheLabel_withRomanFrontMatterAndADecimalBody, and the two negative cases
Rule ARuleBelowAHeader_isDrawnOnEveryPage_atTheExactCoordinatesAndWidth, ARuleAboveAFooter_liesOnTheBandsTopEdge_inTheMirroredMarginsOfItsPage
Logo ALogo_isScaledToTheBandsHeight_atItsZonesEdge_asDecoration, ALogoInEachZone_standsAtThatZonesPlace
Collisions ALongCentre_yieldsToTheRightZone_..., ALongLeft_yieldsToTheRightZone_..., ACentreNextToALogo_..., Zones_neverOverprint_... (120 random rounds)
Refusals the *Refuses* and *refuses* tests in BandZonesTests
Cut as one text ALabelAndANumber_inTwoRuns_... (the reported case: "Page " and "{page}" on page 12 draw "Page"), ATokenAtARunBoundary_..., AChapterTitle_isNotCutAtASpaceInsideIt_..., ARunBoundaryWithNoSpace_*, AZoneCutAcrossRuns_neverPrintsAPartOfATokenValue_... (150 random splits)
Zero-width zone AZoneThatMeasuresZero_standsAtItsSidesEdge_insideTheContentBox (Symbol, margins 0 and 20)
Rule off the text, logo off the rule BandZonesRuleRenderTests (pdftoppm: no dark pixel in the rule's rows, at the minimum and the default height, above and below, Helvetica and Times), ALogoBesideARule_..., the oracle fixture's logo matrix
Bytes BandZonesByteIdentityTests (144 string-band documents, recorded on origin/main before the change), a 1,500-document generator (random page sizes, margins, mirrored margins, tagged, PDF/A-2u, PDF/UA-1, Standard 14 and embedded fonts, tokens, alignments, heights, truncation, strict) whose output, truncation reports and diagnostic codes are identical on origin/main and here, and the existing goldens
PDF/A-2u, PDF/UA-1 BandZonesOracleTests: veraPDF 2u and ua1 pass on a document with a three-zone header, a logo and rules; qpdf clean; pdftotext reads the zones

Mutations

Each was run in a detached worktree and fails the named tests. The first four are the original set; the rest
cover the changes made after review. The runner's environment includes the JDK, as veraPDF needs it.

Mutant Fails
zones never swapped Zones_swapSides_onEvenPages_andNotOnOddOnes, ALongLeft_yieldsToTheRightZone_andTheCutZoneStaysTheLeftOneWhenZonesSwap, EvenMeans_thePhysicalPage_notTheLabel_withRomanFrontMatterAndADecimalBody
{chapter} in the centre zone not resolved Tokens_resolveInEveryZone_onEveryPage, EvenMeans_thePhysicalPage_...
rule drawn on the first page only ARuleBelowAHeader_isDrawnOnEveryPage_..., ARuleAboveAFooter_liesOnTheBandsTopEdge_...
collisions overprinted (no limit on a zone's width) Zones_neverOverprint_..., ACentreNextToALogo_..., ALongCentre_yieldsToTheRightZone_...
zone fit ignores word boundaries ALabelAndANumber_inTwoRuns_..., ALiteralSpaceAfterAToken_..., ALongCentre_..., ARunBoundaryWithNoSpace_... and others
token value cuttable, or spaces inside a token are boundaries ATokenAtARunBoundary_..., AChapterTitle_isNotCutAtASpaceInsideIt_..., AZoneCutAcrossRuns_...
a run boundary counts as a boundary ARunBoundaryWithNoSpace_inAZoneWithNoSpace_cutsInsideTheRunAndNotAtTheBoundary
a zone's width not accumulated (a second run overprints) ASecondRunThatOverflows_..., Zones_neverOverprint_... (zones of one to three runs) and 13 more
a zero-width zone gets no place AZoneThatMeasuresZero_standsAtItsSidesEdge_insideTheContentBox
undefined Standard14, unpaired surrogate, tiny font size accepted AZone_refusesAStandard14Value..., AZone_refusesAnUnpairedSurrogate_inAnyFont, AZone_refusesAFontSizeThatIsWrittenAsZero
text box ignores the rule, its clearance, or the descent or ascent ALogoBesideARule_..., ARuleThatTheHeightCannotHold_..., the exact-baseline tests, the oracle fixture
logo ignores the rule ALogoBesideARule_..., the oracle fixture
left-logo and centre-logo gap unchecked ALogoLeftAndALogoAtTheCentre_keepTheGap_atItsBoundary
string band's rule outside the artifact (tagged) AStringBandsRule_isInsideTheArtifactMarkedContent_ofATaggedDocument
the warning always names page 1 ATruncationWarning_namesThePageThatLostTheMost, ALabelAndANumber_...
no rule on a page where nothing else is drawn ARule_isDrawnOnEveryPage_whereTheZonesDrawNothing

Gates

Release build 0 warnings; Layout.Tests Release on net10.0 and net11.0, 4,386 tests each, 0 failed, 2 skipped
each (the named-pipe tests, which skip on Windows); dotnet format --verify-no-changes; clean-room check;
generate-roadmap.py --check. Oracles were required (REQUIRE_ORACLES=1, REQUIRE_VERAPDF=1, veraPDF 1.30.4,
qpdf 12.4.2).

Not in this change

Per-section bands (#286) and /Subtype /Header|/Footer|/PageNum artifact property lists (#303).

…ogo and a rule

A book-style header or footer puts a title, a chapter and a page number on one
line. RunningBand takes three BandZone values, each holding styled runs or a
logo. Tokens resolve through the existing band template scan. Zones that would
overlap are cut by priority and reported as a string band's cut is; MirrorZones
swaps the sides on even physical pages; BandRule draws a line along an edge.
A string band saves the same bytes as before.
… refuse at build

A zone of two runs is cut over its whole text at the last literal space that
fits, and a page number, count or chapter title is drawn whole or not at all.
A zone that measures zero width still has its side's place. The text box is
the fonts' ascent plus descent, centred in what the rule leaves, and the rule
keeps one point clear of it and of the logo. A Standard14 value the enumeration
does not name, an unpaired surrogate and a size written as zero are refused
when the zone is built.
…, pin the cut and the boxes

Runs of a zoned band that together pass int.MaxValue characters on a page now
throw InvalidOperationException naming the band, where the report cast threw
OverflowException. The default height reads the largest leading once. The docs
say the rule's clearance holds for a font's own bounding box and not for a
viewer's substitute for a Standard 14 face, name the two exclusions of the cut,
and refer to #470. Tests pin the 14 AFM boxes, the head box of an embedded
font, a leading space, a run of spaces and a cut between surrogate halves.
… its widths

The comment named the project whose resource files the values were read from.
The tree cites the Adobe Core-14 AFM files themselves for the Standard 14
widths, so the bounding-box rows now say the same. The values are unchanged.
The changelog paragraph had a 135-character line, and it said twice that a
logo is shortened by the rule. The cut remarks had a broken line. Wording
and code are otherwise unchanged.
@Tim81
Tim81 merged commit 33d423a into main Nov 28, 2026
4 checks passed
@Tim81
Tim81 deleted the feat/layout-band-zones branch November 28, 2026 15:43
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.

Layout: headers and footers can only contain a single string

1 participant