From 8c416b88f27633009c4453ec2cd37b03a76228c9 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Fri, 13 Jun 2025 01:44:12 -0300 Subject: [PATCH] add footer level fields --- crates/typst-library/src/layout/grid/mod.rs | 10 ++++++++++ crates/typst-library/src/layout/grid/resolve.rs | 10 ++++++---- crates/typst-library/src/model/table.rs | 10 ++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/crates/typst-library/src/layout/grid/mod.rs b/crates/typst-library/src/layout/grid/mod.rs index 52621c647..589799e52 100644 --- a/crates/typst-library/src/layout/grid/mod.rs +++ b/crates/typst-library/src/layout/grid/mod.rs @@ -496,6 +496,16 @@ pub struct GridFooter { #[default(true)] pub repeat: bool, + /// The level of the footer. Must not be zero. + /// + /// This allows repeating multiple footers at once. Footers with different + /// levels can repeat together, as long as they have descending levels. + /// + /// Notably, when a footer with a lower level stops repeating, all higher + /// or equal level headers start repeating, replacing the previous footer. + #[default(NonZeroU32::ONE)] + pub level: NonZeroU32, + /// The cells and lines within the footer. #[variadic] pub children: Vec, diff --git a/crates/typst-library/src/layout/grid/resolve.rs b/crates/typst-library/src/layout/grid/resolve.rs index fc1d13564..c51db2d1e 100644 --- a/crates/typst-library/src/layout/grid/resolve.rs +++ b/crates/typst-library/src/layout/grid/resolve.rs @@ -54,6 +54,7 @@ pub fn grid_to_cellgrid<'a>( }, GridChild::Footer(footer) => ResolvableGridChild::Footer { repeat: footer.repeat(styles), + level: footer.level(styles), span: footer.span(), items: footer.children.iter().map(resolve_item), }, @@ -108,6 +109,7 @@ pub fn table_to_cellgrid<'a>( }, TableChild::Footer(footer) => ResolvableGridChild::Footer { repeat: footer.repeat(styles), + level: footer.level(styles), span: footer.span(), items: footer.children.iter().map(resolve_item), }, @@ -647,7 +649,7 @@ impl<'a> Entry<'a> { /// Any grid child, which can be either a header or an item. pub enum ResolvableGridChild { Header { repeat: bool, level: NonZeroU32, span: Span, items: I }, - Footer { repeat: bool, span: Span, items: I }, + Footer { repeat: bool, level: NonZeroU32, span: Span, items: I }, Item(ResolvableGridItem), } @@ -1213,7 +1215,7 @@ impl<'x> CellGridResolver<'_, '_, 'x> { let mut first_available_row = 0; let (header_footer_items, simple_item) = match child { - ResolvableGridChild::Header { repeat, level, span, items, .. } => { + ResolvableGridChild::Header { repeat, level, span, items } => { row_group_data = Some(RowGroupData { range: None, span, @@ -1240,13 +1242,13 @@ impl<'x> CellGridResolver<'_, '_, 'x> { (Some(items), None) } - ResolvableGridChild::Footer { repeat, span, items, .. } => { + ResolvableGridChild::Footer { repeat, level, span, items } => { row_group_data = Some(RowGroupData { range: None, span, repeat, kind: RowGroupKind::Footer, - repeatable_level: NonZeroU32::ONE, + repeatable_level: level, top_hlines_start: pending_hlines.len(), top_hlines_end: None, }); diff --git a/crates/typst-library/src/model/table.rs b/crates/typst-library/src/model/table.rs index 0b905bd5f..685f78aeb 100644 --- a/crates/typst-library/src/model/table.rs +++ b/crates/typst-library/src/model/table.rs @@ -590,6 +590,16 @@ pub struct TableFooter { #[default(true)] pub repeat: bool, + /// The level of the footer. Must not be zero. + /// + /// This allows repeating multiple footers at once. Footers with different + /// levels can repeat together, as long as they have descending levels. + /// + /// Notably, when a footer with a lower level stops repeating, all higher + /// or equal level headers start repeating, replacing the previous footer. + #[default(NonZeroU32::ONE)] + pub level: NonZeroU32, + /// The cells and lines within the footer. #[variadic] pub children: Vec,