mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-27 03:06:57 -06:00
M3.55: Edit Colors and Recolor Artwork also recolour gradient meshes, embedded images and pattern fills
One shared colour visitor (`colorcmds::Recolor`, used by Edit Colors, Recolor Artwork, the Blend
commands, the proxy Invert/Complement and Document Color Mode) maps solid colours, gradient stops
and text runs as before, and now also:
- gradient-mesh points (with fills); Blend grades meshes by their average and keeps their shading;
- embedded images' pixels (`includeImages?`, default on): the image becomes a recoloured copy under
a content key, the original stays for undo and other objects; linked images are left alone;
- the tiles of pattern fills and strokes (`includePatterns?`, default on): one recoloured copy per
pattern saved as a new pattern swatch ("Dots 2"), the original untouched.
Everything stays one undo step; only nodes that change are copied, in one walk of the tree.
- doc: `ImageBlob::map_rgb` (decode, map each distinct colour once, keep alpha, re-encode PNG),
`ImageBlob::content_key` (now also used by image import) and `ImageBlob::png`.
- `recolor.colors` lists mesh points and pattern tile colours too.
- patterncmds: `add_pattern` adds a pattern and its swatch (shared by Make Pattern and Save a Copy).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
1de1c6446f
commit
2edac7e317
@@ -219,6 +219,12 @@ fn next_pattern_name(d: &Document) -> String {
|
||||
(1..).map(|i| format!("New Pattern {i}")).find(|n| d.pattern(n).is_none() && d.swatch(n).is_none()).unwrap()
|
||||
}
|
||||
|
||||
/// Add pattern `def` and its swatch.
|
||||
pub(crate) fn add_pattern(d: &mut Document, def: PatternDef) {
|
||||
d.swatches.push(vectorcraft_color::Swatch { name: def.name.clone(), paint: pattern_paint(&def.name), global: false, spot: false });
|
||||
d.patterns.push(def);
|
||||
}
|
||||
|
||||
/// Fresh-id deep copies of `nodes`.
|
||||
fn copies(d: &mut Document, nodes: &[Arc<Node>]) -> Vec<Node> {
|
||||
nodes.iter().map(|n| d.reid(n)).collect()
|
||||
@@ -299,8 +305,7 @@ fn pattern_make(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
def.tile_type = tt;
|
||||
let c = def.tile.center();
|
||||
def.tile = Rect::from_center_size(c, (w.unwrap_or(def.tile.width()).max(1e-3), h.unwrap_or(def.tile.height()).max(1e-3)));
|
||||
d.patterns.push(def);
|
||||
d.swatches.push(vectorcraft_color::Swatch { name: name.clone(), paint: pattern_paint(&name), global: false, spot: false });
|
||||
add_pattern(d, def);
|
||||
if edit {
|
||||
enter_edit(d, sel, &name, None)?;
|
||||
}
|
||||
@@ -393,8 +398,7 @@ fn pattern_save_copy(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if def.size_tile_to_art {
|
||||
def.fit_tile_to_art();
|
||||
}
|
||||
d.patterns.push(def);
|
||||
d.swatches.push(vectorcraft_color::Swatch { name: name.clone(), paint: pattern_paint(&name), global: false, spot: false });
|
||||
add_pattern(d, def);
|
||||
Ok(name)
|
||||
})?;
|
||||
Ok(json!({ "name": name }))
|
||||
|
||||
Reference in New Issue
Block a user