mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-14 22:42:46 +00:00
Expose IDML cell option values
This commit is contained in:
2 files changed
+34
-1
No files matched your search
@@ -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};
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user