Read table cells through shared IDML model

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 07:02:41 -05:00
1 parent aad973279a
commit 75d1b844f3
3 files changed
+25 -23

No files matched your search

Generated
+11 -11
View File
@@ -1242,10 +1242,10 @@ dependencies = [
[[package]]
name = "craft-idml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=a4432f087#a4432f08707fca90bf53128011c5dde0d87a2dfd"
source = "git+https://github.com/storytold/craft-libs?rev=8345921af#8345921aff971504d55cc202b93d2ca6aa5932de"
dependencies = [
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a4432f087)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a4432f087)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=8345921af)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=8345921af)",
"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=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551"
source = "git+https://github.com/storytold/craft-libs?rev=8345921af#8345921aff971504d55cc202b93d2ca6aa5932de"
dependencies = [
"quick-xml 0.41.0",
"thiserror 2.0.21",
@@ -1665,7 +1665,7 @@ dependencies = [
[[package]]
name = "craft-xml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=a4432f087#a4432f08707fca90bf53128011c5dde0d87a2dfd"
source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551"
dependencies = [
"quick-xml 0.41.0",
"thiserror 2.0.21",
@@ -1730,7 +1730,7 @@ dependencies = [
[[package]]
name = "craft-zip"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551"
source = "git+https://github.com/storytold/craft-libs?rev=8345921af#8345921aff971504d55cc202b93d2ca6aa5932de"
dependencies = [
"flate2",
"thiserror 2.0.21",
@@ -1740,7 +1740,7 @@ dependencies = [
[[package]]
name = "craft-zip"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=a4432f087#a4432f08707fca90bf53128011c5dde0d87a2dfd"
source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551"
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=a4432f087)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=8345921af)",
"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=a4432f087)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=8345921af)",
"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=a4432f087)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=8345921af)",
"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=a4432f087)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=8345921af)",
"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 = "a4432f087", version = "=0.1.0" }
craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "8345921af", 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 = "a4432f087", version = "=0.1.0" }
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "8345921af", 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 -10
View File
@@ -55,8 +55,9 @@ 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 layout = craft_idml::model::TableLayout::from_el(&crate::xml::to_craft(e));
let model_table = craft_idml::model::Table::from_el(&crate::xml::to_craft(e));
let table_options = model_table.values.table_options();
let layout = craft_idml::model::TableLayout::from_table(&model_table);
// A file's row and column counts are its claim, and a table of them is allocated whole: a
// story holding one `<Table>` with 5,000 of each asked for 25M cells, around 34 GB, which
// aborts the process instead of failing (#1583). What is read is clamped, and the rest of
@@ -151,8 +152,7 @@ impl<'r> Importer<'r> {
column_strokes.merge(&self.alt_stroke_attrs(e, "Column"));
column_strokes.apply_to(&mut t.options.column_strokes);
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));
for model_cell in model_table.cells() {
let options = model_cell.options();
let Some((c, r)) = model_cell.position().map(|(c, r)| (c as usize, r as usize)) else {
continue;
@@ -164,14 +164,16 @@ impl<'r> Importer<'r> {
let rs = (rs as usize).min(nr - r);
let cs = (cs as usize).min(nc - c);
let mut cell = t.cell(r, c).cloned().unwrap_or_default();
let cell_style = ce.get("AppliedCellStyle").map(|r| self.cell_style_ref(r)).unwrap_or_else(|| designcraft_doc::NO_CELL_STYLE.into());
let cell_el = crate::xml::from_craft(model_cell.to_el());
let cell_style =
model_cell.values.get("AppliedCellStyle").map(|r| self.cell_style_ref(r)).unwrap_or_else(|| designcraft_doc::NO_CELL_STYLE.into());
if cell_style != designcraft_doc::NO_CELL_STYLE {
designcraft_doc::resolve_cell_style(&self.styles.cell, &cell_style).apply_to(&mut cell);
}
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, &options, border_unset);
cell.text = self.story_with_para(StoryId(0), &cell_el, default_para);
self.read_cell_attrs(&mut cell, &options, border_unset);
if let Some(slot) = t.cell_mut(r, c) {
*slot = cell;
}
@@ -186,7 +188,7 @@ 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, options: &craft_idml::model::CellOptions, border_unset: bool) {
fn read_cell_attrs(&mut self, cell: &mut designcraft_doc::Cell, options: &craft_idml::model::CellOptions, border_unset: bool) {
if let Some(fc) = options.fill_color.as_deref() {
cell.fill = self.swatch_ref(fc);
}
@@ -211,8 +213,8 @@ impl<'r> Importer<'r> {
if cell.rotation != 0.0 {
self.rotated_cells += 1;
}
for (i, side) in ["TopEdge", "LeftEdge", "BottomEdge", "RightEdge"].iter().enumerate() {
let attrs = self.cell_stroke_attrs(ce, side);
for (i, values) in options.edge_strokes.iter().cloned().enumerate() {
let attrs = self.map_stroke_values(values);
attrs.apply_to(&mut cell.strokes[i]);
cell.stroke_defined[i] |= !attrs.is_empty();
let priority = options.edge_stroke_priorities[i];