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.
This commit is contained in:
dotCooCoo
2026-11-08 13:20:41 +07:00
committed by bflatastic
parent cd95a8a6d1
commit 7b8185ed33
2 changed files with 19 additions and 3 deletions
+3 -3
View File
@@ -361,13 +361,13 @@ fn stop_key(s: &GradientStop) -> Option<StopKey<'_>> {
}
/// 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<String> = d.swatches_iter().map(|w| w.name.clone()).collect();
let live: HashSet<String> = d.swatches_iter().chain([vectorcraft_color::swatch::registration()]).map(|w| w.name.clone()).collect();
let mut by_color: HashMap<ColorKey, &String> = HashMap::new();
for (c, n) in links {
if let Some(k) = color_key(c) {
+16
View File
@@ -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();