Merge pull request #8253 from dotCooCoo/feat/color-guide-spot-tints

Color Guide: a spot color base gives tints of that spot color
This commit is contained in:
BFlat
2026-11-17 13:08:18 +07:00
committed by GitHub
11 changed files with 446 additions and 45 deletions
+7 -1
View File
@@ -294,13 +294,19 @@ impl GuideOptions {
}
}
/// The share of the way to its target (black or white, cool or warm, gray or full color) that the
/// variation at `step` goes: 0 at the center, the options' reach at the outermost steps.
pub fn step_fraction(opts: &GuideOptions, step: i32) -> f32 {
(step.unsigned_abs() as f32 / opts.steps.max(1) as f32).min(1.0) * opts.reach()
}
/// Variation of `c` at `step` (−steps..=steps: negative towards shades/cool/muted, positive towards
/// tints/warm/vivid; 0 is `c` itself), in `c`'s model.
pub fn variation(c: Color, opts: &GuideOptions, step: i32) -> Color {
if step == 0 {
return c;
}
let f = (step.unsigned_abs() as f32 / opts.steps.max(1) as f32).min(1.0) * opts.reach();
let f = step_fraction(opts, step);
let v = match opts.variation {
Variation::TintsShades => c.lerp(if step < 0 { &Color::BLACK } else { &Color::WHITE }, f),
Variation::WarmCool => {
+37 -14
View File
@@ -19,7 +19,7 @@ pub fn specs() -> Vec<CommandSpec> {
"New Swatch",
["Window", "Swatches"],
None,
"{name?, color? | colors?: [colour] (one swatch each, in one undo step; #rrggbbaa and #rgba are refused) | swatch? | gradient? | pattern?: name (default: the current fill), tint?: 0..100 (% of the global or spot `swatch`, or of the one the current fill links to), mode?: \"gray\"|\"rgb\"|\"hsb\"|\"lab\"|\"cmyk\"|\"web\" (convert the colour; lab: CIE L*a*b*, how spot colours are usually defined), global?, spot? (a spot colour, always global), group?: colour group name (solid colours only; default: ungrouped), none?: true (the None paint), paint?: paint.setFill params, keepModel?: bool (as paint.setFill)} save a colour, gradient or pattern as a swatch. A tint of a global or spot colour (below 100%, without mode, global or spot) becomes a tint swatch, \"Name 40%\", linked to its base: it follows edits to the base and applies as that tint of it. A gradient swatch keeps the gradient's aspect (with or without start/end) and holds no link to the swatch its gradient came from, and a pattern swatch holds the pattern untransformed. Names are unique (\"Sky 2\"); a colour's default name is its values (\"C=10 M=20 Y=30 K=0\", \"R=255 G=128 B=0\", \"Gray K=40\", \"L=55 a=60 b=40\") → {name, names: [every new swatch]}",
"{name?, color? | colors?: [colour | {swatch, tint?}] (one swatch each, in one undo step; #rrggbbaa and #rgba are refused; `{swatch, tint}` is the paint paint.setFill gives, so a tint of a global or spot color becomes a tint swatch) | swatch? | gradient? | pattern?: name (default: the current fill), tint?: 0..100 (% of the global or spot `swatch`, or of the one the current fill links to), mode?: \"gray\"|\"rgb\"|\"hsb\"|\"lab\"|\"cmyk\"|\"web\" (convert the colour; lab: CIE L*a*b*, how spot colours are usually defined), global?, spot? (a spot colour, always global), group?: colour group name (solid colours only; default: ungrouped), none?: true (the None paint), paint?: paint.setFill params, keepModel?: bool (as paint.setFill)} save a colour, gradient or pattern as a swatch. A tint of a global or spot colour (below 100%, without mode, global or spot) becomes a tint swatch, \"Name 40%\", linked to its base: it follows edits to the base and applies as that tint of it. A gradient swatch keeps the gradient's aspect (with or without start/end) and holds no link to the swatch its gradient came from, and a pattern swatch holds the pattern untransformed. Names are unique (\"Sky 2\"); a colour's default name is its values (\"C=10 M=20 Y=30 K=0\", \"R=255 G=128 B=0\", \"Gray K=40\", \"L=55 a=60 b=40\") → {name, names: [every new swatch]}",
has_doc,
swatch_new
),
@@ -37,7 +37,7 @@ pub fn specs() -> Vec<CommandSpec> {
"New Color Group",
["Window", "Swatches"],
None,
"{name?, swatches?: [names] (solid colours move into the group; gradients, patterns and None stay), colors?: [colour] (added as new swatches; #rrggbbaa and #rgba are refused), keepModel?: bool (as paint.setFill), fromArtwork?: false (add the unique colours of the selected art: fills, strokes, text, gradient stops and mesh points; a colour linked to a global swatch moves that swatch into the group), toGlobal?: true (with fromArtwork: the new swatches are global and the selected art's matching unlinked colours link to them), includeTints?: false (with fromArtwork: tints of global swatches also get swatches of their own)} → {name, swatches: [names in the group], linked: paints linked}",
"{name?, swatches?: [names] (solid colours move into the group; gradients, patterns and None stay), colors?: [colour | {swatch, tint?}] (added as new swatches; #rrggbbaa and #rgba are refused; `{swatch, tint}` below 100% of a global or spot color adds a tint swatch, \"Name 40%\", linked to it, and any other `{swatch}` its color), keepModel?: bool (as paint.setFill), fromArtwork?: false (add the unique colours of the selected art: fills, strokes, text, gradient stops and mesh points; a colour linked to a global swatch moves that swatch into the group), toGlobal?: true (with fromArtwork: the new swatches are global and the selected art's matching unlinked colours link to them), includeTints?: false (with fromArtwork: tints of global swatches also get swatches of their own)} → {name, swatches: [names in the group], linked: paints linked}",
has_doc,
swatch_new_group
),
@@ -146,9 +146,11 @@ fn swatch_new(s: &mut Session, p: &Value) -> Result<Value> {
let stored = |c: Color| if mode.is_some() { c } else { super::paint::new_color(s, p, c) };
let cs: Vec<Paint> = cs
.iter()
.map(|c| color_value(c).map(|c| Paint::solid(stored(c))))
.collect::<Option<_>>()
.ok_or_else(|| bad(C, "bad colour in `colors`"))?;
.map(|c| match swatch_entry(s, c, C)? {
Some(paint) => Ok(paint),
None => color_value(c).map(|c| Paint::solid(stored(c))).ok_or_else(|| bad(C, "bad colour in `colors`")),
})
.collect::<Result<_>>()?;
if cs.is_empty() {
return Err(bad(C, "`colors` is empty"));
}
@@ -216,6 +218,16 @@ fn swatch_new(s: &mut Session, p: &Value) -> Result<Value> {
Ok(json!({ "name": names[0], "names": names }))
}
/// A `colors` entry of `swatch.new` or `swatch.newGroup` that names a color swatch,
/// `{swatch, tint?}`: the paint `paint.setFill {swatch, tint}` applies (a tint of a global or spot
/// color stays linked to it). `None` for an entry without `swatch`.
fn swatch_entry(s: &Session, v: &Value, cmd: &str) -> Result<Option<Paint>> {
let Some(name) = v.get("swatch") else { return Ok(None) };
let name = name.as_str().ok_or_else(|| bad(cmd, format!("`swatch` in `colors` must be a swatch name, not {name}")))?;
let tint = super::paint::tint_param(v, cmd)?;
super::paint::swatch_solid(&s.doc()?.doc, name, tint).map(Some).map_err(|e| bad(cmd, e))
}
/// A gradient or pattern `paint`, parsed from the paint params `p`, as a new or edited swatch
/// stores it.
fn stored_paint(paint: Paint, p: &Value) -> Paint {
@@ -475,10 +487,20 @@ fn swatch_new_group(s: &mut Session, p: &Value) -> Result<Value> {
let mut names = str_list(p, "swatches");
super::paint::check_keep_model(p, C)?;
check_switches(p, &["fromArtwork", "toGlobal", "includeTints"], C)?;
let colors: Vec<Color> = p
// A `{swatch, tint}` entry below 100% becomes a tint swatch linked to its base; any other
// entry becomes a process color swatch.
let colors: Vec<Paint> = p
.get("colors")
.and_then(Value::as_array)
.map(|a| a.iter().map(|v| color_value(v).map(|c| super::paint::new_color(s, p, c)).ok_or_else(|| bad(C, format!("bad color {v}")))).collect())
.map(|a| {
a.iter()
.map(|v| match swatch_entry(s, v, C)? {
Some(paint @ Paint::Solid { swatch: Some(_), tint, .. }) if tint < 1.0 => Ok(paint),
Some(paint) => paint.color().map(Paint::solid).ok_or_else(|| bad(C, format!("bad color {v}"))),
None => color_value(v).map(|c| Paint::solid(super::paint::new_color(s, p, c))).ok_or_else(|| bad(C, format!("bad color {v}"))),
})
.collect::<Result<Vec<_>>>()
})
.transpose()?
.unwrap_or_default();
let from_art = bool_or(p, "fromArtwork", false);
@@ -486,15 +508,15 @@ fn swatch_new_group(s: &mut Session, p: &Value) -> Result<Value> {
let tints = bool_or(p, "includeTints", false);
let requested = name_param(p, "name");
let (name, members, linked) = s.edit("New Color Group", |d, sel| {
// New swatches: (colour, global).
let mut new: Vec<(Color, bool)> = colors.iter().map(|c| (*c, false)).collect();
// New swatches: (paint, global).
let mut new: Vec<(Paint, bool)> = colors.iter().map(|c| (c.clone(), false)).collect();
if from_art {
if sel.objects.is_empty() {
return Err(bad(C, "select artwork to make a group of its colours"));
}
let mut art = vec![];
artwork_colors(d, &sel.objects, tints, &mut names, &mut art);
new.extend(art.into_iter().map(|c| (c, to_global)));
new.extend(art.into_iter().map(|c| (Paint::solid(c), to_global)));
}
let name = d.free_swatch_name(requested.as_deref().unwrap_or("Color Group"));
// Colour groups hold solid colours only.
@@ -505,12 +527,13 @@ fn swatch_new_group(s: &mut Session, p: &Value) -> Result<Value> {
let mut free = d.free_swatch_names();
free.insert(&name);
group.swatches.iter().for_each(|sw| free.insert(&sw.name));
for (c, global) in new {
let nm = free.take(&color_name(c));
if global {
for (paint, global) in new {
// A tint swatch is named "Name 40%", a colour after its values.
let nm = free.take_new(&paint);
if global && let Some(c) = paint.color() {
links.push((c, nm.clone()));
}
group.swatches.push(Swatch { name: nm, paint: Paint::solid(c), global, spot: false });
group.swatches.push(Swatch { name: nm, paint, global, spot: false });
}
let members: Vec<String> = group.swatches.iter().map(|w| w.name.clone()).collect();
d.swatch_groups.push(group);
+47
View File
@@ -95,3 +95,50 @@ fn new_swatch_saves_several_colours_in_one_step() {
assert!(s.execute("swatch.new", &json!({"colors": []})).is_err());
assert!(s.execute("swatch.new", &json!({"colors": ["nope"]})).is_err());
}
/// The tint swatch a swatch named `name` is: (base, tint 0..1); none for any other swatch.
fn tint_of(s: &Session, name: &str) -> Option<(String, f32)> {
s.doc().unwrap().doc.swatch(name)?.tint_of().map(|(b, t)| (b.to_string(), t))
}
/// `{swatch, tint}` entries of `swatch.new {colors}` and `swatch.newGroup {colors}` make tint
/// swatches linked to their spot color, beside plain colors, in one undo step; the tints follow an
/// edit of the spot color; a bad entry saves nothing.
#[test]
fn colors_entries_naming_a_spot_color_save_tint_swatches() {
let mut s = session();
s.execute("swatch.new", &json!({"name": "Ink", "color": "#0066cc", "spot": true})).unwrap();
let undo = s.doc().unwrap().history.undo.len();
let r = s.execute("swatch.new", &json!({"colors": [{"swatch": "Ink", "tint": 60}, "#112233", {"swatch": "Ink", "tint": 30}]})).unwrap();
let names = hexes(&r["names"]);
assert_eq!(names, ["Ink 60%", "R=17 G=34 B=51", "Ink 30%"]);
assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1, "one undo step");
let (base, tint) = tint_of(&s, "Ink 60%").expect("a tint swatch");
assert_eq!(base, "Ink");
assert!((tint - 0.6).abs() < 1e-6, "{tint}");
assert!(tint_of(&s, "R=17 G=34 B=51").is_none());
let r = s.execute("swatch.newGroup", &json!({"name": "Guide", "colors": [{"swatch": "Ink", "tint": 45}, "#445566", {"swatch": "Ink"}]})).unwrap();
let members = hexes(&r["swatches"]);
assert_eq!(members[0], "Ink 45%");
assert_eq!(tint_of(&s, "Ink 45%").map(|(b, _)| b).as_deref(), Some("Ink"));
assert!(members[1..].iter().all(|m| tint_of(&s, m).is_none()), "a color and the full spot color are process copies: {members:?}");
let d = &s.doc().unwrap().doc;
let full = d.swatch(&members[2]).unwrap();
assert!(!full.spot && !full.global, "{full:?}");
// The tint swatches follow an edit of the spot color.
s.execute("swatch.edit", &json!({"name": "Ink", "color": "#cc0000"})).unwrap();
let d = &s.doc().unwrap().doc;
let ink = d.global_color("Ink").unwrap();
for name in ["Ink 60%", "Ink 45%"] {
let w = d.swatch(name).unwrap();
let t = w.tint_of().unwrap().1;
assert_eq!(w.paint.color().map(|c| c.to_hex()), Some(ink.tinted(t).to_hex()), "{name}");
}
// A missing swatch, a tint of a process color or a tint that is not a number saves nothing.
let count = s.doc().unwrap().doc.swatches_iter().count();
for bad in [json!({"swatch": "Nope", "tint": 50}), json!({"swatch": "R=17 G=34 B=51", "tint": 50}), json!({"swatch": "Ink", "tint": "half"})] {
assert!(s.execute("swatch.new", &json!({"colors": ["#010203", bad]})).is_err(), "{bad}");
assert!(s.execute("swatch.newGroup", &json!({"colors": ["#010203", bad]})).is_err(), "{bad}");
}
assert_eq!(s.doc().unwrap().doc.swatches_iter().count(), count);
}
+6
View File
@@ -267,6 +267,12 @@ impl VectorcraftApp {
{
self.ui.status = w.to_string();
}
// A renamed spot color swatch stays the Color Guide's base.
if id == "swatch.edit"
&& let (Some(from), Some(to)) = (params["name"].as_str(), v["name"].as_str())
{
crate::panels::color_guide::swatch_renamed(self, from, to);
}
if id == "file.new" {
self.ui.status.clear();
// New Document's Pixel preview mode (Overprint Preview is the engine's).
+1 -1
View File
@@ -870,7 +870,7 @@ pub(crate) fn show_sized(app: &mut VectorcraftApp, ui: &mut Ui, height: f32) {
}
if let (Some((t, phase)), Some(tint)) = (tinted, tgt.tint()) {
if phase == Live::Released {
super::color_guide::choose_base(app, tint.base.tinted(t));
super::color_guide::choose_linked_base(app, tint.base.tinted(t), Some((tint.swatch.clone(), t)));
}
apply_tint(app, &tgt, tint, t, phase);
}
+318 -25
View File
@@ -10,34 +10,141 @@
//! Swatches saves as one group (without a selection, the group holds the harmony colors). The
//! selection lasts until the guide changes. A harmony color or a cell dragged with the primary button
//! carries its color alone, as shown, without applying it or changing the selection; the Swatches
//! panel makes a swatch of it. Limit to Library (the library button,
//! panel makes a swatch of it. When the base is a spot color, or a tint of one, chosen from the
//! Swatches panel, the Color panel's tint slider or the base chip ([`SpotBase`]), the cells right of
//! the center in the base row of Tints/Shades are tints of that spot color: a click applies the tint,
//! a drag carries it, and saving makes tint swatches linked to the spot color. Every other cell is
//! a process color. Limit to Library (the library button,
//! `ui.colorGuideLimit`) snaps every colour to a swatch library or the document's swatches; Edit or
//! Apply Colors opens Recolor Artwork with the harmony colours, limited the same way.
use egui::{Rect, Sense, Ui, vec2};
use serde_json::{Value, json};
use vectorcraft_color::harmony::{Guide, GuideOptions, Harmony, Variation};
use vectorcraft_color::harmony::{self, Guide, GuideOptions, Harmony, Variation};
use vectorcraft_color::{Color, Paint};
use vectorcraft_engine::cmd::swatchlib;
use super::swatches::{self, colour_libraries, limit_key, limit_name};
use super::{active_paint, apply_click, c32, color_json, library_panel, pstate, set_pstate};
use super::{active_paint, apply_click, c32, color_json, library_panel, paint_params, pstate, set_pstate};
use crate::VectorcraftApp;
use crate::widgets::{self, PanelDrag, menu_item};
/// The base colour before one is set: an orange.
const DEFAULT_BASE: Color = Color::Rgb { r: 230.0 / 255.0, g: 120.0 / 255.0, b: 40.0 / 255.0 };
/// The guide's base color: the one last chosen or set with the base chip; before that, the current
/// color.
/// The spot color swatch the guide's base is a tint of (`UiState::color_guide_spot`).
#[derive(Clone, Debug, PartialEq)]
pub struct SpotBase {
/// The document the swatch belongs to (its `uid`).
pub doc: u64,
/// The spot color swatch's name.
pub swatch: String,
/// The base's tint of it, 0..1.
pub tint: f32,
}
/// The spot color the base is a tint of, while its swatch is still a spot color of the active
/// document.
fn live_spot(app: &VectorcraftApp) -> Option<&SpotBase> {
let s = app.ui.color_guide_spot.as_ref()?;
let st = app.session.active()?;
let spot = st.doc.swatch(&s.swatch).is_some_and(|w| w.spot) && st.doc.global_color(&s.swatch).is_some();
(st.uid == s.doc && spot).then_some(s)
}
/// The color of tint `tint` (0..1) of global swatch `name` in the active document.
fn tint_color(app: &VectorcraftApp, name: &str, tint: f32) -> Option<Color> {
app.session.active()?.doc.tint_paint(name, tint)?.color()
}
/// The guide's base color: the one last chosen or set with the base chip (a spot color base
/// follows edits to its swatch); before that, the current color.
pub(crate) fn base_color(app: &VectorcraftApp) -> Color {
if let Some(c) = live_spot(app).and_then(|s| tint_color(app, &s.swatch, s.tint)) {
return c;
}
app.ui.color_guide_base.unwrap_or_else(|| active_paint(app).color().unwrap_or(DEFAULT_BASE))
}
/// Make `c` the guide's base color: a color chosen in the Color panel, the Swatches panel or the
/// Color Picker. A color applied from the guide itself leaves the base as it is.
pub(crate) fn choose_base(app: &mut VectorcraftApp, c: Color) {
choose_linked_base(app, c, None);
}
/// [`choose_base`] for a color linked to a global swatch at a tint (0..1): when that swatch is a
/// spot color of the active document, the base is that tint of it ([`SpotBase`]).
pub(crate) fn choose_linked_base(app: &mut VectorcraftApp, c: Color, link: Option<(String, f32)>) {
app.ui.color_guide_base = Some(c);
app.ui.color_guide_spot = link.and_then(|(swatch, tint)| {
let st = app.session.active()?;
st.doc.swatch(&swatch).filter(|w| w.spot)?;
Some(SpotBase { doc: st.uid, swatch, tint: tint.clamp(0.0, 1.0) })
});
}
/// `swatch.edit` renamed swatch `from` of the active document to `to`: a spot color base linked to
/// it links to `to`.
pub(crate) fn swatch_renamed(app: &mut VectorcraftApp, from: &str, to: &str) {
let uid = app.session.active().map(|st| st.uid);
if let Some(s) = app.ui.color_guide_spot.as_mut()
&& Some(s.doc) == uid
&& s.swatch == from
{
s.swatch = to.to_string();
}
}
/// The global swatch and tint (0..1) a solid paint links to.
fn paint_link(p: &Paint) -> Option<(String, f32)> {
match p {
Paint::Solid { swatch: Some(n), tint, .. } => Some((n.clone(), *tint)),
_ => None,
}
}
/// The tint of the spot color base that cell (`row`, `col`) of the guide `g` is: a cell right of
/// the center in the base row of Tints/Shades, without a library limit. Its tint is the base's
/// tint less the share the cell goes towards white. → (swatch, tint 0..1)
fn cell_tint(app: &VectorcraftApp, g: &Guide, row: usize, col: usize) -> Option<(String, f32)> {
let opts = app.ui.color_guide.clamped();
let centre = g.centre();
if row != 0 || col <= centre || opts.variation != Variation::TintsShades || !app.ui.color_guide_limit.is_empty() {
return None;
}
let s = live_spot(app)?;
let step = i32::try_from(col - centre).ok()?;
Some((s.swatch.clone(), s.tint * (1.0 - harmony::step_fraction(&opts, step))))
}
/// The paint cell (`row`, `col`) of `g` applies, carries and saves: a tint of the spot color base
/// ([`cell_tint`]) or the color the cell shows.
fn cell_paint(app: &VectorcraftApp, g: &Guide, row: usize, col: usize) -> Option<Paint> {
let color = *g.grid.get(row)?.get(col)?;
Some(match cell_tint(app, g, row, col) {
Some((name, tint)) => Paint::Solid { color, swatch: Some(name), tint },
None => Paint::solid(color),
})
}
/// The `swatch.new` / `swatch.newGroup` entry for cell (`row`, `col`) of `g`: `{swatch, tint}` for
/// a tint of the spot color base, the color otherwise.
fn cell_entry(app: &VectorcraftApp, g: &Guide, row: usize, col: usize) -> Option<Value> {
Some(match cell_paint(app, g, row, col)? {
p @ Paint::Solid { swatch: Some(_), .. } => paint_params(&p),
p => color_json(&p.color()?),
})
}
/// `g` with the base row's spot color tints ([`cell_tint`]) shown in their own colors.
fn with_spot_tints(app: &VectorcraftApp, mut g: Guide) -> Guide {
let cols = g.grid.first().map_or(0, Vec::len);
let tints: Vec<(usize, Color)> =
(0..cols).filter_map(|col| cell_tint(app, &g, 0, col).and_then(|(n, t)| tint_color(app, &n, t)).map(|c| (col, c))).collect();
for (col, c) in tints {
g.grid[0][col] = c;
}
g
}
fn rule(ctx: &egui::Context) -> Harmony {
@@ -59,6 +166,7 @@ fn clear_selection(ctx: &egui::Context) {
#[derive(Clone, PartialEq)]
struct SelKey {
base: Color,
spot: Option<SpotBase>,
opts: GuideOptions,
rule: usize,
limit: String,
@@ -68,6 +176,7 @@ struct SelKey {
fn sel_key(app: &VectorcraftApp, ctx: &egui::Context, g: &Guide) -> SelKey {
SelKey {
base: base_color(app),
spot: live_spot(app).cloned(),
opts: app.ui.color_guide,
rule: pstate(ctx, "cg-harmony"),
limit: app.ui.color_guide_limit.clone(),
@@ -93,12 +202,13 @@ struct GuideKey {
doc: Option<(u64, u64)>,
}
/// The guide the panel shows, limited to the Limit to Library colours.
/// The guide the panel shows, limited to the Limit to Library colours; without a limit, a spot
/// color base's tints show in their own colors.
fn guide(app: &VectorcraftApp, ctx: &egui::Context) -> Guide {
let (base, rule, opts) = (base_color(app), rule(ctx), app.ui.color_guide);
let limit = &app.ui.color_guide_limit;
if limit.is_empty() {
return Guide::new(base, rule, &opts);
return with_spot_tints(app, Guide::new(base, rule, &opts));
}
let doc = app.session.active().filter(|_| limit == swatchlib::DOCUMENT_SWATCHES).map(|d| (d.uid, d.revision));
let key = GuideKey { base, rule, opts, limit: limit.clone(), doc };
@@ -156,10 +266,11 @@ fn edit_or_apply(app: &mut VectorcraftApp, g: &Guide) {
app.run("ui.recolorDialog", p).ok();
}
/// Save the selected cells' colors as swatches (one undo step), each in its own model.
/// Save the selected cells' colors as swatches (one undo step), each in its own model; a tint of a
/// spot color base becomes a tint swatch of it.
fn save_selected(app: &mut VectorcraftApp, ctx: &egui::Context) {
let g = guide(app, ctx);
let colors: Vec<Value> = live_selection(app, ctx, &g).into_iter().filter_map(|(r, c)| g.grid.get(r)?.get(c)).map(color_json).collect();
let colors: Vec<Value> = live_selection(app, ctx, &g).into_iter().filter_map(|(r, c)| cell_entry(app, &g, r, c)).collect();
if !colors.is_empty() {
app.run("swatch.new", json!({ "colors": colors, "keepModel": true })).ok();
}
@@ -168,13 +279,13 @@ fn save_selected(app: &mut VectorcraftApp, ctx: &egui::Context) {
/// Save Color Group to Swatches: the selected cells as one swatch group, in grid order (row by
/// row, left to right), each cell once; with no cell of the shown guide selected, the harmony
/// colors. The group is named after the harmony rule, saved in one undo step, and each color
/// keeps its own model.
/// keeps its own model; a tint of a spot color base becomes a tint swatch of it.
fn save_group(app: &mut VectorcraftApp, ctx: &egui::Context) {
let g = guide(app, ctx);
let mut cells = live_selection(app, ctx, &g);
cells.sort_unstable();
cells.dedup();
let mut colors: Vec<Value> = cells.into_iter().filter_map(|(r, c)| g.grid.get(r)?.get(c)).map(color_json).collect();
let mut colors: Vec<Value> = cells.into_iter().filter_map(|(r, c)| cell_entry(app, &g, r, c)).collect();
if colors.is_empty() {
colors = g.colors.iter().map(color_json).collect();
}
@@ -186,27 +297,30 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let ctx = ui.ctx().clone();
// The current color becomes the base when the panel first shows; selecting artwork later
// leaves it as it is.
let first = base_color(app);
let set = *app.ui.color_guide_base.get_or_insert(first);
if app.ui.color_guide_base.is_none() {
let current = active_paint(app);
choose_linked_base(app, current.color().unwrap_or(DEFAULT_BASE), paint_link(&current));
}
let h = rule(&ctx);
let g = guide(app, &ctx);
// Selected cells belong to the guide they were picked from: a new base, new options, another
// harmony rule, another library limit or new grid colors clear them.
let key = SelKey { base: set, ..sel_key(app, &ctx, &g) };
let key = sel_key(app, &ctx, &g);
if pstate::<Option<SelKey>>(&ctx, "cg-sel-key").as_ref() != Some(&key) {
set_pstate(&ctx, "cg-sel-key", Some(key));
clear_selection(&ctx);
}
let base = g.colors[0];
let mut chosen: Option<Color> = None;
let mut chosen: Option<Paint> = None;
ui.horizontal(|ui| {
let (r, resp) = ui.allocate_exact_size(vec2(26.0, 26.0), Sense::click());
widgets::swatch_tile(ui, r, &Paint::solid(base), false, resp.hovered());
if resp.on_hover_text(tl!("Set base color to the current color")).clicked()
&& let Some(c) = active_paint(app).color()
{
app.ui.color_guide_base = Some(c);
clear_selection(&ctx);
if resp.on_hover_text(tl!("Set base color to the current color")).clicked() {
let current = active_paint(app);
if let Some(c) = current.color() {
choose_linked_base(app, c, paint_link(&current));
clear_selection(&ctx);
}
}
let labels: Vec<&str> = Harmony::ALL.iter().map(|h| h.label()).collect();
if let Some(i) = widgets::dropdown(ui, "cg-rule", h.label(), &labels, ui.available_width() - 4.0) {
@@ -223,7 +337,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
widgets::drag_source(ui, &resp, || PanelDrag::paint(Paint::solid(*c)));
ui.painter().rect_filled(r, 0.0, c32(c));
if resp.on_hover_text(c.to_hex()).clicked() {
chosen = Some(*c);
chosen = Some(Paint::solid(*c));
}
}
ui.add_space(6.0);
@@ -241,7 +355,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
for (ci, v) in row.iter().enumerate() {
let r = Rect::from_min_size(rr.min + vec2(x(ci), 0.0), vec2(x(ci + 1) - x(ci) - gap, 17.0));
let resp = ui.interact(r, ui.scope_id().with(("cg-v", ri, ci)), Sense::click_and_drag());
widgets::drag_source(ui, &resp, || PanelDrag::paint(Paint::solid(*v)));
let paint = cell_paint(app, &g, ri, ci).unwrap_or_else(|| Paint::solid(*v));
widgets::drag_source(ui, &resp, || PanelDrag::paint(paint.clone()));
ui.painter().rect_filled(r, 0.0, c32(v));
if sel.contains(&(ri, ci)) {
ui.painter().rect_stroke(r.shrink(1.0), 0.0, egui::Stroke::new(1.0, egui::Color32::WHITE), egui::StrokeKind::Inside);
@@ -252,7 +367,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
if resp.on_hover_text(v.to_hex()).clicked() {
if !multi {
sel.clear();
chosen = Some(*v);
chosen = Some(paint);
}
match sel.iter().position(|s| *s == (ri, ci)) {
Some(i) => {
@@ -299,8 +414,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
save_group(app, &ctx);
}
});
if let Some(c) = chosen {
apply_click(app, ui, json!({"color": color_json(&c)}));
if let Some(p) = chosen {
apply_click(app, ui, paint_params(&p));
}
}
@@ -703,6 +818,184 @@ mod tests {
assert!(selected(&ctx).is_empty(), "the panel clears the selection");
}
/// A document with a selected rectangle and the spot color swatch "Ink", made the guide's base
/// as clicking it in the Swatches panel makes it, at `tint` (0..1) of the spot color.
fn spot_app(tint: f32) -> VectorcraftApp {
let mut app = app();
app.run("swatch.new", json!({"name": "Ink", "color": "#0066cc", "spot": true})).unwrap();
app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap();
app.run("paint.setFill", json!({"color": "#808080"})).unwrap();
let ink = app.session.active().unwrap().doc.global_color("Ink").unwrap();
choose_linked_base(&mut app, ink.tinted(tint), Some(("Ink".to_string(), tint)));
app
}
/// The selected art's fill: (the swatch it links to, its tint 0..1, its color).
fn fill_link(app: &VectorcraftApp) -> (Option<String>, f32, String) {
match crate::panels::current_paints(app).0 {
Paint::Solid { color, swatch, tint } => (swatch, tint, color.to_hex()),
other => panic!("a solid fill: {other:?}"),
}
}
/// The tint the cell `steps` right of the centre has with a base at `base` tint.
fn expected_tint(app: &VectorcraftApp, base: f32, steps: i32) -> f32 {
base * (1.0 - harmony::step_fraction(&app.ui.color_guide.clamped(), steps))
}
/// With a spot color base, a cell right of the centre in the base row of Tints/Shades paints the
/// art with a tint of the spot color, which follows an edit of the spot color; the shades, the
/// other rows, the other variation modes and a library limit give process colors.
#[test]
fn a_spot_color_base_gives_tints_of_that_spot_color() {
let mut app = spot_app(1.0);
let ctx = egui::Context::default();
frame(&mut app, &ctx);
let g = guide(&app, &ctx);
let c = g.centre();
let ink = app.session.active().unwrap().doc.global_color("Ink").unwrap();
assert_eq!(g.grid[0][c].to_hex(), ink.to_hex(), "the spot color in the centre");
let at = rect_of(&mut app, &ctx, ("cg-v", 0usize, c + 2)).center();
click(&mut app, &ctx, at);
let (swatch, tint, hex) = fill_link(&app);
assert_eq!(swatch.as_deref(), Some("Ink"), "a tint of the spot color");
let want = expected_tint(&app, 1.0, 2);
assert!((tint - want).abs() < 1e-4, "{tint} vs {want}");
assert_eq!(hex, g.grid[0][c + 2].to_hex(), "the color the cell shows");
assert_eq!(hex, ink.tinted(tint).to_hex());
// The painted tint follows an edit of the spot color, and so does the base.
app.run("swatch.edit", json!({"name": "Ink", "color": "#cc0000"})).unwrap();
let red = app.session.active().unwrap().doc.global_color("Ink").unwrap();
assert_eq!(fill_link(&app).2, red.tinted(tint).to_hex(), "the art follows the spot color");
assert_eq!(base_color(&app), red, "the base follows the spot color");
frame(&mut app, &ctx);
// Shades, another harmony row and the harmony strip are process colors.
for id in [("cg-v", 0usize, c - 1), ("cg-v", 1, c + 1)] {
let at = rect_of(&mut app, &ctx, id).center();
click(&mut app, &ctx, at);
assert_eq!(fill_link(&app).0, None, "{id:?}");
}
let at = rect_of(&mut app, &ctx, ("cg-h", 0usize)).center();
click(&mut app, &ctx, at);
assert_eq!(fill_link(&app).0, None, "the harmony strip");
// Warm/Cool and a library limit: process colors.
app.ui.color_guide.variation = Variation::WarmCool;
frame(&mut app, &ctx);
let at = rect_of(&mut app, &ctx, ("cg-v", 0usize, c + 1)).center();
click(&mut app, &ctx, at);
assert_eq!(fill_link(&app).0, None, "Warm/Cool");
app.ui.color_guide.variation = Variation::TintsShades;
app.run("ui.colorGuideLimit", json!({"library": "web-safe-216"})).unwrap();
frame(&mut app, &ctx);
let at = rect_of(&mut app, &ctx, ("cg-v", 0usize, c + 1)).center();
click(&mut app, &ctx, at);
assert_eq!(fill_link(&app).0, None, "limited to a library");
}
/// A base that is already a tint of the spot color gives lighter tints of it; a plain color with
/// the spot color's values, a deleted swatch and a swatch that is no longer a spot color give
/// process colors.
#[test]
fn a_tinted_spot_base_gives_lighter_tints_and_a_lost_link_gives_process_colors() {
let mut app = spot_app(0.5);
let ctx = egui::Context::default();
frame(&mut app, &ctx);
let c = guide(&app, &ctx).centre();
let cell = |app: &VectorcraftApp, ctx: &egui::Context, col| cell_paint(app, &guide(app, ctx), 0, col).unwrap();
let Paint::Solid { swatch, tint, .. } = cell(&app, &ctx, c + 1) else { panic!("a solid") };
assert_eq!(swatch.as_deref(), Some("Ink"));
let want = expected_tint(&app, 0.5, 1);
assert!((tint - want).abs() < 1e-4 && tint < 0.5, "{tint} vs {want}");
// The same values without the link.
choose_base(&mut app, Color::from_hex("#0066cc").unwrap());
assert_eq!(cell(&app, &ctx, c + 1), Paint::solid(guide(&app, &ctx).grid[0][c + 1]));
// The spot color made a process color, then deleted.
let link = Some(("Ink".to_string(), 1.0));
let ink = app.session.active().unwrap().doc.global_color("Ink").unwrap();
choose_linked_base(&mut app, ink, link.clone());
assert!(matches!(cell(&app, &ctx, c + 1), Paint::Solid { swatch: Some(_), .. }));
app.run("swatch.edit", json!({"name": "Ink", "spot": false, "global": false})).unwrap();
assert!(matches!(cell(&app, &ctx, c + 1), Paint::Solid { swatch: None, .. }), "no longer a spot color");
choose_linked_base(&mut app, ink, link.clone());
assert!(app.ui.color_guide_spot.is_none(), "a process swatch gives no spot base");
app.run("swatch.edit", json!({"name": "Ink", "spot": true})).unwrap();
choose_linked_base(&mut app, ink, link);
app.run("swatch.delete", json!({"name": "Ink"})).unwrap();
assert!(matches!(cell(&app, &ctx, c + 1), Paint::Solid { swatch: None, .. }), "a deleted swatch");
}
/// A spot color base stays linked to its swatch when Swatch Options renames it: the tints link to
/// the new name and follow an edit of it.
#[test]
fn a_renamed_spot_color_stays_the_base() {
let mut app = spot_app(1.0);
let ctx = egui::Context::default();
frame(&mut app, &ctx);
let c = guide(&app, &ctx).centre();
app.run("swatch.edit", json!({"name": "Ink", "newName": "Deep Ink"})).unwrap();
let Paint::Solid { swatch, .. } = cell_paint(&app, &guide(&app, &ctx), 0, c + 1).unwrap() else { panic!("a solid") };
assert_eq!(swatch.as_deref(), Some("Deep Ink"));
app.run("swatch.edit", json!({"name": "Deep Ink", "color": "#cc0000"})).unwrap();
let red = app.session.active().unwrap().doc.global_color("Deep Ink").unwrap();
assert_eq!(base_color(&app), red, "the base follows the renamed spot color");
}
/// Save Colors as Swatches and Save Color Group save a spot color base's tints as tint swatches
/// linked to it, beside process colors for the other cells, each in one undo step.
#[test]
fn saved_spot_tints_are_tint_swatches_of_the_spot_color() {
let mut app = spot_app(1.0);
let ctx = egui::Context::default();
frame(&mut app, &ctx);
let g = guide(&app, &ctx);
let c = g.centre();
let undo = app.session.doc().unwrap().history.undo.len();
set_pstate(&ctx, "cg-sel", vec![(0usize, c + 1), (0, c - 1), (0, c + 3)]);
save_selected(&mut app, &ctx);
let st = app.session.doc().unwrap();
assert_eq!(st.history.undo.len(), undo + 1, "one undo step");
let made: Vec<_> = st.doc.swatches[st.doc.swatches.len() - 3..].to_vec();
let tint = |w: &vectorcraft_color::Swatch| w.tint_of().map(|(b, t)| (b.to_string(), t));
assert_eq!(tint(&made[0]).map(|(b, _)| b).as_deref(), Some("Ink"));
assert!((tint(&made[0]).unwrap().1 - expected_tint(&app, 1.0, 1)).abs() < 1e-4);
assert_eq!(made[1].paint, Paint::solid(g.grid[0][c - 1]), "a shade is a process color");
assert_eq!(tint(&made[2]).map(|(b, _)| b).as_deref(), Some("Ink"));
assert!(made[0].name.starts_with("Ink ") && made[0].name.ends_with('%'), "{}", made[0].name);
// A group of the selected cells, in grid order.
set_pstate(&ctx, "cg-sel", vec![(1usize, c + 1), (0, c + 2)]);
save_group(&mut app, &ctx);
let group = app.session.doc().unwrap().doc.swatch_groups.last().cloned().unwrap();
assert_eq!(group.swatches.len(), 2);
assert_eq!(tint(&group.swatches[0]).map(|(b, _)| b).as_deref(), Some("Ink"), "the base row's tint");
assert_eq!(group.swatches[1].paint, Paint::solid(g.grid[1][c + 1]), "another row is a process color");
// The saved tints follow an edit of the spot color.
app.run("swatch.edit", json!({"name": "Ink", "color": "#cc0000"})).unwrap();
let d = &app.session.active().unwrap().doc;
let red = d.global_color("Ink").unwrap();
let first = d.swatch(&made[0].name).unwrap();
assert_eq!(first.paint.color(), Some(red.tinted(first.tint_of().unwrap().1)));
}
/// A spot color base's tint dragged from the guide carries the tint, and the Swatches panel makes
/// a tint swatch of it.
#[test]
fn a_dragged_spot_tint_becomes_a_tint_swatch() {
let mut app = spot_app(1.0);
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
guide_frame(&mut app, &ctx, vec![], 0.0, true, ("cg-h", 0usize));
let g = guide(&app, &ctx);
let c = g.centre();
let tile = |ctx: &egui::Context| ctx.read_response(egui::Id::unique(("swatch-tile", "Red"))).expect("the Red swatch is drawn").rect.center();
let held = drag_from(&mut app, &ctx, ("cg-v", 0, c + 1), Some(tile(&ctx)), 1.0, true);
let Some(PanelDrag::Paint { paint: Paint::Solid { swatch, tint, .. }, .. }) = held else { panic!("a solid paint: {held:?}") };
assert_eq!(swatch.as_deref(), Some("Ink"));
let newest = app.session.doc().unwrap().doc.swatches.last().cloned().expect("a swatch");
let (base, made) = newest.tint_of().unwrap_or_else(|| panic!("a tint swatch: {newest:?} {}", app.ui.status));
assert_eq!(base, "Ink");
assert!((made - tint).abs() < 1e-4, "{made} vs {tint}");
}
/// Every colour of the panel's guide.
fn shown(app: &VectorcraftApp, ctx: &egui::Context) -> Vec<String> {
let g = guide(app, ctx);
+4 -3
View File
@@ -190,13 +190,14 @@ fn swatch_params(e: &Entry) -> Option<Value> {
/// Apply a clicked swatch to the active proxy (Alt: the inactive one). An Alt-click on a color
/// swatch with a gradient stop selected recolors the stop as dropping the swatch on it does,
/// and with a freeform gradient point selected it recolors the point. A color swatch also becomes
/// the Color Guide's base color.
/// the Color Guide's base color, linked to the spot color it is or is a tint of.
fn apply(app: &mut VectorcraftApp, ui: &Ui, e: &Entry) {
let Some(params) = swatch_params(e) else { return };
if let Entry::Swatch { paint, .. } = e
if let Entry::Swatch { name, paint, .. } = e
&& let Some(c) = paint.color()
{
super::color_guide::choose_base(app, c);
let link = app.session.active().and_then(|st| st.doc.swatch_link(name));
super::color_guide::choose_linked_base(app, c, link);
}
if super::alt_held(ui)
&& let Some(c) = drag_of(e, vec![]).color()
@@ -178,6 +178,23 @@ fn a_clicked_color_swatch_becomes_the_color_guides_base() {
assert_eq!(base(&app), "#2050a0");
}
/// A clicked spot color swatch, or a tint swatch of one, becomes the Color Guide's base linked to
/// that spot color at the swatch's tint; a process color swatch clears the link.
#[test]
fn a_clicked_spot_color_swatch_becomes_a_linked_color_guide_base() {
let mut app = app();
let ctx = context();
app.run("swatch.new", json!({"name": "Ink", "color": "#0066cc", "spot": true})).unwrap();
app.run("swatch.new", json!({"swatch": "Ink", "tint": 40})).unwrap();
let spot = |app: &VectorcraftApp| app.ui.color_guide_spot.as_ref().map(|s| (s.swatch.clone(), (s.tint * 100.0).round()));
click_tile(&mut app, &ctx, "Ink", Modifiers::NONE, 0.0);
assert_eq!(spot(&app), Some(("Ink".to_string(), 100.0)));
click_tile(&mut app, &ctx, "Ink 40%", Modifiers::NONE, 2.0);
assert_eq!(spot(&app), Some(("Ink".to_string(), 40.0)), "a tint swatch: its tint of the spot color");
click_tile(&mut app, &ctx, "Red", Modifiers::NONE, 4.0);
assert_eq!(spot(&app), None, "a process color");
}
/// The hex colors of the stops of the selection's gradient fill, and its stroke's color.
fn stops_and_stroke(app: &VectorcraftApp) -> (Vec<String>, String) {
let (fill, stroke) = crate::panels::current_paints(app);
+5
View File
@@ -721,6 +721,10 @@ pub struct UiState {
/// saved.
#[serde(skip)]
pub color_guide_base: Option<vectorcraft_color::Color>,
/// Color Guide panel: the spot color swatch the base is a tint of, when it was chosen from one
/// ([`crate::panels::color_guide::SpotBase`]). Not saved.
#[serde(skip)]
pub color_guide_spot: Option<crate::panels::color_guide::SpotBase>,
/// Align panel: the Align To choice, Selection or Artboard, which Object → Align and the align
/// buttons follow ([`crate::panels::align::with_align_to`]).
#[serde(default, deserialize_with = "crate::panels::align::deserialize_align_to")]
@@ -1239,6 +1243,7 @@ impl Default for UiState {
flattener_preview: Default::default(),
color_guide_limit: String::new(),
color_guide_base: None,
color_guide_spot: None,
align_to: Default::default(),
align_spacing: 0.0,
color_mode: None,
+3 -1
View File
@@ -1072,7 +1072,9 @@ given and the swatch already has keeps its model, as does a stop color that `pai
gradient already has; a stop that names a swatch takes the swatch's color as it is, and `swatch.new` or `swatch.edit`
with `mode` converts a color into that mode only. RGB documents keep colors as given. Harmonies, Edit
Colors blends, inversions and Recolor Artwork keep each colour's model (a blend between models takes the document's).
`swatch.new {colors: [...]}` saves several colours as swatches in one undo step. `color.harmony {color, rule, steps?, variation?, amount?}` answers what the Color
`swatch.new {colors: [...]}` saves several colours as swatches in one undo step. An entry of `swatch.new {colors}` or
`swatch.newGroup {colors}` may be `{swatch, tint}`: a tint of a global or spot color below 100% becomes a tint swatch
("Name 40%") linked to it, as the Color Guide panel saves the tints of a spot color base. `color.harmony {color, rule, steps?, variation?, amount?}` answers what the Color
Guide panel shows: the harmony rule's colours, base first, and per colour its row of `2·steps+1` variations
(shades, cool or muted on the left, tints, warm or vivid on the right). With `limitTo` (a swatch library id or name,
or `"document"` for the document's swatches) every colour snaps to the library's nearest colour (ΔE 2000), as the
+1
View File
@@ -1751,6 +1751,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- **Sample Color from Screen:** an eyedropper button in the Color Picker and `ui.sampleScreenColor` (which can be given a key in Keyboard Shortcuts) pick a color anywhere on the screen with the system's sampler: `NSColorSampler` on macOS, the XDG desktop portal's [PickColor](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Screenshot.html) on Linux, a still copy of every monitor under a crosshair on Windows, and the EyeDropper API in browsers that have it. The color becomes the fill or the stroke as one undo step, or the Color Picker's color, converted from display sRGB into the working RGB space. On Linux, a session without a portal that has PickColor, a portal that does not return from the call within 25 seconds (VectorCraft's own limit) or leaves the bus before it answers, and a portal that ends the request another way each show a status message and end the wait. On Windows, the copy is read as sRGB, so the colors of HDR and wide-gamut displays are not converted; Escape, a click of another mouse button or switching to another window cancels (VectorCraft's own rules). The BSDs and other browsers have no sampler yet; the button is gray there.
- **Color Guide color groups:** with variation cells selected, the Color Guide's Save Color Group to Swatches button saves those cells as one swatch group, and with none selected it saves the harmony colors, as the [help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf) describes saving several selected variations together (printed page 135). The group takes the cells in grid order (row by row, left to right, each cell once), is named after the harmony rule and is one undo step; these are VectorCraft's own rules. A selection lasts until the base, the Color Guide Options, the variation mode, the harmony rule, the library limit or the colors the grid shows (for example after a new swatch while the guide is limited to the document's swatches) change.
- **Color Guide colors dragged to Swatches:** a variation cell dragged from the Color Guide onto the Swatches panel's list becomes a swatch of that color, as the [help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf) describes for saving variations as individual swatches (printed page 135). In VectorCraft a harmony strip color drags the same way, a drag carries only the grabbed color (the selected cells stay selected and the selection is not saved), it carries the color the cell shows (snapped to the Limit to Library colors), keeps the color's model and does not paint the selected art; the swatch follows the panel's rules for a dropped color (`swatch.new`, one undo step, a color that is already a swatch is added again under another name, a drop on a color group joins it). These are VectorCraft's own rules. Tests: `a_dragged_guide_color_carries_its_color_and_applies_nothing` and `a_guide_color_dragged_onto_the_swatches_panel_becomes_a_swatch` in `crates/ui-egui/src/panels/color_guide.rs`.
- **Color Guide tints of a spot color:** when the Color Guide's base is a spot color, or a tint of one, chosen in the Swatches panel, with the Color panel's tint slider or with the base chip, the cells right of the center in the base row of Tints/Shades are tints of that spot color: a click paints the art with the tint, a drag carries it, and Save Colors as Swatches and Save Color Group to Swatches make tint swatches ("Ink 60%") linked to the spot color, so they follow an edit of it. The [help page](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/color-guide-panel-overview.html) says spot colors are kept only on the right side of Tints/Shades and every other variation gives process colors. The tint percentages (the base's tint reduced by the share each cell goes toward white), the shades on the left staying process colors, a Limit to Library giving process colors, and a global process base keeping plain colors are VectorCraft's own rules. `swatch.new {colors}` and `swatch.newGroup {colors}` take `{swatch, tint}` entries. Tests: `a_spot_color_base_gives_tints_of_that_spot_color`, `a_tinted_spot_base_gives_lighter_tints_and_a_lost_link_gives_process_colors`, `a_renamed_spot_color_stays_the_base`, `saved_spot_tints_are_tint_swatches_of_the_spot_color`, `a_dragged_spot_tint_becomes_a_tint_swatch`, `a_clicked_spot_color_swatch_becomes_a_linked_color_guide_base`, `colors_entries_naming_a_spot_color_save_tint_swatches`.
- **Stroke visibility (#1253):** adding paint to a previously unpainted zero-width stroke restores the existing 1 pt default (`PaintDefaults::default`, `Appearance::set_stroke`), for the selected appearance item, the new-art defaults and Swap Fill/Stroke. Positive widths are kept; recoloring a painted zero-width stroke keeps its explicit zero. A real Eyedropper-to-new-shape sequence reproduces the zero-width inheritance. Five engine regressions cover creation, defaults, targeted items, preserved widths and one-step Undo/Redo (`crates/engine/tests/it/stroke_visibility.rs`).
- **Gradients:** lossless, validated gradient params; gradients follow rotate, reflect, shear, non-uniform scale and distortions; the Gradient tool edits the fill or stroke of the active proxy, type included; an interactive on-canvas annotator (move, length/angle, rotate, add/move/delete/duplicate stops, midpoints, a stop popover, Delete and arrow keys). The Gradient panel has the Fill/Stroke proxy, a gradient-swatch dropdown with Save to Swatches, midpoint locations, Alt-drag to copy or swap stops, swatch drops on the ramp and a stop eyedropper; copied appearances and graphic styles place gradients on each target's own bounds; gradient handles, both ends of a vector drawn on the art and the start of a clicked one snap as other drawn points do (path segments, construction guides and View › Snap to Glyph's guides included) and honour Constrain Angle. Gradient stops stay linked to global and spot swatches. Freeform gradients (points and lines) are edited on the canvas; radial gradients have an extent ellipse, an aspect handle and an off-centre focal point (SVG `fx`/`fy`, PDF two-point radials). A stroke's gradient runs within, along or across it. Object ▸ Expand turns gradients into N objects or a gradient mesh.
A gradient stop that loses its link to a spot swatch (the swatch deleted, a recolor or adjustment that unlinks it, a library gradient, or a library character style linked to a swatch the document lacks) keeps the color it shows at full tint and drops the process plates it printed with that ink, as a stop given a plain color does; this is VectorCraft's own rule. Evidence: `tests::mapping_links_drops_the_process_plates_of_unlinked_stops` in `crates/color`, `tests::linked_stops::deleting_a_spot_swatch_takes_the_process_plates_of_the_stops_it_unlinks` and `tests::library::library_stops_unlinked_from_their_swatch_keep_no_process_plates` in `crates/engine`.