Skip to content

feat(doc-codec): read and write a section's own page size and margins - #915

Merged
Mearman merged 3 commits into
mainfrom
feat/doc-section-page-size-margins
Sep 4, 2026
Merged

feat(doc-codec): read and write a section's own page size and margins#915
Mearman merged 3 commits into
mainfrom
feat/doc-section-page-size-margins

Conversation

@Mearman

@Mearman Mearman commented Sep 4, 2026

Copy link
Copy Markdown
Member

Part of #85.

Reads and writes the one section this package supports' own real page size and margins, via PlcfSed/Sepx and the SEP sprm family (sprmSXaPage, sprmSYaPage, sprmSDxaLeft, sprmSDxaRight, sprmSDyaTop, sprmSDyaBottom) — reusing the same format-generic Prl/grpprl walker already built for paragraph and character sprms, confirmed field-by-field against the MS-DOC FibRgFcLcb97 spec page for fcPlcfSed's own byte offset. A document's whole-document default US Letter placeholder is now only a fallback for a field the file genuinely leaves unstated, not the whole story.

sprmSDyaTop/sprmSDyaBottom's YAS operand has a minimum-margin (positive) and fixed-margin (negative) form; both report the same absolute point size on read, since document-schema.js's Margins has no minimum/fixed distinction. The writer always emits the positive form, matching a real producer's own worked example in the spec.

Verified via this package's own independent reader (write → read → equality, including the negative-YAS case) and against LibreOffice: a non-default 600x800pt page with a 90/54/45/36pt left/right/top/bottom margin round-trips through LibreOffice's own fo:page-width/fo:page-height/fo:margin-* export to the exact point, with no discrepancy.

PlcfSed/Sepx carry a section's own page width/height and left/right/top/bottom
margins as SEP sprms (sprmSXaPage, sprmSYaPage, sprmSDxaLeft, sprmSDxaRight,
sprmSDyaTop, sprmSDyaBottom), reusing the format-generic Prl/grpprl walker
already built for paragraph and character sprms. A field the file leaves
unstated falls back to Word's own new-document default (US Letter, one-inch
margins), exactly as an individual unstated sprm already does elsewhere.

sprmSDyaTop/sprmSDyaBottom's YAS operand has a minimum-margin (positive) and a
fixed-margin (negative) form; both report the same absolute point size, since
document-schema.js's Margins has no minimum/fixed distinction and this reader
has no header/footer geometry to grow a minimum margin against. The writer
always emits the positive form, matching what a real producer's own worked
example does.

writeDocContent now writes a real PlcfSed/Sepx for the one section it
supports, appended after the Chpx/Papx pages in the WordDocument stream (not
itself an FKP-paged structure, so it needs no page alignment) and referenced
from a new Sed in the Table stream.
… forms

Extends test-support/doc.ts's buildDoc with an optional sectionGrpprl,
building a real PlcfSed/Sepx from hand-encoded sprm bytes independently of
the writer under test, the same fixture-independence convention the file's
existing sprm byte constants already follow.

Covers: reading real, non-default page size and margins from a hand-built
Sepx; falling back to Word's own new-document default when a file carries no
PlcfSed at all; reading a fixed (negative YAS) top/bottom margin as the same
absolute size a minimum (positive) one reports; and a full writeDocContent/
readDocContent round trip through non-default page geometry. Adds a
prop/sep.js deep-import smoke entry alongside its prop/chp.js/prop/pap.js
siblings.
…nd written

Adds the read-side page-size/margins bullet and the write-side PlcfSed/Sepx
note, and records LibreOffice verification: a non-default 600x800pt page with
a 90/54/45/36pt left/right/top/bottom margin round-trips through LibreOffice's
own fo:page-width/fo:page-height/fo:margin-* export to the exact point.

Reframes the former "Section properties" scope row as "Section boundaries":
the whole document is still always one section, but that one section's own
page size and margins are no longer a placeholder.
@Mearman
Mearman marked this pull request as ready for review September 4, 2026 13:50
@Mearman
Mearman merged commit 3ab55ac into main Sep 4, 2026
17 checks passed
@Mearman
Mearman deleted the feat/doc-section-page-size-margins branch September 4, 2026 13:51
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review Completed 2026-09-04T14:01:55.099844Z 4cfe00b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant