Skip to content

feat(docx): give a word document the page it was written on - #676

Merged
andiwand merged 2 commits into
mainfrom
feat/docx-page-layout
Aug 9, 2026
Merged

feat(docx): give a word document the page it was written on#676
andiwand merged 2 commits into
mainfrom
feat/docx-page-layout

Conversation

@andiwand

@andiwand andiwand commented Aug 9, 2026

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

A docx carried no page layout at all — text_root_page_layout returned an empty
struct, and nothing in the tree read w:sectPr. With text_document_margin on,
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 off
the DocumentAtom, pdf off the MediaBox).

Document now reads the section properties in its constructor, the way the pptx
Document computes its slide layout: w:pgSz for size and orientation, w:pgMar
for the margins. A negative w:top/w:bottom — the signed form that lets a header
flow 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 layout
per text root while Word carries one per section, and w:body/w:sectPr describes
the last section — a section is closed by the w:pPr/w:sectPr of its final
paragraph. 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.docx
has two sections with different bottom margins, so the new test pins the choice.

odr-page-outer" style="width:8.5in;min-height:11in;"
odr-page-inner" style="margin-right:1in;margin-top:1in;margin-left:1in;margin-bottom:0.5in;"

Reference output moves for the 24 docx documents and nothing else; each diff is
those two lines.

README.md claimed "page layout (via master page)" — docx has no master pages
and it was never implemented. .doc has the same gap and keeps it: section
properties there mean PlcfSedSepx, real work in a module that does visible
text only, so it is written down in oldms/text/AGENTS.md instead.

andiwand and others added 2 commits August 9, 2026 16:28
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
@andiwand
andiwand enabled auto-merge (squash) August 9, 2026 14:32
@andiwand
andiwand merged commit 890c5e6 into main Aug 9, 2026
36 checks passed
@andiwand
andiwand deleted the feat/docx-page-layout branch August 9, 2026 14:44
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.

1 participant