From 7b8185ed338d2b91b53a9b6ea300ceda029a5052 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 7 Nov 2026 18:44:37 -0800 Subject: [PATCH] Swatches: global Add Used Colors keeps Registration links A paint linked to the built-in Registration swatch is no longer relinked to a new global swatch of the same color, so it keeps printing on every plate. The same rule applies to New Color Group from artwork with global swatches. --- crates/engine/src/cmd/swatch.rs | 6 +++--- crates/engine/src/tests/swatchcmds.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/swatch.rs b/crates/engine/src/cmd/swatch.rs index 77bbc3f82..f19861685 100644 --- a/crates/engine/src/cmd/swatch.rs +++ b/crates/engine/src/cmd/swatch.rs @@ -361,13 +361,13 @@ fn stop_key(s: &GradientStop) -> Option> { } /// Link the solid paints in the subtrees of `ids` whose color is one of `links`' to that swatch -/// (the first one listed for the color), unless they already link to an existing swatch. Returns -/// the number of paints linked. +/// (the first one listed for the color), unless they already link to an existing swatch or to the +/// built-in Registration swatch. Returns the number of paints linked. fn link_colors(d: &mut Document, ids: &[NodeId], links: &[(Color, String)]) -> usize { if links.is_empty() { return 0; } - let live: HashSet = d.swatches_iter().map(|w| w.name.clone()).collect(); + let live: HashSet = d.swatches_iter().chain([vectorcraft_color::swatch::registration()]).map(|w| w.name.clone()).collect(); let mut by_color: HashMap = HashMap::new(); for (c, n) in links { if let Some(k) = color_key(c) { diff --git a/crates/engine/src/tests/swatchcmds.rs b/crates/engine/src/tests/swatchcmds.rs index 6e06cbade..53876a218 100644 --- a/crates/engine/src/tests/swatchcmds.rs +++ b/crates/engine/src/tests/swatchcmds.rs @@ -195,6 +195,22 @@ fn add_used_colors_global_links_every_paint_of_a_new_color() { assert!(USED_NAMES.iter().all(|n| doc(&s).swatch(n).unwrap().global)); } +/// A paint linked to Registration keeps its link when a new global swatch has the same color. +#[test] +fn add_used_colors_global_leaves_registration_links_alone() { + let mut s = session(); + let reg_paint = Paint::Solid { color: Color::cmyk(1.0, 1.0, 1.0, 1.0), swatch: Some(vectorcraft_color::swatch::REGISTRATION.into()), tint: 1.0 }; + let registration = rect_filled(&mut s, json!({"color": "#000000"})); + set_fill(&mut s, registration, reg_paint.clone()); + let plain = rect_filled(&mut s, json!({"color": "#000000"})); + set_fill(&mut s, plain, Paint::solid(Color::cmyk(1.0, 1.0, 1.0, 1.0))); + let r = run(&mut s, "swatch.addUsedColors", json!({"global": true})); + assert_eq!(r["linked"], json!(1), "{r}"); + let name = r["added"][0].as_str().unwrap().to_string(); + assert_eq!(fill(&s, registration), reg_paint); + assert_eq!(fill(&s, plain), Paint::Solid { color: Color::cmyk(1.0, 1.0, 1.0, 1.0), swatch: Some(name), tint: 1.0 }); +} + #[test] fn unused_matches_links_tints_colors_gradients_and_patterns_exactly() { let mut s = session();