Parse IDML stroke value families

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 09:05:19 -05:00
1 parent d412f12f59
commit 6891ec1a94
1 file changed
+25 -2
+25 -2
View File
@@ -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<El>,
}
/// 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<f64>,
pub color: Option<String>,
pub tint: Option<f64>,
pub kind: Option<String>,
pub gap_color: Option<String>,
pub gap_tint: Option<f64>,
}
impl Values {
/// The attributes and `<Properties>` 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