Retain optional gradient stop values

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 09:05:18 -05:00
1 parent 5d8ddd13e5
commit 0e537f7952
2 files changed
+26 -2

No files matched your search

+2 -2
View File
@@ -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};
+24
View File
@@ -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<String>,
pub location: Option<f64>,
pub midpoint: Option<f64>,
}
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<GradientStopValue> {
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.