fix(docx): draw a page zone on the pages its predicate picks - #727
Merged
Merged
Conversation
The DOCX export wrote every page zone on every page and only warned about an appliesTo predicate. The predicate is now asked over sample pages and sorted into Word's kinds: a first-page zone becomes the title page's part (w:titlePg), an even- or odd-page zone the even or default part (w:evenAndOddHeaders, document-wide), and pages a zone skips get an empty part. A predicate that picks pages within a kind, or refuses a sample page, is written on every page and reported. A zone's distance from the page edge is measured on any page it is drawn on, so a zone that skips the first page is placed where the layout drew it.
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.
Why
A page zone chooses its pages with
appliesTo(Predicate<PageContext>): a cover-only header, a footer that skips the cover, a running head on even pages. The DOCX export could not evaluate a predicate, so it wrote every such zone on every page and only logged a warning. In Word, the cover header repeated on every page, and the "not on the cover" footer appeared on the cover.Word does not test pages. It has three kinds of header and footer per section:
w:titlePg);w:evenAndOddHeaders);What changed
DocxPageClasses(package-private) asks a zone's predicate about sample pages and sorts the answers into those three kinds.null.DocxSemanticBackend.applyPageZoneswrites each zone into the part of every kind it is drawn on.w:titlePgwhen some zone tells the first page from the rest.w:evenAndOddHeaderswhen some zone tells even pages from odd. That setting is document-wide, so it is decided before any section is written, and every section then states its even pages.docx.zone.pagePredicatewarning and anAPPROXIMATED"page zone" note in the export report. A zone that asks for no page at all is not written.DocxLayoutMetrics.zoneDistanceFromEdgenow measures a zone on any page it is drawn on. Before, it read only the first page. A zone that skips the first page had nothing there and fell back to its padding.titlePg, no settings flag, same bytes. The committedword-export-companion.docxpreview did not move.Verification
In an editor. A three-page document with three zones, converted with LibreOffice:
Both break the text at the same lines.
Gate. Full reactor gate (
clean verifyover core, render-pdf/docx/pptx, templates, testing, qa, coverage) → BUILD SUCCESS. Examples after install: 93 green.extract-api --checkis current: no public API change.New tests.
DocxPageClassesTest(6):isFirst,!isFirst, even and odd page numbers and never are each sorted into the right kinds;isLast, the third page, and the first four pages have no Word equivalent;DocxPageZoneKindsTest(7):titlePg, and the other pages get an empty header;settings.xml, since POI's getter only reports that the element is present) and leaves the default part empty;Sabotaging each fails the matching tests:
titlePg;Changed existing test.
qaDocxPageZoneTest.aPagePredicateCannotBeEvaluatedSoTheZoneLandsEverywhereAndSaysSopinned "every predicate is written on every page". It used!isFirst, which Word now states exactly. It is nowaPagePredicateWordCannotStateLandsEverywhereAndSaysSo, with a last-page predicate, and keeps its point: an inexpressible predicate lands everywhere and is warned about.Lane: shared-engine (render-docx). No public API change.