From 0e537f7952fbeccf2fd1440d0b5cd50dac93b330 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 04:37:20 -0500 Subject: [PATCH] Retain optional gradient stop values --- crates/idml/src/model/mod.rs | 4 ++-- crates/idml/src/model/resources.rs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/idml/src/model/mod.rs b/crates/idml/src/model/mod.rs index a0d630498..49ba0b3eb 100644 --- a/crates/idml/src/model/mod.rs +++ b/crates/idml/src/model/mod.rs @@ -19,8 +19,8 @@ mod story; pub use geometry::{MAX_PATH_POINTS, PathGeometry, PathGeometryError, PathPoint, SubPath}; pub use resources::{ - ColorGroup, ColorSpace, GradientStop, StrokeStyle, StrokeStyleKind, Style, StyleGroup, StyleKind, StyleNode, Swatch, SwatchKind, color_groups, - named, preference, stroke_styles, style_groups, swatches, + ColorGroup, ColorSpace, GradientStop, GradientStopValue, StrokeStyle, StrokeStyleKind, Style, StyleGroup, StyleKind, StyleNode, Swatch, + SwatchKind, color_groups, named, preference, stroke_styles, style_groups, swatches, }; pub use spread::{Graphic, GraphicChild, GraphicKind, Guide, ItemChild, ItemKind, Link, Page, PageChild, PageItem, Spread, SpreadChild, spreads}; pub use story::{Ace, CONTAINERS, Cell, Container, ContentPart, Range, Story, Table, TableChild, TextNode, stories}; diff --git a/crates/idml/src/model/resources.rs b/crates/idml/src/model/resources.rs index 6a66f6f91..3a5b80d9a 100644 --- a/crates/idml/src/model/resources.rs +++ b/crates/idml/src/model/resources.rs @@ -238,6 +238,14 @@ pub struct GradientStop { pub midpoint: f64, } +/// A `GradientStop` in source order, including optional values as written. +#[derive(Clone, Debug, PartialEq)] +pub struct GradientStopValue { + pub color: Option, + pub location: Option, + pub midpoint: Option, +} + impl Swatch { pub fn to_el(&self) -> El { let mut el = self.values.element(self.kind.name()); @@ -296,6 +304,22 @@ impl Swatch { }) .collect() } + + /// Every gradient stop in source order, retaining absent or malformed optional values. + pub fn stops_in_order(&self) -> Vec { + self.rest + .iter() + .filter(|e| e.local() == "GradientStop") + .map(|e| { + let values = Values::of(e); + GradientStopValue { + color: values.get("StopColor").map(str::to_string), + location: values.num("Location"), + midpoint: values.num("Midpoint"), + } + }) + .collect() + } } /// The swatches among `top`, in order.