Expose IDML cell option values

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 09:05:19 -05:00
1 parent 9f57e1fc0e
commit d412f12f59
2 files changed
+34 -1

No files matched your search

+1 -1
View File
@@ -26,7 +26,7 @@ pub use spread::{
Graphic, GraphicChild, GraphicKind, Guide, ItemChild, ItemKind, Link, MarginPreference, Page, PageChild, PageItem, Spread, SpreadChild, TextPath,
spreads,
};
pub use story::{Ace, CONTAINERS, Cell, Container, ContentPart, Range, Story, StoryPreference, Table, TableChild, TextNode, stories};
pub use story::{Ace, CONTAINERS, Cell, CellOptions, Container, ContentPart, Range, Story, StoryPreference, Table, TableChild, TextNode, stories};
use craft_xml::{El, Local, Node};
+33
View File
@@ -150,6 +150,19 @@ pub struct Cell {
pub children: Vec<TextNode>,
}
/// Format-level options on an IDML table cell, before DesignCraft maps them into its model.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct CellOptions {
pub fill_color: Option<String>,
pub fill_tint: Option<f64>,
pub insets: [Option<f64>; 4],
pub vertical_justification: Option<String>,
pub first_baseline_offset: Option<String>,
pub minimum_first_baseline_offset: Option<f64>,
pub rotation_angle: Option<f64>,
pub edge_stroke_priorities: [i32; 4],
}
/// The children of `el` other than `<Properties>`, as text nodes.
fn nodes(el: &El) -> Vec<TextNode> {
el.elements().filter(|e| !e.is(Local("Properties"))).map(TextNode::from_el).collect()
@@ -443,6 +456,26 @@ impl Cell {
(n("ColumnSpan"), n("RowSpan"))
}
pub fn options(&self) -> CellOptions {
let inset = |current: &str, legacy: &str| self.values.num(current).or_else(|| self.values.num(legacy));
let priority = |side: &str| self.values.prop(&format!("{side}StrokePriority")).and_then(|v| v.trim().parse().ok()).unwrap_or(0);
CellOptions {
fill_color: self.values.value("FillColor"),
fill_tint: self.values.num("FillTint"),
insets: [
inset("TextTopInset", "TopInset"),
inset("TextLeftInset", "LeftInset"),
inset("TextBottomInset", "BottomInset"),
inset("TextRightInset", "RightInset"),
],
vertical_justification: self.values.value("VerticalJustification"),
first_baseline_offset: self.values.value("FirstBaselineOffset"),
minimum_first_baseline_offset: self.values.num("MinimumFirstBaselineOffset"),
rotation_angle: self.values.num("RotationAngle"),
edge_stroke_priorities: [priority("TopEdge"), priority("LeftEdge"), priority("BottomEdge"), priority("RightEdge")],
}
}
pub fn paragraphs(&self) -> Vec<&Range> {
paragraphs(&self.children)
}