diff --git a/crates/typst-layout/src/grid/layouter.rs b/crates/typst-layout/src/grid/layouter.rs index d46040910..fd846b6e9 100644 --- a/crates/typst-layout/src/grid/layouter.rs +++ b/crates/typst-layout/src/grid/layouter.rs @@ -298,11 +298,6 @@ impl<'a> GridLayouter<'a> { self.prepare_next_repeating_footers(true, engine)?; - // Ensure rows in the first region will be aware of the possible - // presence of the footer. - self.regions.size.y -= self.current.footer_height; - self.current.initial_after_repeats = self.regions.size.y; - let mut y = 0; let mut consecutive_header_count = 0; while y < self.grid.rows.len() { @@ -1785,13 +1780,6 @@ impl<'a> GridLayouter<'a> { )?; } - // Ensure rows don't try to overrun the footer. - // Note that header layout will only subtract this again if it has - // to skip regions to fit headers, so there is no risk of - // subtracting this twice. - self.regions.size.y -= self.current.footer_height; - self.current.initial_after_repeats = self.regions.size.y; - if !self.repeating_headers.is_empty() || !self.pending_headers.is_empty() { // Add headers to the new region. self.layout_active_headers(engine)?; diff --git a/crates/typst-layout/src/grid/repeated.rs b/crates/typst-layout/src/grid/repeated.rs index 1a8733102..86506df79 100644 --- a/crates/typst-layout/src/grid/repeated.rs +++ b/crates/typst-layout/src/grid/repeated.rs @@ -632,9 +632,18 @@ impl<'a> GridLayouter<'a> { .simulate_footer_heights(footers, &self.regions, engine, disambiguator)?; } + // Ensure rows don't try to overrun the new footers. + // Note that header layout will only subtract this again if it has + // to skip regions to fit headers, so there is no risk of + // subtracting this twice. + self.regions.size.y -= expected_footer_height; self.current.footer_height += expected_footer_height; self.current.repeating_footer_heights.extend(expected_footer_heights); + if at_region_top { + self.current.initial_after_repeats = self.regions.size.y; + } + Ok(()) } diff --git a/tests/ref/grid-subfooters-demo.png b/tests/ref/grid-subfooters-demo.png index dc64e29af..f4a3f1731 100644 Binary files a/tests/ref/grid-subfooters-demo.png and b/tests/ref/grid-subfooters-demo.png differ diff --git a/tests/ref/grid-subfooters-repeat-replace-double-widow.png b/tests/ref/grid-subfooters-repeat-replace-double-widow.png index 86d92a832..37ecbca34 100644 Binary files a/tests/ref/grid-subfooters-repeat-replace-double-widow.png and b/tests/ref/grid-subfooters-repeat-replace-double-widow.png differ diff --git a/tests/ref/grid-subfooters-repeat-replace-gutter.png b/tests/ref/grid-subfooters-repeat-replace-gutter.png index 2ca221533..61bdabeb6 100644 Binary files a/tests/ref/grid-subfooters-repeat-replace-gutter.png and b/tests/ref/grid-subfooters-repeat-replace-gutter.png differ diff --git a/tests/ref/grid-subfooters-repeat-replace-multiple-levels.png b/tests/ref/grid-subfooters-repeat-replace-multiple-levels.png new file mode 100644 index 000000000..6247969a0 Binary files /dev/null and b/tests/ref/grid-subfooters-repeat-replace-multiple-levels.png differ diff --git a/tests/ref/grid-subfooters-repeat-replace-widow.png b/tests/ref/grid-subfooters-repeat-replace-widow.png index 35633b0a4..090ebca36 100644 Binary files a/tests/ref/grid-subfooters-repeat-replace-widow.png and b/tests/ref/grid-subfooters-repeat-replace-widow.png differ diff --git a/tests/ref/grid-subfooters-repeat-replace.png b/tests/ref/grid-subfooters-repeat-replace.png index 0d7803b85..95025f8b3 100644 Binary files a/tests/ref/grid-subfooters-repeat-replace.png and b/tests/ref/grid-subfooters-repeat-replace.png differ