mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 22:39:07 +00:00
Swatches: merging a swatch drops the process plates of the gradient stops linked to it
Merge Swatches relinked a gradient stop linked to a merged spot swatch to the kept swatch but kept the process plates it printed with the old ink, so a kept spot swatch printed them beside its own tint and a kept global process swatch held them for a later change back to spot. The merge now clears those plates in the art, gradient swatches, graphic styles, the art of brushes and the fill and stroke for new art, in the same undo step. Stops linked to other swatches keep their plates.
This commit is contained in:
@@ -231,6 +231,75 @@ fn deleting_a_spot_swatch_takes_the_process_plates_of_the_stops_it_unlinks() {
|
||||
assert_eq!(gradient(&s, id).gradient.stops[1], linked, "undo brings back the link and the plates");
|
||||
}
|
||||
|
||||
/// The stops of the gradients the merge test puts in place: the art's fill, gradient swatch "Glow",
|
||||
/// graphic style "Style", the art of brush "Brush" and the fill new art takes.
|
||||
fn merge_test_stops(s: &Session, id: NodeId) -> Vec<(&'static str, Vec<GradientStop>)> {
|
||||
let d = doc(s);
|
||||
let stops = |p: Paint| match p {
|
||||
Paint::Gradient(g) => g.gradient.stops,
|
||||
p => panic!("not a gradient: {p:?}"),
|
||||
};
|
||||
let style = d.graphic_style("Style").unwrap().appearance.items.iter().find_map(|it| match it {
|
||||
vectorcraft_doc::AppearanceItem::Fill(f) => Some(f.paint.clone()),
|
||||
vectorcraft_doc::AppearanceItem::Stroke(_) => None,
|
||||
});
|
||||
let mut brush = None;
|
||||
for n in vectorcraft_brush::find(d, "Brush").unwrap().art() {
|
||||
n.walk(&mut |m| {
|
||||
if brush.is_none() && matches!(m.appearance.fill_paint(), Paint::Gradient(_)) {
|
||||
brush = Some(m.appearance.fill_paint());
|
||||
}
|
||||
});
|
||||
}
|
||||
vec![
|
||||
("art", stops(d.node(id).unwrap().appearance.fill_paint())),
|
||||
("gradient swatch", stops(d.swatch("Glow").unwrap().paint.clone())),
|
||||
("graphic style", stops(style.unwrap())),
|
||||
("brush art", stops(brush.unwrap())),
|
||||
("new art", stops(s.paint.fill.clone())),
|
||||
]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merging_swatches_takes_the_process_plates_of_the_stops_it_relinks() {
|
||||
// Kept swatch "Keep": spot, global process, and process that isn't global.
|
||||
for (spot, global) in [(true, true), (false, true), (false, false)] {
|
||||
let (mut s, id) = setup();
|
||||
run(&mut s, "swatch.new", json!({"name": "Keep", "color": "#00ff00", "spot": spot, "global": global}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Other", "color": {"c": 1, "m": 0, "y": 0, "k": 0}, "spot": true}));
|
||||
// Ink at 50 % over a 30 % cyan plate, and Other over its own 20 % magenta plate, which the
|
||||
// merge leaves alone.
|
||||
let plated = json!({"stops": [
|
||||
{"offset": 0, "swatch": "Ink", "tint": 50, "plates": [0.3, 0, 0, 0]},
|
||||
{"offset": 1, "swatch": "Other", "plates": [0, 0.2, 0, 0]},
|
||||
]});
|
||||
run(&mut s, "paint.editGradient", plated.clone());
|
||||
run(&mut s, "swatch.new", json!({"name": "Glow", "gradient": plated}));
|
||||
run(&mut s, "graphicStyle.new", json!({"name": "Style"}));
|
||||
run(&mut s, "brush.new", json!({"type": "art", "name": "Brush"}));
|
||||
s.paint.fill = doc(&s).node(id).unwrap().appearance.fill_paint();
|
||||
let before = merge_test_stops(&s, id);
|
||||
let kept = doc(&s).linked_color(doc(&s).swatch("Keep").unwrap().paint.color().unwrap(), spot);
|
||||
assert!(before.iter().all(|(_, st)| st[0].plates == Some([0.3, 0.0, 0.0, 0.0])), "{before:?}");
|
||||
|
||||
run(&mut s, "swatch.merge", json!({"names": ["Keep", "Ink"]}));
|
||||
let after = merge_test_stops(&s, id);
|
||||
// The stop shows its tint of the kept color, unlinked when the kept swatch isn't global.
|
||||
let (link, tint, color) = if global { (Some("Keep"), 0.5, kept.tinted(0.5)) } else { (None, 1.0, kept.tinted(0.5)) };
|
||||
for (place, st) in &after {
|
||||
let what = format!("spot {spot}, global {global}, {place}: {st:?}");
|
||||
assert_eq!((st[0].swatch.as_deref(), st[0].tint, st[0].plates), (link, tint, None), "{what}");
|
||||
assert_eq!(st[0].color, color, "{what}");
|
||||
assert_eq!((st[1].swatch.as_deref(), st[1].plates), (Some("Other"), Some([0.0, 0.2, 0.0, 0.0])), "{what}");
|
||||
}
|
||||
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert_eq!(merge_test_stops(&s, id), before, "undo brings back the links and the plates");
|
||||
run(&mut s, "edit.redo", json!({}));
|
||||
assert_eq!(merge_test_stops(&s, id), after, "redo merges again");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn radial_spot_gradients_mixed_with_other_inks_export_as_device_n_shadings() {
|
||||
let (mut s, _) = setup();
|
||||
|
||||
Reference in New Issue
Block a user