@@ -189,36 +189,6 @@ function collectReferencedRIdsBySection(effectiveRefsBySection: Map<number, Head
189189 return result ;
190190}
191191
192- /**
193- * Resolve the default header/footer rId for each section.
194- *
195- * Multi-section layout has historically measured only the default variant with
196- * section-specific constraints. Preserve that behavior to avoid changing
197- * established rendering for documents that use first/even/odd variants.
198- */
199- function resolveDefaultRIdPerSection (
200- sectionMetadata : SectionMetadata [ ] ,
201- kind : 'header' | 'footer' ,
202- ) : Map < number , string > {
203- const result = new Map < number , string > ( ) ;
204- let inheritedDefaultRId : string | undefined ;
205-
206- for ( const section of sectionMetadata ) {
207- const refs = getRefsForKind ( section , kind ) ;
208- const explicitDefaultRId = refs ?. default ;
209-
210- if ( explicitDefaultRId ) {
211- inheritedDefaultRId = explicitDefaultRId ;
212- }
213-
214- if ( inheritedDefaultRId ) {
215- result . set ( section . sectionIndex , inheritedDefaultRId ) ;
216- }
217- }
218-
219- return result ;
220- }
221-
222192/**
223193 * Layout header/footer blocks per rId, respecting per-section margins.
224194 *
@@ -411,7 +381,7 @@ async function layoutWithPerSectionConstraints(
411381) : Promise < void > {
412382 if ( ! blocksByRId ) return ;
413383
414- const defaultRIdPerSection = resolveDefaultRIdPerSection ( sectionMetadata , kind ) ;
384+ const effectiveRefsBySection = buildEffectiveRefsBySection ( sectionMetadata , kind ) ;
415385
416386 // Extract table width specs per rId (SD-1837).
417387 // Word allows tables in headers/footers to extend beyond content margins.
@@ -433,8 +403,12 @@ async function layoutWithPerSectionConstraints(
433403 > ( ) ;
434404
435405 for ( const section of sectionMetadata ) {
436- const rId = defaultRIdPerSection . get ( section . sectionIndex ) ;
437- if ( ! rId || ! blocksByRId . has ( rId ) ) continue ;
406+ const refs = effectiveRefsBySection . get ( section . sectionIndex ) ;
407+ if ( ! refs ) continue ;
408+
409+ for ( const variant of HEADER_FOOTER_VARIANTS ) {
410+ const rId = refs [ variant ] ;
411+ if ( ! rId || ! blocksByRId . has ( rId ) ) continue ;
438412
439413 // Resolve the minimum width needed for tables in this section.
440414 // For pct tables, this depends on the section's content width.
0 commit comments