diff --git a/crates/idml/src/model/mod.rs b/crates/idml/src/model/mod.rs index bfca5923b..f79155b50 100644 --- a/crates/idml/src/model/mod.rs +++ b/crates/idml/src/model/mod.rs @@ -27,7 +27,10 @@ pub use spread::{ Graphic, GraphicChild, GraphicKind, Guide, ItemChild, ItemKind, Link, MarginPreference, Page, PageChild, PageItem, Spread, SpreadChild, TextPath, spreads, }; -pub use story::{Ace, CONTAINERS, Cell, CellOptions, Container, ContentPart, Range, Story, StoryPreference, Table, TableChild, TextNode, stories}; +pub use story::{ + Ace, CONTAINERS, Cell, CellOptions, Container, ContentPart, Range, Story, StoryPreference, Table, TableChild, TableColumn, TableLayout, TableRow, + TextNode, stories, +}; use crate::value::{matrix, nums}; diff --git a/crates/idml/src/model/story.rs b/crates/idml/src/model/story.rs index c8fa0d446..136b58455 100644 --- a/crates/idml/src/model/story.rs +++ b/crates/idml/src/model/story.rs @@ -135,6 +135,57 @@ pub struct Table { pub children: Vec, } +/// The row and column grid of an IDML table, read without allocating cell models. +#[derive(Clone, Debug, Default, PartialEq)] +pub struct TableLayout { + pub rows: Vec, + pub columns: Vec, +} + +#[derive(Clone, Debug, Default, PartialEq)] +pub struct TableRow { + pub values: Values, +} + +#[derive(Clone, Debug, Default, PartialEq)] +pub struct TableColumn { + pub values: Values, +} + +impl TableLayout { + pub fn from_el(el: &El) -> TableLayout { + let mut layout = TableLayout::default(); + for child in el.elements() { + match child.local() { + "Row" => layout.rows.push(TableRow { values: Values::of(child) }), + "Column" => layout.columns.push(TableColumn { values: Values::of(child) }), + _ => {} + } + } + layout + } +} + +impl TableRow { + pub fn auto_grow(&self) -> Option { + self.values.boolean("AutoGrow") + } + + pub fn minimum_height(&self) -> Option { + self.values.num("MinimumHeight") + } + + pub fn single_row_height(&self) -> Option { + self.values.num("SingleRowHeight") + } +} + +impl TableColumn { + pub fn single_column_width(&self) -> Option { + self.values.num("SingleColumnWidth") + } +} + /// A child of a table, in document order. #[derive(Clone, Debug, PartialEq)] pub enum TableChild {