feat(docx): give a word document the page it was written on - #676
Merged
Conversation
A docx carried no page layout at all: `text_root_page_layout` returned an empty struct, so with page margins turned on the renderer drew a box that hugged the text instead of a sheet of paper. Read `w:sectPr` — `w:pgSz` for the size and orientation, `w:pgMar` for the margins. The first section properties in document order win: the body's own describe the *last* section, while the first are the ones the document opens with, and for a single-section document the two are the same. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nk1S12YmjBsmksSJ4tVB3X
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nk1S12YmjBsmksSJ4tVB3X
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.
🤖 Generated with Claude Code
A docx carried no page layout at all —
text_root_page_layoutreturned an emptystruct, and nothing in the tree read
w:sectPr. Withtext_document_marginon,the renderer drew a page box that hugged the text: no page size, no margins, a
white rectangle the width of the longest line. Every other paginated format
already had one (odt/odp/odg off the master page, pptx off
p:sldSz, .ppt offthe
DocumentAtom, pdf off theMediaBox).Documentnow reads the section properties in its constructor, the way the pptxDocumentcomputes its slide layout:w:pgSzfor size and orientation,w:pgMarfor the margins. A negative
w:top/w:bottom— the signed form that lets a headerflow into the body — clamps to zero, since as a CSS margin it would push the text
off the page.
Which
w:sectPr. The first in document order. The model carries one layoutper text root while Word carries one per section, and
w:body/w:sectPrdescribesthe last section — a section is closed by the
w:pPr/w:sectProf its finalparagraph. The first one is therefore the page the document opens with, and for
the single-section documents that are the norm the two coincide.
sample3.docxhas two sections with different bottom margins, so the new test pins the choice.
Reference output moves for the 24 docx documents and nothing else; each diff is
those two lines.
README.mdclaimed "page layout (via master page)" — docx has no master pagesand it was never implemented.
.dochas the same gap and keeps it: sectionproperties there mean
PlcfSed→Sepx, real work in a module that does visibletext only, so it is written down in
oldms/text/AGENTS.mdinstead.