Add neutral IDML color definition writer

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 09:05:19 -05:00
1 parent 398e7510ac
commit 30c63d643f
2 files changed
+37 -2

No files matched your search

+2 -2
View File
@@ -22,8 +22,8 @@ use craft_xml::{El, Local, Node};
pub use document::{ModelDocument, TopLevelKind, TopLevelNode};
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,
SwatchKind, color_groups, inks, named, preference, stroke_styles, style_groups, swatches,
ColorDefinition, ColorGroup, ColorSpace, GradientStop, GradientStopValue, Ink, StrokeStyle, StrokeStyleKind, Style, StyleGroup, StyleKind,
StyleNode, Swatch, SwatchKind, color_groups, inks, named, preference, stroke_styles, style_groups, swatches,
};
pub use spread::{
Graphic, GraphicChild, GraphicKind, Guide, ItemChild, ItemKind, Link, MarginPreference, Page, PageChild, PageItem, Spread, SpreadChild, TextPath,
+35
View File
@@ -394,6 +394,41 @@ pub struct Ink {
pub values: Values,
}
/// A neutral colour definition for writing `Graphic.xml`.
///
/// The caller supplies colour-space values as IDML's serialized value list; this type owns the
/// element and attribute grammar so applications do not need to emit `Color` XML themselves.
#[derive(Clone, Debug, PartialEq)]
pub struct ColorDefinition {
pub self_id: String,
pub name: String,
pub model: String,
pub space: String,
pub value: String,
pub override_kind: String,
pub editable: bool,
pub removable: bool,
pub visible: bool,
}
impl ColorDefinition {
pub fn to_el(&self) -> El {
El::new("Color")
.with_attr("Self", &self.self_id)
.with_attr("Model", &self.model)
.with_attr("Space", &self.space)
.with_attr("ColorValue", &self.value)
.with_attr("ColorOverride", &self.override_kind)
.with_attr("AlternateSpace", "NoAlternateColor")
.with_attr("AlternateColorValue", "")
.with_attr("Name", &self.name)
.with_attr("ColorEditable", self.editable)
.with_attr("ColorRemovable", self.removable)
.with_attr("Visible", self.visible)
.with_attr("SwatchCreatorID", "7937")
}
}
impl Ink {
pub fn name(&self) -> Option<&str> {
self.values.name()