fix: read OOXML toggles as ST_OnOff, not as element presence

w:evenAndOddHeaders, w:titlePg and w:pageBreakBefore were treated as on
whenever the element existed, but w:val="false"/"0"/"off" turns them off
and both Word and the docx lib write that explicit form.

A file with <w:evenAndOddHeaders w:val="false"/> therefore took the
even-page header variant on every second page, which is empty — the
header and footer vanished from page 2 onwards.
This commit is contained in:
Steffen Becker committed 2026-08-06 19:53:47 +00:00
1 parent f48e5508a8
commit 3a68a144cb
2 files changed
+58 -3

No files matched your search

+5 -3
View File
@@ -776,7 +776,7 @@ function blockAttrs(ppr: Element | null, kind: BlockKind, headingLevel: number |
if (kind === 'body') {
const pb = fc(ppr, 'pageBreakBefore');
if (pb && wVal(pb) !== 'false' && wVal(pb) !== '0') attrs.breakBefore = 'page';
if (pb && onOff(pb)) attrs.breakBefore = 'page';
}
// Paragraph background ("colored field", w:shd) + per-side borders ("rule line", w:pBdr).
@@ -1461,7 +1461,8 @@ function docHasEvenOddHeaders(files: Record<string, Uint8Array>): boolean {
const bytes = files['word/settings.xml'];
if (!bytes) return false;
try {
return !!parseXml(strFromU8(bytes)).getElementsByTagNameNS(W, 'evenAndOddHeaders')[0];
const el = parseXml(strFromU8(bytes)).getElementsByTagNameNS(W, 'evenAndOddHeaders')[0];
return !!el && onOff(el);
} catch {
return false;
}
@@ -1489,7 +1490,8 @@ function parseSectPr(sect: Element | null, ctx: Ctx, oddEven = false): {
: null;
// Different first page: w:titlePg turns on the "first"-type refs for page 1.
const titlePg = !!fc(sect, 'titlePg');
const titlePgEl = fc(sect, 'titlePg');
const titlePg = !!titlePgEl && onOff(titlePgEl);
const refId = (type: string, variant: 'default' | 'first' | 'even' = 'default') => {
const ref = fcAll(sect, `${type}Reference`).find((r) => (r.getAttributeNS(W, 'type') ?? 'default') === variant);
return ref?.getAttributeNS(R, 'id') ?? null;