mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 13:33:51 +00:00
Swatches: a library pattern keeps a global color whose name the document uses
When Add to Swatches brought a library pattern whose art links to a global or spot color, and the document had that name for another color, the pattern was relinked to the document's color. Adding the library's color then made a numbered copy that the pattern did not use. The color now comes in under a numbered name and the pattern links to it, as an added color does, and the check for a pattern already in the document compares it the same way.
This commit is contained in:
@@ -89,9 +89,11 @@ pub fn swatch_source(w: &Swatch) -> Option<Arc<Document>> {
|
||||
/// painted with it does: the same pattern there already is used, and a name another pattern or
|
||||
/// swatch has gets a number → the pattern's name in `d`, and the swatches the import added for
|
||||
/// the pattern's art: (the swatch's name in `lib`, its name in `d`), pattern swatches left out.
|
||||
/// A global or spot color whose name `d` gives another color comes in under a free name, as Add
|
||||
/// to Swatches adds such a color, so that the pattern keeps the library's colors.
|
||||
pub(crate) fn import(d: &mut Document, lib: &Document, name: &str) -> Result<(String, Vec<(String, String)>)> {
|
||||
let had: std::collections::HashSet<String> = d.swatches_iter().map(|w| w.name.clone()).collect();
|
||||
let imported = gather(lib, name).import_into(d, &SwatchChoices::default(), false)?;
|
||||
let imported = gather(lib, name).import_into(d, &SwatchChoices::add_all(), false)?;
|
||||
let from = |to: &str| {
|
||||
let renamed = imported.renamed.iter().find(|r| r["kind"] == "swatch" && r["to"] == to).and_then(|r| r["from"].as_str());
|
||||
renamed.unwrap_or(to).to_string()
|
||||
@@ -144,7 +146,7 @@ pub(crate) fn present_pattern(d: &Document, lib: &Document, name: &str) -> Optio
|
||||
return None;
|
||||
}
|
||||
let mut probe = d.clone();
|
||||
let imported = gathered.import_into(&mut probe, &SwatchChoices::default(), false).ok()?;
|
||||
let imported = gathered.import_into(&mut probe, &SwatchChoices::add_all(), false).ok()?;
|
||||
(imported.added == 0).then(|| imported_name(&imported, name))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user