From 30c63d643f5008481f2aa638bfa00e638cefbb94 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 06:34:56 -0500 Subject: [PATCH] Add neutral IDML color definition writer --- crates/idml/src/model/mod.rs | 4 ++-- crates/idml/src/model/resources.rs | 35 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/crates/idml/src/model/mod.rs b/crates/idml/src/model/mod.rs index 07503bc2a..6fab05c3a 100644 --- a/crates/idml/src/model/mod.rs +++ b/crates/idml/src/model/mod.rs @@ -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, diff --git a/crates/idml/src/model/resources.rs b/crates/idml/src/model/resources.rs index baca34a8e..6437fc9cc 100644 --- a/crates/idml/src/model/resources.rs +++ b/crates/idml/src/model/resources.rs @@ -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()