Read IDML table options through shared model

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 05:52:52 -05:00
1 parent 00f16cee6b
commit a15eca46c4
4 files changed
+41 -39

No files matched your search

Generated
+26 -26
View File
@@ -1242,10 +1242,10 @@ dependencies = [
[[package]]
name = "craft-idml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=cda7d1338#cda7d13387abb9cbefab887fb57dd4910bfff70c"
source = "git+https://github.com/storytold/craft-libs?rev=1e7f088b8#1e7f088b80670ad9ec6a2a3a714d40ded01f8c01"
dependencies = [
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cda7d1338)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cda7d1338)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=1e7f088b8)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=1e7f088b8)",
"thiserror 2.0.21",
]
@@ -1644,6 +1644,15 @@ dependencies = [
"thiserror 2.0.21",
]
[[package]]
name = "craft-xml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=1e7f088b8#1e7f088b80670ad9ec6a2a3a714d40ded01f8c01"
dependencies = [
"quick-xml 0.41.0",
"thiserror 2.0.21",
]
[[package]]
name = "craft-xml"
version = "0.1.0"
@@ -1680,15 +1689,6 @@ dependencies = [
"thiserror 2.0.21",
]
[[package]]
name = "craft-xml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=cda7d1338#cda7d13387abb9cbefab887fb57dd4910bfff70c"
dependencies = [
"quick-xml 0.41.0",
"thiserror 2.0.21",
]
[[package]]
name = "craft-xml"
version = "0.1.0"
@@ -1727,6 +1727,16 @@ dependencies = [
"zip 9.1.1",
]
[[package]]
name = "craft-zip"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=1e7f088b8#1e7f088b80670ad9ec6a2a3a714d40ded01f8c01"
dependencies = [
"flate2",
"thiserror 2.0.21",
"zip 9.1.1",
]
[[package]]
name = "craft-zip"
version = "0.1.0"
@@ -1747,16 +1757,6 @@ dependencies = [
"zip 9.1.1",
]
[[package]]
name = "craft-zip"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=cda7d1338#cda7d13387abb9cbefab887fb57dd4910bfff70c"
dependencies = [
"flate2",
"thiserror 2.0.21",
"zip 9.1.1",
]
[[package]]
name = "craft-zip"
version = "0.1.0"
@@ -2021,7 +2021,7 @@ dependencies = [
"craft-prepress",
"craft-print",
"craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cda7d1338)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=1e7f088b8)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f23b0f33f0d00b157476533a43cbbcfd901aa1f1)",
"designcraft-color",
"designcraft-compose",
@@ -2103,9 +2103,9 @@ name = "designcraft-idml"
version = "0.20.1"
dependencies = [
"craft-file-formats",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cda7d1338)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=1e7f088b8)",
"craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cda7d1338)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=1e7f088b8)",
"designcraft-color",
"designcraft-compose",
"designcraft-doc",
@@ -2222,7 +2222,7 @@ version = "0.20.1"
dependencies = [
"craft-docx",
"craft-file-formats",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cda7d1338)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=1e7f088b8)",
"craft-rtf",
"craft-wordmodel",
"craft-xlsx",
+2 -2
View File
@@ -16,10 +16,10 @@ craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "4052591363
craft-designcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "19692b6190465671e41967c75d0cd4c439d0c84c", version = "=0.1.0" }
craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" }
craft-epub = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" }
craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "cda7d1338", version = "=0.1.0" }
craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "1e7f088b8", version = "=0.1.0" }
craft-indd = { git = "https://github.com/storytold/craft-libs", rev = "47bf5650b0d503b97bfb5e841746c4957897d11f", version = "=0.1.0" }
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "cc23ffd4d26f3074808e2187d332564817624f8f", version = "=0.1.0", features = ["tree-render", "tree-text"] }
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "cda7d1338", version = "=0.1.0" }
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "1e7f088b8", version = "=0.1.0" }
craft-xml-dtd = { package = "craft-xml", git = "https://github.com/storytold/craft-libs", rev = "f23b0f33f0d00b157476533a43cbbcfd901aa1f1", version = "=0.1.0" }
craft-rtf = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" }
craft-xlsx = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" }
+1 -1
View File
@@ -358,7 +358,7 @@ impl<'r> Importer<'r> {
self.map_stroke_values(values)
}
fn map_stroke_values(&mut self, values: craft_idml::model::StrokeValues) -> designcraft_doc::CellStrokeAttrs {
pub(super) fn map_stroke_values(&mut self, values: craft_idml::model::StrokeValues) -> designcraft_doc::CellStrokeAttrs {
designcraft_doc::CellStrokeAttrs {
weight: values.weight,
color: values.color.map(|v| self.swatch_ref(&v)),
+12 -10
View File
@@ -55,6 +55,7 @@ pub(super) fn uniform_cell_stroke(edges: &[designcraft_doc::CellStrokeAttrs; 4])
impl<'r> Importer<'r> {
/// `<Table>`: rows, columns and cells (cell `Name` is `column:row`).
pub(super) fn table(&mut self, e: &El) -> Option<Table> {
let table_options = craft_idml::model::Values::of(&crate::xml::to_craft(e)).table_options();
let rows: Vec<&El> = e.find_all("Row").collect();
let cols: Vec<&El> = e.find_all("Column").collect();
// A file's row and column counts are its claim, and a table of them is allocated whole: a
@@ -93,7 +94,7 @@ impl<'r> Importer<'r> {
let rows = &rows[..nr.min(rows.len())];
let cols = &cols[..nc.min(cols.len())];
let mut t = Table::new(id, nr, nc, 0, 0, 0.0);
t.options.direction = if e.get("TableDirection") == Some("RightToLeftDirection") {
t.options.direction = if table_options.direction.as_deref() == Some("RightToLeftDirection") {
designcraft_doc::TextDirection::RightToLeft
} else {
designcraft_doc::TextDirection::LeftToRight
@@ -106,12 +107,13 @@ impl<'r> Importer<'r> {
for (c, ce) in cols.iter().enumerate() {
t.columns[c].width = ce.num("SingleColumnWidth").unwrap_or(72.0).max(3.0);
}
let h = e.num("HeaderRowCount").unwrap_or(0.0) as usize;
let f = e.num("FooterRowCount").unwrap_or(0.0) as usize;
let h = table_options.header_rows.unwrap_or(0.0) as usize;
let f = table_options.footer_rows.unwrap_or(0.0) as usize;
if h.saturating_add(f) < nr {
t.set_header_footer(h, f);
}
let style_name = e.get("AppliedTableStyle").map(|r| self.table_style_ref(r)).unwrap_or_else(|| designcraft_doc::BASIC_TABLE.into());
let style_name =
table_options.applied_style.as_deref().map(|r| self.table_style_ref(r)).unwrap_or_else(|| designcraft_doc::BASIC_TABLE.into());
let style = self.styles.resolve_table_style(&style_name);
style.apply_to(&mut t, &self.styles.cell);
// IDML distinguishes an explicit AppliedCellStyle from the effective region style.
@@ -122,17 +124,17 @@ impl<'r> Importer<'r> {
// materialized independently, so their edges retain their higher precedence.
let mut border_unset = style.border.is_none() && style.borders.iter().all(|b| b.is_empty());
let mut borders = std::array::from_fn::<_, 4, _>(|i| t.options.border_for(i).clone());
for (side, border) in ["TopBorder", "LeftBorder", "BottomBorder", "RightBorder"].iter().zip(&mut borders) {
let attrs = self.cell_stroke_attrs(e, side);
for (attrs, border) in table_options.borders.into_iter().zip(&mut borders) {
let attrs = self.map_stroke_values(attrs);
border_unset &= attrs.is_empty();
attrs.apply_to(border);
}
t.options.border = borders[0].clone();
t.options.borders = borders.map(Some);
t.options.space_before = e.num("SpaceBefore").unwrap_or(t.options.space_before);
t.options.space_after = e.num("SpaceAfter").unwrap_or(t.options.space_after);
t.options.repeat_header = e.get("HeaderBehavior") != Some("RepeatOnce");
t.options.repeat_footer = e.get("FooterBehavior") != Some("RepeatOnce");
t.options.space_before = table_options.space_before.unwrap_or(t.options.space_before);
t.options.space_after = table_options.space_after.unwrap_or(t.options.space_after);
t.options.repeat_header = table_options.repeat_header;
t.options.repeat_footer = table_options.repeat_footer;
// A local count may enable a pattern disabled by its parent style. Merge before
// materialization so the parent's colors/tints are still available in that case.
let mut row_fills = style.row_fills.clone();