diff --git a/crates/idml/src/model/mod.rs b/crates/idml/src/model/mod.rs index 245990f73..5d10c1fff 100644 --- a/crates/idml/src/model/mod.rs +++ b/crates/idml/src/model/mod.rs @@ -17,6 +17,7 @@ mod resources; mod spread; mod story; +use craft_xml::{El, Local, Node}; pub use geometry::{MAX_PATH_POINTS, PathGeometry, PathGeometryError, PathPoint, SubPath}; pub use resources::{ ColorGroup, ColorSpace, GradientStop, GradientStopValue, Ink, StrokeStyle, StrokeStyleKind, Style, StyleGroup, StyleKind, StyleNode, Swatch, @@ -28,8 +29,6 @@ pub use spread::{ }; pub use story::{Ace, CONTAINERS, Cell, CellOptions, Container, ContentPart, Range, Story, StoryPreference, Table, TableChild, TextNode, stories}; -use craft_xml::{El, Local, Node}; - use crate::value::{matrix, nums}; /// An IDML transform: `a b c d tx ty`, inner coordinates to parent coordinates. @@ -46,6 +45,17 @@ pub struct Values { pub properties: Vec, } +/// Raw IDML stroke values before the caller maps swatches and stroke styles into its model. +#[derive(Clone, Debug, Default, PartialEq)] +pub struct StrokeValues { + pub weight: Option, + pub color: Option, + pub tint: Option, + pub kind: Option, + pub gap_color: Option, + pub gap_tint: Option, +} + impl Values { /// The attributes and `` of `el`. pub fn of(el: &El) -> Values { @@ -164,6 +174,19 @@ impl Values { } el } + + /// Read an IDML stroke attribute family such as `TopEdgeStrokeWeight` or + /// `StartRowStrokeColor`. + pub fn stroke_values(&self, prefix: &str) -> StrokeValues { + StrokeValues { + weight: self.num(&format!("{prefix}StrokeWeight")).map(|v| v.max(0.0)), + color: self.value(&format!("{prefix}StrokeColor")), + tint: self.num(&format!("{prefix}StrokeTint")), + kind: self.value(&format!("{prefix}StrokeType")), + gap_color: self.value(&format!("{prefix}StrokeGapColor")), + gap_tint: self.num(&format!("{prefix}StrokeGapTint")), + } + } } /// `el` without its indentation: the whitespace-only text between the children of an element