From 4c5d990a078be68091659e01a07b548f355c448f Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 06:56:46 -0500 Subject: [PATCH] Use shared IDML fill values for import --- Cargo.lock | 52 +++++++++++++------------- Cargo.toml | 4 +- crates/idml/src/import/item.rs | 11 ++++-- crates/idml/src/import/object_style.rs | 5 --- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53bfa9b41..5a06edd57 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=56e1735c7#56e1735c70b0f36b454c32a50a56d42f64a5e321" +source = "git+https://github.com/storytold/craft-libs?rev=c205fc236#c205fc2360e4b3498e356a8fb8d763e2e54d7829" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=56e1735c7)", - "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=56e1735c7)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c205fc236)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c205fc236)", "thiserror 2.0.21", ] @@ -1653,15 +1653,6 @@ dependencies = [ "thiserror 2.0.21", ] -[[package]] -name = "craft-xml" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=56e1735c7#56e1735c70b0f36b454c32a50a56d42f64a5e321" -dependencies = [ - "quick-xml 0.41.0", - "thiserror 2.0.21", -] - [[package]] name = "craft-xml" version = "0.1.0" @@ -1680,6 +1671,15 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=c205fc236#c205fc2360e4b3498e356a8fb8d763e2e54d7829" +dependencies = [ + "quick-xml 0.41.0", + "thiserror 2.0.21", +] + [[package]] name = "craft-xml" version = "0.1.0" @@ -1727,16 +1727,6 @@ dependencies = [ "zip 9.1.1", ] -[[package]] -name = "craft-zip" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=56e1735c7#56e1735c70b0f36b454c32a50a56d42f64a5e321" -dependencies = [ - "flate2", - "thiserror 2.0.21", - "zip 9.1.1", -] - [[package]] name = "craft-zip" version = "0.1.0" @@ -1757,6 +1747,16 @@ dependencies = [ "zip 9.1.1", ] +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=c205fc236#c205fc2360e4b3498e356a8fb8d763e2e54d7829" +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=56e1735c7)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c205fc236)", "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=56e1735c7)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c205fc236)", "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=56e1735c7)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c205fc236)", "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=56e1735c7)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c205fc236)", "craft-rtf", "craft-wordmodel", "craft-xlsx", diff --git a/Cargo.toml b/Cargo.toml index eb38d8071..db58b93bc 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 = "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 = "56e1735c7", version = "=0.1.0" } +craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "c205fc236", 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 = "56e1735c7", version = "=0.1.0" } +craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "c205fc236", 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/item.rs b/crates/idml/src/import/item.rs index f3100fff0..0f0570b9e 100644 --- a/crates/idml/src/import/item.rs +++ b/crates/idml/src/import/item.rs @@ -43,13 +43,16 @@ impl<'r> Importer<'r> { .unwrap_or_else(|| designcraft_doc::NO_OBJECT_STYLE.into()); // Fill and stroke. if tag != "Group" { - if let Some(f) = self.attr_or_style(e, "FillColor") { - it.fill.swatch = self.swatch_ref(&f); + let fill_elements = std::iter::once(e).chain(self.object_style_chain(e)).map(crate::xml::to_craft).collect::>(); + let fill_refs: Vec<_> = fill_elements.iter().collect(); + let fill_values = craft_idml::model::FillValues::from_elements(&fill_refs); + if let Some(f) = fill_values.color.as_deref() { + it.fill.swatch = self.swatch_ref(f); } - if let Some(t) = self.attr_or_style(e, "FillTint").and_then(|v| v.parse().ok()) { + if let Some(t) = fill_values.tint { it.fill.tint = tint(Some(t)).unwrap_or(1.0); } - it.fill.overprint = self.attr_or_style(e, "OverprintFill").as_deref() == Some("true"); + it.fill.overprint = fill_values.overprint == Some(true); if let Some(a) = model_item.gradient_fill_angle() && a != 0.0 { diff --git a/crates/idml/src/import/object_style.rs b/crates/idml/src/import/object_style.rs index 477f77c61..25ff994c7 100644 --- a/crates/idml/src/import/object_style.rs +++ b/crates/idml/src/import/object_style.rs @@ -52,11 +52,6 @@ impl<'r> Importer<'r> { chain } - /// Resolve an item attribute, falling back to its object style chain. - pub(super) fn attr_or_style(&self, e: &El, k: &str) -> Option { - e.get(k).or_else(|| self.object_style_chain(e).into_iter().find_map(|s| s.get(k))).map(str::to_string) - } - /// The item's child element `name` laid over the same element of each style in its object style /// chain: attributes and nested elements merge one by one, nearer levels winning. IDML writes on an /// item only the values that differ from its style. Effects whose category the applied style turns