Read IDML cell options from shared model

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 05:47:08 -05:00
1 parent 6801ab6aa8
commit 3bfe3fdcff
3 files changed
+37 -39

No files matched your search

Generated
+23 -23
View File
@@ -1242,20 +1242,20 @@ dependencies = [
[[package]]
name = "craft-idml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=06287eae1#06287eae100ad7fa9879e521750c795dd2346791"
source = "git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558#eed3c28cf016723d004d6f2c79c61424c15d4558"
dependencies = [
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=06287eae1)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=06287eae1)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)",
"thiserror 2.0.21",
]
[[package]]
name = "craft-idml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558#eed3c28cf016723d004d6f2c79c61424c15d4558"
source = "git+https://github.com/storytold/craft-libs?rev=fd3d9cde6#fd3d9cde6c369fdcf59ae377aa89163df6fcb4de"
dependencies = [
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fd3d9cde6)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fd3d9cde6)",
"thiserror 2.0.21",
]
@@ -1644,15 +1644,6 @@ dependencies = [
"thiserror 2.0.21",
]
[[package]]
name = "craft-xml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=06287eae1#06287eae100ad7fa9879e521750c795dd2346791"
dependencies = [
"quick-xml 0.41.0",
"thiserror 2.0.21",
]
[[package]]
name = "craft-xml"
version = "0.1.0"
@@ -1718,13 +1709,12 @@ dependencies = [
]
[[package]]
name = "craft-zip"
name = "craft-xml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=06287eae1#06287eae100ad7fa9879e521750c795dd2346791"
source = "git+https://github.com/storytold/craft-libs?rev=fd3d9cde6#fd3d9cde6c369fdcf59ae377aa89163df6fcb4de"
dependencies = [
"flate2",
"quick-xml 0.41.0",
"thiserror 2.0.21",
"zip 9.1.1",
]
[[package]]
@@ -1777,6 +1767,16 @@ dependencies = [
"zip 9.1.1",
]
[[package]]
name = "craft-zip"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=fd3d9cde6#fd3d9cde6c369fdcf59ae377aa89163df6fcb4de"
dependencies = [
"flate2",
"thiserror 2.0.21",
"zip 9.1.1",
]
[[package]]
name = "crc32fast"
version = "1.5.3"
@@ -2021,8 +2021,8 @@ 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=06287eae1)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f23b0f33f0d00b157476533a43cbbcfd901aa1f1)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fd3d9cde6)",
"designcraft-color",
"designcraft-compose",
"designcraft-doc",
@@ -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=06287eae1)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fd3d9cde6)",
"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=06287eae1)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fd3d9cde6)",
"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=06287eae1)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fd3d9cde6)",
"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 = "06287eae1", version = "=0.1.0" }
craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "fd3d9cde6", 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 = "06287eae1", version = "=0.1.0" }
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "fd3d9cde6", 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 -14
View File
@@ -150,6 +150,7 @@ impl<'r> Importer<'r> {
let mut regions = Vec::new();
for ce in e.find_all("Cell") {
let model_cell = craft_idml::model::Cell::from_el(&crate::xml::to_craft(ce));
let options = model_cell.options();
let Some((c, r)) = model_cell.position().map(|(c, r)| (c as usize, r as usize)) else {
continue;
};
@@ -167,7 +168,7 @@ impl<'r> Importer<'r> {
cell.style = if cell_style == designcraft_doc::NO_CELL_STYLE { String::new() } else { cell_style };
let default_para = cell.text.paras.first().cloned().unwrap_or_default();
cell.text = self.story_with_para(StoryId(0), ce, default_para);
self.read_cell_attrs(&mut cell, ce, border_unset);
self.read_cell_attrs(&mut cell, ce, &options, border_unset);
if let Some(slot) = t.cell_mut(r, c) {
*slot = cell;
}
@@ -182,31 +183,28 @@ impl<'r> Importer<'r> {
}
/// A cell's local fill, insets, alignment, rotation and edge strokes.
fn read_cell_attrs(&mut self, cell: &mut designcraft_doc::Cell, ce: &El, border_unset: bool) {
if let Some(fc) = ce.get("FillColor") {
fn read_cell_attrs(&mut self, cell: &mut designcraft_doc::Cell, ce: &El, options: &craft_idml::model::CellOptions, border_unset: bool) {
if let Some(fc) = options.fill_color.as_deref() {
cell.fill = self.swatch_ref(fc);
}
if let Some(tint) = tint(ce.num("FillTint")) {
if let Some(tint) = tint(options.fill_tint) {
cell.fill_tint = tint;
}
// Current InDesign writes `TextTopInset` and so on; the older `TopInset` names are the fallback.
let inset_names =
[("TextTopInset", "TopInset"), ("TextLeftInset", "LeftInset"), ("TextBottomInset", "BottomInset"), ("TextRightInset", "RightInset")];
for (i, (text, old)) in inset_names.iter().enumerate() {
if let Some(v) = ce.num(text).or_else(|| ce.num(old)) {
for (i, inset) in options.insets.iter().enumerate() {
if let Some(v) = inset {
cell.insets[i] = v.max(0.0);
}
}
if let Some(vj) = ce.get("VerticalJustification") {
if let Some(vj) = options.vertical_justification.as_deref() {
cell.vj = names::vj_in(vj);
}
if let Some(fb) = ce.get("FirstBaselineOffset") {
if let Some(fb) = options.first_baseline_offset.as_deref() {
cell.first_baseline = names::first_baseline_in(fb);
}
if let Some(min) = ce.num("MinimumFirstBaselineOffset").filter(|v| v.is_finite()) {
if let Some(min) = options.minimum_first_baseline_offset {
cell.first_baseline_min = min.clamp(0.0, 8640.0);
}
cell.rotation = ce.num("RotationAngle").unwrap_or(cell.rotation);
cell.rotation = options.rotation_angle.unwrap_or(cell.rotation);
if cell.rotation != 0.0 {
self.rotated_cells += 1;
}
@@ -214,7 +212,7 @@ impl<'r> Importer<'r> {
let attrs = self.cell_stroke_attrs(ce, side);
attrs.apply_to(&mut cell.strokes[i]);
cell.stroke_defined[i] |= !attrs.is_empty();
let priority = ce.prop(&format!("{side}StrokePriority")).and_then(|v| v.trim().parse::<i32>().ok()).unwrap_or(0);
let priority = options.edge_stroke_priorities[i];
cell.stroke_priorities[i] = priority;
// Preserve style-defined edges and #102's positive-priority local overrides.
cell.border_overrides[i] |= priority > 0;