From 75eeeca16f94acdcc34ebb5e0d6aea6b615c5c4b Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 08:50:49 -0500 Subject: [PATCH] Use shared IDML table style values --- Cargo.lock | 18 +++++++++--------- Cargo.toml | 4 ++-- crates/idml/src/import/styles.rs | 32 +++++++++++++++++--------------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 360c3a5ee..66b6116cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1242,10 +1242,10 @@ dependencies = [ [[package]] name = "craft-idml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=796d4a94c#796d4a94c925ab1412fffaeb41b29b67024ad6f2" +source = "git+https://github.com/storytold/craft-libs?rev=7aca8fe26#7aca8fe26798806266fa09187908e50a614ff303" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=796d4a94c)", - "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=796d4a94c)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7aca8fe26)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7aca8fe26)", "thiserror 2.0.21", ] @@ -1656,7 +1656,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=796d4a94c#796d4a94c925ab1412fffaeb41b29b67024ad6f2" +source = "git+https://github.com/storytold/craft-libs?rev=7aca8fe26#7aca8fe26798806266fa09187908e50a614ff303" dependencies = [ "quick-xml 0.41.0", "thiserror 2.0.21", @@ -1720,7 +1720,7 @@ dependencies = [ [[package]] name = "craft-zip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=796d4a94c#796d4a94c925ab1412fffaeb41b29b67024ad6f2" +source = "git+https://github.com/storytold/craft-libs?rev=7aca8fe26#7aca8fe26798806266fa09187908e50a614ff303" dependencies = [ "flate2", "thiserror 2.0.21", @@ -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=796d4a94c)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7aca8fe26)", "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=796d4a94c)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7aca8fe26)", "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=796d4a94c)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7aca8fe26)", "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=796d4a94c)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7aca8fe26)", "craft-rtf", "craft-wordmodel", "craft-xlsx", diff --git a/Cargo.toml b/Cargo.toml index 7b79b49d8..9cd572e6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = "93d0998383aa150fa50a2ffbf49ef37786e37eca", 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 = "796d4a94c", version = "=0.1.0" } +craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "7aca8fe26", 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 = "796d4a94c", version = "=0.1.0" } +craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "7aca8fe26", 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" } diff --git a/crates/idml/src/import/styles.rs b/crates/idml/src/import/styles.rs index a75079f59..a6d30566f 100644 --- a/crates/idml/src/import/styles.rs +++ b/crates/idml/src/import/styles.rs @@ -134,21 +134,23 @@ impl<'r> Importer<'r> { } } for (_, e) in &table_styles { - let name = names::style_name_in(names::TABLE_BUILTINS, e.get("Name").unwrap_or("")); + let values = craft_idml::model::TableStyleValues::from_el(&crate::xml::to_craft(e)); + let name = names::style_name_in(names::TABLE_BUILTINS, values.name.as_deref().unwrap_or("")); let mut ts = designcraft_doc::TableStyle { name: name.clone(), ..Default::default() }; ts.based_on = - e.prop("BasedOn").map(|r| self.table_style_ref(&r)).or_else(|| Some(designcraft_doc::NO_TABLE_STYLE.into())).filter(|n| *n != name); - ts.header = e.get("HeaderRegionCellStyle").map(|r| if r == "n" { designcraft_doc::NO_CELL_STYLE.into() } else { self.cell_style_ref(r) }); - ts.body = e.get("BodyRegionCellStyle").map(|r| if r == "n" { designcraft_doc::NO_CELL_STYLE.into() } else { self.cell_style_ref(r) }); - ts.footer = e.get("FooterRegionCellStyle").map(|r| if r == "n" { designcraft_doc::NO_CELL_STYLE.into() } else { self.cell_style_ref(r) }); - ts.left_column = - e.get("LeftColumnRegionCellStyle").map(|r| if r == "n" { designcraft_doc::NO_CELL_STYLE.into() } else { self.cell_style_ref(r) }); - ts.right_column = - e.get("RightColumnRegionCellStyle").map(|r| if r == "n" { designcraft_doc::NO_CELL_STYLE.into() } else { self.cell_style_ref(r) }); - ts.header_same_as_body = e.boolean("HeaderRegionSameAsBodyRegion"); - ts.footer_same_as_body = e.boolean("FooterRegionSameAsBodyRegion"); - ts.left_column_same_as_body = e.boolean("LeftColumnRegionSameAsBodyRegion"); - ts.right_column_same_as_body = e.boolean("RightColumnRegionSameAsBodyRegion"); + values.based_on.map(|r| self.table_style_ref(&r)).or_else(|| Some(designcraft_doc::NO_TABLE_STYLE.into())).filter(|n| *n != name); + let cell_ref = |r: Option, importer: &Self| { + r.map(|r| if r == "n" { designcraft_doc::NO_CELL_STYLE.into() } else { importer.cell_style_ref(&r) }) + }; + ts.header = cell_ref(values.header_cell_style, self); + ts.body = cell_ref(values.body_cell_style, self); + ts.footer = cell_ref(values.footer_cell_style, self); + ts.left_column = cell_ref(values.left_column_cell_style, self); + ts.right_column = cell_ref(values.right_column_cell_style, self); + ts.header_same_as_body = values.header_same_as_body; + ts.footer_same_as_body = values.footer_same_as_body; + ts.left_column_same_as_body = values.left_column_same_as_body; + ts.right_column_same_as_body = values.right_column_same_as_body; ts.borders = ["TopBorder", "LeftBorder", "BottomBorder", "RightBorder"].map(|side| self.cell_stroke_attrs(e, side)); if let Some(border) = uniform_cell_stroke(&ts.borders) { ts.border = Some(border); @@ -158,8 +160,8 @@ impl<'r> Importer<'r> { ts.column_fills = self.alt_fill_attrs(e, "Column"); ts.row_strokes = self.alt_stroke_attrs(e, "Row"); ts.column_strokes = self.alt_stroke_attrs(e, "Column"); - ts.space_before = e.num("SpaceBefore"); - ts.space_after = e.num("SpaceAfter"); + ts.space_before = values.space_before; + ts.space_after = values.space_after; match self.styles.table.iter_mut().find(|c| c.name == name) { Some(slot) => *slot = ts, None => self.styles.table.push(ts),