Use shared IDML cell style values

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 08:49:14 -05:00
1 parent 9ea7beb6f3
commit 862c052c2f
3 files changed
+24 -24

No files matched your search

Generated
+10 -10
View File
@@ -1242,10 +1242,10 @@ dependencies = [
[[package]]
name = "craft-idml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=2e24de528#2e24de528e46c5f680c6e64bb9ac277ccf44032e"
source = "git+https://github.com/storytold/craft-libs?rev=796d4a94c#796d4a94c925ab1412fffaeb41b29b67024ad6f2"
dependencies = [
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2e24de528)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2e24de528)",
"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)",
"thiserror 2.0.21",
]
@@ -1647,7 +1647,7 @@ dependencies = [
[[package]]
name = "craft-xml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=2e24de528#2e24de528e46c5f680c6e64bb9ac277ccf44032e"
source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f"
dependencies = [
"quick-xml 0.41.0",
"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=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f"
source = "git+https://github.com/storytold/craft-libs?rev=796d4a94c#796d4a94c925ab1412fffaeb41b29b67024ad6f2"
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=2e24de528#2e24de528e46c5f680c6e64bb9ac277ccf44032e"
source = "git+https://github.com/storytold/craft-libs?rev=796d4a94c#796d4a94c925ab1412fffaeb41b29b67024ad6f2"
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=2e24de528)",
"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=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=2e24de528)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=796d4a94c)",
"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=2e24de528)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=796d4a94c)",
"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=2e24de528)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=796d4a94c)",
"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 = "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 = "2e24de528", version = "=0.1.0" }
craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "796d4a94c", 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 = "2e24de528", version = "=0.1.0" }
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "796d4a94c", 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" }
+12 -12
View File
@@ -100,34 +100,34 @@ impl<'r> Importer<'r> {
// Keep built-ins as well: [Basic Table] is editable, and [No table style]
// supplies the defaults used by named styles in ordinary IDML files.
for (id, e) in &cell_styles {
self.cell_names.insert(id.clone(), names::style_name_in(names::CELL_BUILTINS, e.get("Name").unwrap_or("")));
let values = craft_idml::model::CellStyleValues::from_el(&crate::xml::to_craft(e));
self.cell_names.insert(id.clone(), names::style_name_in(names::CELL_BUILTINS, values.name.as_deref().unwrap_or("")));
}
for (id, e) in &table_styles {
self.table_names.insert(id.clone(), names::style_name_in(names::TABLE_BUILTINS, e.get("Name").unwrap_or("")));
}
for (_, e) in &cell_styles {
let name = names::style_name_in(names::CELL_BUILTINS, e.get("Name").unwrap_or(""));
let values = craft_idml::model::CellStyleValues::from_el(&crate::xml::to_craft(e));
let name = names::style_name_in(names::CELL_BUILTINS, values.name.as_deref().unwrap_or(""));
let mut cs = designcraft_doc::CellStyle { name: name.clone(), ..Default::default() };
cs.based_on =
e.prop("BasedOn").map(|r| self.cell_style_ref(&r)).or_else(|| Some(designcraft_doc::NO_CELL_STYLE.into())).filter(|n| *n != name);
cs.fill = e.prop("FillColor").map(|c| self.swatch_ref(&c));
cs.fill_tint = tint(e.num("FillTint"));
let inset_names =
[("TextTopInset", "TopInset"), ("TextLeftInset", "LeftInset"), ("TextBottomInset", "BottomInset"), ("TextRightInset", "RightInset")];
cs.inset_overrides = inset_names.map(|(text, old)| e.num(text).or_else(|| e.num(old)).map(|v| v.max(0.0)));
values.based_on.map(|r| self.cell_style_ref(&r)).or_else(|| Some(designcraft_doc::NO_CELL_STYLE.into())).filter(|n| *n != name);
cs.fill = values.fill.as_deref().map(|c| self.swatch_ref(c));
cs.fill_tint = tint(values.fill_tint);
cs.inset_overrides = values.insets;
if let [Some(top), Some(left), Some(bottom), Some(right)] = cs.inset_overrides {
cs.insets = Some([top, left, bottom, right]);
cs.inset_overrides = [None; 4];
}
cs.vj = e.get("VerticalJustification").map(names::vj_in);
cs.first_baseline = e.get("FirstBaselineOffset").map(names::first_baseline_in);
cs.first_baseline_min = e.num("MinimumFirstBaselineOffset").filter(|v| v.is_finite()).map(|v| v.clamp(0.0, 8640.0));
cs.vj = values.vertical_justification.as_deref().map(names::vj_in);
cs.first_baseline = values.first_baseline.as_deref().map(names::first_baseline_in);
cs.first_baseline_min = values.first_baseline_min;
cs.strokes = ["TopEdge", "LeftEdge", "BottomEdge", "RightEdge"].map(|side| self.cell_stroke_attrs(e, side));
if let Some(stroke) = uniform_cell_stroke(&cs.strokes) {
cs.stroke = Some(stroke);
cs.strokes = Default::default();
}
cs.paragraph_style = e.get("AppliedParagraphStyle").map(|r| self.para_style_ref(r)).filter(|n| n != designcraft_doc::NO_PARA_STYLE);
cs.paragraph_style = values.paragraph_style.as_deref().map(|r| self.para_style_ref(r)).filter(|n| n != designcraft_doc::NO_PARA_STYLE);
match self.styles.cell.iter_mut().find(|c| c.name == name) {
Some(slot) => *slot = cs,
None => self.styles.cell.push(cs),