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