mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 11:05:03 +00:00
Swatch libraries: a deleted color a found tint links to keeps its name
A numbered copy of a library tint found in the document now brings back the deleted global or spot color it links to, as a tint of the library tint's own name does. A deleted color that the call also picks is added before the other new swatches, so a pattern added earlier in the call cannot give its name to another color and leave the found tint linked to the wrong one. A picked pattern the document already has is probed once: the probe gives both its name in the document and the colors its art takes, instead of a presence check, a second import into a copy and a third presence check.
This commit is contained in:
@@ -145,11 +145,12 @@ pub(crate) fn imported_name(imported: &Imported, name: &str) -> String {
|
||||
}
|
||||
|
||||
/// The pattern of `d` that [`import`] of pattern `name` of library `lib` would use without adding
|
||||
/// anything to `d` → its name in `d`. A pattern whose art uses no other resource is compared as
|
||||
/// [`existing_pattern`] does. One whose art uses other resources, such as a pattern it is painted
|
||||
/// with, is imported into a copy of `d` as [`probe_import`] does, so that those resources are
|
||||
/// compared too.
|
||||
pub(crate) fn present_pattern(d: &Document, lib: &Document, name: &str) -> Option<String> {
|
||||
/// anything to `d` → its name in `d`, and the swatches of `d` that the art takes under another
|
||||
/// name than its own, as [`import`] lists them. A pattern whose art uses no other resource is
|
||||
/// compared as [`existing_pattern`] does. One whose art uses other resources, such as a pattern it
|
||||
/// is painted with, is imported into a copy of `d` as [`probe_import`] does, so that those
|
||||
/// resources are compared too.
|
||||
pub(crate) fn present_pattern(d: &Document, lib: &Document, name: &str) -> Option<(String, SwatchNames)> {
|
||||
let gathered = gather(lib, name);
|
||||
let only_pattern = gathered.patterns.len() == 1
|
||||
&& gathered.symbols.is_empty()
|
||||
@@ -161,14 +162,24 @@ pub(crate) fn present_pattern(d: &Document, lib: &Document, name: &str) -> Optio
|
||||
&& gathered.images.is_empty()
|
||||
&& gathered.graph_designs.is_empty();
|
||||
if only_pattern {
|
||||
return existing_pattern(d, lib, name);
|
||||
return existing_pattern(d, lib, name).map(|target| (target, vec![]));
|
||||
}
|
||||
// Without a pattern to reuse, the document is not copied.
|
||||
if !has_candidate(d, lib, name) {
|
||||
return None;
|
||||
}
|
||||
let (_, _, imported) = probe_import(d, lib, name, &gathered).ok()?;
|
||||
(imported.added == 0).then(|| imported_name(&imported, name))
|
||||
if imported.added != 0 {
|
||||
return None;
|
||||
}
|
||||
let took = imported
|
||||
.renamed
|
||||
.iter()
|
||||
.filter(|r| r["kind"] == "swatch")
|
||||
.filter_map(|r| Some((r["from"].as_str()?.to_string(), r["to"].as_str()?.to_string())))
|
||||
.filter(|(_, to)| d.swatches_iter().any(|w| w.name == *to))
|
||||
.collect();
|
||||
Some((imported_name(&imported, name), took))
|
||||
}
|
||||
|
||||
/// Whether `d` has a pattern that importing pattern `name` of `lib` can reuse: one under that name
|
||||
|
||||
Reference in New Issue
Block a user