feat: a section numbers its pages in its own format

A roman front matter before a decimal body is one page style before another
in ODF and one w:pgNumType per section in Word, not a document setting — read
as one, its pages printed 1, 3 where the reference prints i, iii. HfSet grows
pageNumberFormat, both exports write it back, and the DOCX importer takes the
document's own format from the first section, as it already does the paper.
This commit is contained in:
Steffen Becker committed 2026-09-04 19:30:05 +02:00
1 parent ad12231bf0
commit 862ba22df2
8 files changed
+66 -14

No files matched your search

+7 -1
View File
@@ -2670,11 +2670,17 @@ export async function buildDocx(
},
// w:pgNumType. Word restarts numbering at every section carrying a start, so a
// later section gets one only where it really restarts; the rest continue.
// w:fmt is per section as well, so a roman front matter keeps its own.
...(i === 0
? (pageNumbering.format !== '1' || pageNumbering.start !== 1
? { pageNumbers: { formatType: DOCX_PAGE_NUM_FORMAT[pageNumbering.format], ...(pageNumbering.start !== 1 ? { start: pageNumbering.start } : {}) } }
: {})
: (s.pageNumberStart != null ? { pageNumbers: { start: s.pageNumberStart } } : {})),
: (s.pageNumberStart != null || s.pageNumberFormat
? { pageNumbers: {
...(s.pageNumberFormat ? { formatType: DOCX_PAGE_NUM_FORMAT[s.pageNumberFormat] } : {}),
...(s.pageNumberStart != null ? { start: s.pageNumberStart } : {}),
} }
: {})),
};
};
// Fresh instances per section (Word's per-sectPr references, i.e. no "Link to
+8 -1
View File
@@ -5436,7 +5436,8 @@ function applySectionMasterPages(odtBytes: Uint8Array, sets: HfSet[], pageCount:
const layoutFor = (index: number, set: HfSet): string => {
const m = set.margins;
const paper = set.format || set.orientation ? pageDimsCm(set.format ?? format, set.orientation ?? orientation) : null;
if ((!m && !paper) || !layoutXml) return layout;
const numFormat = set.pageNumberFormat ?? null;
if ((!m && !paper && !numFormat) || !layoutXml) return layout;
const name = `${layout}Sec${index + 1}`;
layouts.push(layoutXml
.replace(`style:name="${layout}"`, `style:name="${name}"`)
@@ -5455,6 +5456,12 @@ function applySectionMasterPages(odtBytes: Uint8Array, sets: HfSet[], pageCount:
.replace(/fo:page-height="[^"]*"/, `fo:page-height="${round3(paper.h)}cm"`)
.replace(/style:print-orientation="[^"]*"/, `style:print-orientation="${paper.w > paper.h ? 'landscape' : 'portrait'}"`);
}
// The page-number format rides the layout, which is where LibreOffice keeps it.
if (numFormat) {
p = /style:num-format="/.test(p)
? p.replace(/style:num-format="[^"]*"/, `style:num-format="${numFormat}"`)
: p.replace('<style:page-layout-properties ', `<style:page-layout-properties style:num-format="${numFormat}" `);
}
return p;
}));
return name;