fix(header-footer): use section-aware page numbering for odd/even parity (SD-2991)#3236
Open
luccas-harbour wants to merge 5 commits into
Open
fix(header-footer): use section-aware page numbering for odd/even parity (SD-2991)#3236luccas-harbour wants to merge 5 commits into
luccas-harbour wants to merge 5 commits into
Conversation
… parity OOXML (ECMA-376 §17.10.1) selects even/odd headers based on the printed page number — which respects per-section numbering restarts and offsets — not the physical page index. Track the post-restart/offset value as `displayNumber` on each page and thread it through pagination, header/footer resolution, and the HeaderFooterSessionManager so a section that starts at page 2 picks the `even` variant on its first page.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Summary
displayNumberso headers respect OOXML<w:pgNumType w:start="…">and per-section number restarts (ECMA-376 §17.10.1).displayNumberfield through the layout pipeline (Page→HeaderFooterPage→ResolvedPage→ResolvedHeaderFooterPage) and stamps it fromactivePageCounterinsidelayoutDocument.parityPageNumberoption to theheaderFooterUtilsselectors (getHeaderFooterType,getHeaderFooterTypeForSection,getHeaderFooterIdForPage,resolveHeaderFooterForPage(AndSection)) so callers can override parity when needed. Also fixes the legacy single-section selector to use% 2 !== 0for odd, so negative display numbers route tooddinstead of falling through.HeaderFooterSessionManagernow readsdisplayNumberwhen picking header/footer variants for both per-rId layouts and inferred region variants.Why
When a section sets
<w:pgNumType w:start="2"/>(or otherwise restarts numbering), Word treats the first body page as page 2 and renders the even header on it. We were keying odd/even off the physical page index instead, so the wrong variant was selected — and downstream space reservation (header content height) used the wrong height, shifting body content vertically.Changes by package
layout-engine/contracts: add optionaldisplayNumberonPage,HeaderFooterPage,ResolvedPage,ResolvedHeaderFooterPage.layout-engine/layout-engine: renamedocumentPageNumber→parityPageNumberingetVariantTypeForPage, feed itactivePageCounter, and stampstate.page.displayNumberduring page creation.layout-engine/layout-bridge: newparityPageNumberoption threaded through every header/footer selector; existing callers default topage.displayNumber ?? page.number. Negative-odd parity now resolves to'odd'.layout-engine/layout-resolved: forwarddisplayNumberfrom layout to resolved page/header-footer outputs.super-editor/HeaderFooterSessionManager: usedisplayNumberfor both region variant inference and per-rId variant lookup; preserve it when forwarding pages into header/footer layout requests.Tests
layout-engine: newuses section page-numbering start for odd/even header paritytest (section withnumbering.start = 2swaps body offsets on pages 1 and 2). Existing alternateHeaders tests updated to describe behavior in terms of display number.layout-bridge/headerFooterUtils: new tests cover theparityPageNumberoverride, negative-odd handling, section-aware display-number parity, and caller-supplied parity overrides.layout-resolved/resolveHeaderFooter: assertsdisplayNumberis preserved through resolution.super-editor/HeaderFooterSessionManager: new tests verifydisplayNumberparity is used both when selecting per-rId header layouts and when inferring region variants.