mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-22 10:23:16 +01:00
Swatch libraries: library tints and gradients link to their colors in any order
A library tint or gradient whose global or spot color comes in under a numbered name now links to that copy whichever order the swatches are picked in, when the color was added by an earlier call, and when a pattern's art brought the color or took the document's copy of it. Adding the same tints again finds the ones added before. - Each tint's or gradient's color is looked up for itself before anything is added, past a process swatch of the same paint and past a color group of that name. A numbered copy that the library's own swatch of that name is stays that swatch's, and a new copy skips the library's other names. - A tint links to a global or spot color of the same kind only, and to a color this call picks rather than to a copy a pattern took. - Links are set as soon as the color's name is known. A tint waiting for a color that a pattern's art brings learns its name from an import into a copy, so the pattern does not add a second tint. - A swatch a pattern brought takes a picked swatch's place only when its colors link where the picked one's do. - A stop linked to the Registration swatch counts as linked. - library.use, Add to Swatches and the reuse check share one import probe (patternlib::probe_import), and the probed copy is kept instead of importing a second time. Docs: docs/mcp.md, docs/target-app-parity.md.
This commit is contained in:
1 parent
0575c1604a
commit
35e43f9cfe
7 files changed
+686
-104
No files matched your search
@@ -623,9 +623,8 @@ impl SwatchChoices {
|
||||
Some(v) => Ok(Self { all: one(v)?, by_name: BTreeMap::new() }),
|
||||
}
|
||||
}
|
||||
/// Add for every conflict, as a library pattern is added to a document: each global or spot
|
||||
/// color of its art whose name the document gives another color comes in under a numbered
|
||||
/// name, or as the document's numbered copy of that name with the same color.
|
||||
/// Add for every conflict: each pasted swatch whose name the document gives another color
|
||||
/// comes in renamed.
|
||||
pub(crate) fn add_all() -> Self {
|
||||
Self { all: SwatchChoice::Add, by_name: BTreeMap::new() }
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ use serde_json::{Map, Value, json};
|
||||
use vectorcraft_color::{Color, GradientPaint, Paint};
|
||||
use vectorcraft_doc::{Appearance, Node, NodeId, TextStyleDef};
|
||||
|
||||
use super::clipboard::SwatchChoices;
|
||||
use super::{CommandSpec, EngineError, Result, Session, always, bad, cmd, color_value, has_doc, ids_param, index_opt, ok, point_param, str_param};
|
||||
use crate::Clipboard;
|
||||
|
||||
@@ -1353,32 +1352,13 @@ fn use_pattern(s: &mut Session, data: &Value, stroke: bool) -> Result<String> {
|
||||
if clip.nodes.is_empty() {
|
||||
return Err(damaged());
|
||||
}
|
||||
// A global or spot color the pattern's art links to keeps the library's color: when the
|
||||
// document gives its name another color, it comes in under a numbered name ("Ink 2"), as
|
||||
// Add to Swatches brings a library pattern's colors.
|
||||
let mut choices = SwatchChoices::add_all();
|
||||
// The pattern's name in the document, worked out on a copy: nothing to add is no edit.
|
||||
// The pattern's name in the document, worked out on a copy: nothing to add is no edit. A global
|
||||
// or spot color the pattern's art links to keeps the library's color, as Add to Swatches brings
|
||||
// a library pattern's colors.
|
||||
let current = s.doc()?.doc.clone();
|
||||
let mut probe = (*current).clone();
|
||||
let mut imported = clip.import_into(&mut probe, &choices, false)?;
|
||||
let pattern_of = |i: &super::clipboard::resources::Imported| {
|
||||
i.renamed.iter().find(|r| r["kind"] == "pattern" && r["from"] == name.as_str()).and_then(|r| r["to"].as_str()).unwrap_or(&name).to_string()
|
||||
};
|
||||
// A pattern used before a color of its art kept the library's color has its art linked to the
|
||||
// document's own color of that name: when merging those colors reuses a pattern of the document
|
||||
// that keeping them would add again, they merge.
|
||||
if current.pattern(&pattern_of(&imported)).is_none()
|
||||
&& imported.renamed.iter().any(|r| r["kind"] == "swatch")
|
||||
&& super::patternlib::has_candidate(¤t, &doc, &name)
|
||||
{
|
||||
let mut merged = (*current).clone();
|
||||
let found = clip.import_into(&mut merged, &SwatchChoices::default(), false)?;
|
||||
if current.pattern(&pattern_of(&found)).is_some() {
|
||||
(choices, probe, imported) = (SwatchChoices::default(), merged, found);
|
||||
}
|
||||
}
|
||||
let (choices, probe, imported) = super::patternlib::probe_import(¤t, &doc, &name, &clip)?;
|
||||
drop(current);
|
||||
let target = pattern_of(&imported);
|
||||
let target = super::patternlib::imported_name(&imported, &name);
|
||||
let paint = vectorcraft_doc::pattern::pattern_paint(&target);
|
||||
// A pattern the document holds without a swatch (an imported SVG's) gets one.
|
||||
let has_swatch =
|
||||
|
||||
@@ -85,22 +85,29 @@ pub fn swatch_source(w: &Swatch) -> Option<Arc<Document>> {
|
||||
library_doc(b.id).filter(|d| d.pattern(pattern).is_some())
|
||||
}
|
||||
|
||||
/// Swatches as (the swatch's name in a library, its name in a document).
|
||||
pub(crate) type SwatchNames = Vec<(String, String)>;
|
||||
|
||||
/// Add pattern `name` of library `lib` to `d` with the resources its art uses, as pasting art
|
||||
/// 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.
|
||||
/// the pattern's art: (the swatch's name in `lib`, its name in `d`), pattern swatches left out,
|
||||
/// and the swatches `d` had that the art took under another name than its own, in the same form.
|
||||
/// 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. Those colors
|
||||
/// merge instead when that reuses a pattern of `d` that keeping them would add again
|
||||
/// ([`merge_reuses`]).
|
||||
pub(crate) fn import(d: &mut Document, lib: &Document, name: &str) -> Result<(String, Vec<(String, String)>)> {
|
||||
/// ([`probe_import`]).
|
||||
pub(crate) fn import(d: &mut Document, lib: &Document, name: &str) -> Result<(String, SwatchNames, SwatchNames)> {
|
||||
let gathered = gather(lib, name);
|
||||
let merge = !gathered.swatches.is_empty()
|
||||
&& has_candidate(d, lib, name)
|
||||
&& probe(d, &gathered, &SwatchChoices::add_all()).and_then(|with_add| merge_reuses(d, &gathered, name, &with_add)).is_some();
|
||||
let choices = if merge { SwatchChoices::default() } else { SwatchChoices::add_all() };
|
||||
let had: std::collections::HashSet<String> = d.swatches_iter().map(|w| w.name.clone()).collect();
|
||||
let imported = gathered.import_into(d, &choices, false)?;
|
||||
// Without a color to merge or a pattern to reuse, the document is not copied.
|
||||
let imported = if !gathered.swatches.is_empty() && has_candidate(d, lib, name) {
|
||||
let (_, probed, imported) = probe_import(d, lib, name, &gathered)?;
|
||||
*d = probed;
|
||||
imported
|
||||
} else {
|
||||
gathered.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()
|
||||
@@ -110,7 +117,14 @@ pub(crate) fn import(d: &mut Document, lib: &Document, name: &str) -> Result<(St
|
||||
.filter(|w| !had.contains(&w.name) && !matches!(w.paint, Paint::Pattern { .. }))
|
||||
.map(|w| (from(&w.name), w.name.clone()))
|
||||
.collect();
|
||||
Ok((imported_name(&imported, name), added))
|
||||
let reused = 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)| had.contains(to))
|
||||
.collect();
|
||||
Ok((imported_name(&imported, name), added, reused))
|
||||
}
|
||||
|
||||
/// Pattern `name` of `lib` with the resources its art uses, as an object painted with it is copied.
|
||||
@@ -119,8 +133,13 @@ fn gather(lib: &Document, name: &str) -> Clipboard {
|
||||
Clipboard::gather(lib, vec![user])
|
||||
}
|
||||
|
||||
/// The names in `lib` of the swatches that pattern `name` of `lib` brings with its art.
|
||||
pub(crate) fn brought_names(lib: &Document, name: &str) -> std::collections::HashSet<String> {
|
||||
gather(lib, name).swatches.into_iter().map(|w| w.name).collect()
|
||||
}
|
||||
|
||||
/// The name pattern `name` has in the document `imported` went into.
|
||||
fn imported_name(imported: &Imported, name: &str) -> String {
|
||||
pub(crate) fn imported_name(imported: &Imported, name: &str) -> String {
|
||||
let renamed = imported.renamed.iter().find(|r| r["kind"] == "pattern" && r["from"] == name).and_then(|r| r["to"].as_str());
|
||||
renamed.unwrap_or(name).to_string()
|
||||
}
|
||||
@@ -128,8 +147,8 @@ 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`, so that those resources are compared too, with the colors
|
||||
/// of its art merged when [`merge_reuses`] says so.
|
||||
/// 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> {
|
||||
let gathered = gather(lib, name);
|
||||
let only_pattern = gathered.patterns.len() == 1
|
||||
@@ -148,11 +167,8 @@ pub(crate) fn present_pattern(d: &Document, lib: &Document, name: &str) -> Optio
|
||||
if !has_candidate(d, lib, name) {
|
||||
return None;
|
||||
}
|
||||
let with_add = probe(d, &gathered, &SwatchChoices::add_all())?;
|
||||
if with_add.added == 0 {
|
||||
return Some(imported_name(&with_add, name));
|
||||
}
|
||||
merge_reuses(d, &gathered, name, &with_add).filter(|m| m.added == 0).map(|m| imported_name(&m, name))
|
||||
let (_, _, imported) = probe_import(d, lib, name, &gathered).ok()?;
|
||||
(imported.added == 0).then(|| imported_name(&imported, name))
|
||||
}
|
||||
|
||||
/// Whether `d` has a pattern that importing pattern `name` of `lib` can reuse: one under that name
|
||||
@@ -166,22 +182,25 @@ pub(crate) fn has_candidate(d: &Document, lib: &Document, name: &str) -> bool {
|
||||
d.patterns.iter().any(|p| copy(&p.name) && p.art.len() == def.art.len() && bare(p) == bare(def))
|
||||
}
|
||||
|
||||
/// What importing `gathered` into a copy of `d` with `choices` does.
|
||||
fn probe(d: &Document, gathered: &Clipboard, choices: &SwatchChoices) -> Option<Imported> {
|
||||
let mut probe = d.clone();
|
||||
gathered.import_into(&mut probe, choices, false).ok()
|
||||
}
|
||||
|
||||
/// When importing `gathered` (pattern `name`) into `d` with Add (`with_add`) adds the pattern again
|
||||
/// because a global or spot color of its art comes in numbered, while merging those colors reuses a
|
||||
/// pattern of `d`, what merging does. Such a pattern has its art linked to the document's own colors
|
||||
/// of those names, as pasting with Merge, or adding it from a library before, leaves it.
|
||||
fn merge_reuses(d: &Document, gathered: &Clipboard, name: &str, with_add: &Imported) -> Option<Imported> {
|
||||
/// Import `gathered`, which paints with pattern `name` of `lib`, into a copy of `d` → the swatch
|
||||
/// choices used, the copy and what the import did. A global or spot color whose name `d` gives
|
||||
/// another color comes in under a free name (Add). Those colors merge instead when Add would add
|
||||
/// the pattern again while merging reuses a pattern of `d`: such a pattern has its art linked to
|
||||
/// the document's own colors of those names, as pasting with Merge, or adding it from a library
|
||||
/// before, leaves it.
|
||||
pub(crate) fn probe_import(d: &Document, lib: &Document, name: &str, gathered: &Clipboard) -> Result<(SwatchChoices, Document, Imported)> {
|
||||
let reused = |i: &Imported| d.pattern(&imported_name(i, name)).is_some();
|
||||
if reused(with_add) || !with_add.renamed.iter().any(|r| r["kind"] == "swatch") {
|
||||
return None;
|
||||
let mut with_add = d.clone();
|
||||
let added = gathered.import_into(&mut with_add, &SwatchChoices::add_all(), false)?;
|
||||
if !reused(&added) && added.renamed.iter().any(|r| r["kind"] == "swatch") && has_candidate(d, lib, name) {
|
||||
let mut merged = d.clone();
|
||||
if let Ok(found) = gathered.import_into(&mut merged, &SwatchChoices::default(), false)
|
||||
&& reused(&found)
|
||||
{
|
||||
return Ok((SwatchChoices::default(), merged, found));
|
||||
}
|
||||
}
|
||||
probe(d, gathered, &SwatchChoices::default()).filter(reused)
|
||||
Ok((SwatchChoices::add_all(), with_add, added))
|
||||
}
|
||||
|
||||
/// The pattern of `d` that is pattern `name` of library `lib`: the same tile options and art under
|
||||
|
||||
@@ -49,7 +49,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Add to Swatches",
|
||||
["Window", "Swatch Libraries"],
|
||||
None,
|
||||
"{library: id or name, names?: [swatch or colour group names in the library] (default: all of it; a group comes as a colour group, a single swatch ungrouped), apply?: \"fill\"|\"stroke\" (also apply the first one to the selection and the defaults, as paint.setFill / paint.setStroke), focus?: true (with apply: false keeps the active proxy)} copy library swatches into the document as one undo step. A swatch the document already has (same name and paint, or a numbered copy of that name with the same color when the name has another color there) isn't added again; a name taken by another swatch gets a number (\"Clay 1 2\"). A pattern swatch brings its pattern, as pasting art painted with it does: the same pattern the document has is used, also when its art links to the document's own color of a name, and a name another pattern or swatch has gets a number; a global or spot color its art links to whose name the document gives another color comes in numbered, and the pattern links to it → {library, added: [names in the document, the colors patterns brought included], existing: [names already there], applied?: name}",
|
||||
"{library: id or name, names?: [swatch or colour group names in the library] (default: all of it; a group comes as a colour group, a single swatch ungrouped), apply?: \"fill\"|\"stroke\" (also apply the first one to the selection and the defaults, as paint.setFill / paint.setStroke), focus?: true (with apply: false keeps the active proxy)} copy library swatches into the document as one undo step. A swatch the document already has (same name and paint, or a numbered copy of that name with the same color when the name has another color there) isn't added again; a name taken by another swatch gets a number (\"Clay 1 2\"); a tint links to its color under the name that color has in the document. A pattern swatch brings its pattern, as pasting art painted with it does: the same pattern the document has is used, also when its art links to the document's own color of a name, and a name another pattern or swatch has gets a number; a global or spot color its art links to whose name the document gives another color comes in numbered, and the pattern links to it → {library, added: [names in the document, the colors patterns brought included], existing: [names already there], applied?: name}",
|
||||
has_doc,
|
||||
add
|
||||
),
|
||||
@@ -1011,6 +1011,89 @@ fn free_in(taken: &mut HashSet<String>, base: &str) -> String {
|
||||
name
|
||||
}
|
||||
|
||||
/// [`free_in`] for a library swatch's copy: a numbered name also skips the names `reserved` says
|
||||
/// the library's other swatches have, so that a later add finds the copy as this swatch's.
|
||||
fn free_copy_in(taken: &mut HashSet<String>, base: &str, reserved: impl Fn(&str) -> bool) -> String {
|
||||
let name = if taken.contains(base) {
|
||||
(2..).map(|i| format!("{base} {i}")).find(|n| !taken.contains(n) && !reserved(n)).unwrap_or_else(|| base.to_string())
|
||||
} else {
|
||||
base.to_string()
|
||||
};
|
||||
taken.insert(name.clone());
|
||||
name
|
||||
}
|
||||
|
||||
/// Link the swatches of `d` that `pending` names (document name, library swatch) to their colors
|
||||
/// under the names `links` gives them, for each whose colors `links` names now, in one pass over
|
||||
/// the document's swatches.
|
||||
fn settle(d: &mut vectorcraft_doc::Document, pending: &mut Vec<(String, &Swatch)>, links: &std::collections::HashMap<String, String>) {
|
||||
let mut done: std::collections::HashMap<String, Paint> = std::collections::HashMap::new();
|
||||
pending.retain(|(name, w)| {
|
||||
let all = all_linked(&w.paint, links);
|
||||
if all {
|
||||
done.insert(name.clone(), relinked(&w.paint, links));
|
||||
}
|
||||
!all
|
||||
});
|
||||
if !done.is_empty() {
|
||||
for x in d.swatches_iter_mut() {
|
||||
if let Some(paint) = done.get(&x.name) {
|
||||
x.paint = paint.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether paint `a` shows what paint `b` shows: the same color, or the same gradient with the
|
||||
/// colors its stops show, whichever swatches those colors link to.
|
||||
fn shows(a: &Paint, b: &Paint) -> bool {
|
||||
let unlinked = |p: &Paint| match p {
|
||||
Paint::Gradient(g) => {
|
||||
let mut g = g.clone();
|
||||
g.swatch = None;
|
||||
g.gradient.stops.iter_mut().for_each(|s| s.swatch = None);
|
||||
Paint::Gradient(g)
|
||||
}
|
||||
other => other.clone(),
|
||||
};
|
||||
match (a.color(), b.color()) {
|
||||
(Some(x), Some(y)) => x == y,
|
||||
_ => unlinked(a) == unlinked(b),
|
||||
}
|
||||
}
|
||||
|
||||
/// The names of the swatches the colors of paint `p` link to: a tint's base color, or the colors
|
||||
/// of a gradient's stops.
|
||||
fn linked_names(p: &Paint) -> Vec<&str> {
|
||||
match p {
|
||||
Paint::Solid { swatch: Some(b), .. } => vec![b.as_str()],
|
||||
Paint::Gradient(g) => g.gradient.stops.iter().filter_map(|s| s.swatch.as_deref()).collect(),
|
||||
_ => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
/// Paint `p` with each link to a swatch that `links` names changed to the name it maps to.
|
||||
fn relinked(p: &Paint, links: &std::collections::HashMap<String, String>) -> Paint {
|
||||
let mut out = p.clone();
|
||||
let swap = |name: &mut String| {
|
||||
if let Some(to) = links.get(name.as_str()) {
|
||||
*name = to.clone();
|
||||
}
|
||||
};
|
||||
match &mut out {
|
||||
Paint::Solid { swatch: Some(b), .. } => swap(b),
|
||||
Paint::Gradient(g) => g.gradient.stops.iter_mut().filter_map(|s| s.swatch.as_mut()).for_each(swap),
|
||||
_ => {}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Whether `links` names every swatch the colors of paint `p` link to, the built-in Registration
|
||||
/// swatch aside (every document has it under its own name).
|
||||
fn all_linked(p: &Paint, links: &std::collections::HashMap<String, String>) -> bool {
|
||||
linked_names(p).iter().all(|n| *n == REGISTRATION || links.contains_key(*n))
|
||||
}
|
||||
|
||||
fn add(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const C: &str = "swatch.library.add";
|
||||
let (info, lib) = library_param(s, p, C)?;
|
||||
@@ -1042,42 +1125,69 @@ fn add(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
copies.entry(base).or_default().push(w);
|
||||
}
|
||||
}
|
||||
// A numbered copy whose name a picked library swatch has stands for that swatch alone.
|
||||
let picked_names: HashSet<&str> = picked.iter().map(|(_, w)| w.name.as_str()).collect();
|
||||
// `paint` is `w`'s paint with a tint's base color under the name the base has in the document.
|
||||
let there = |w: &Swatch, paint: &Paint| match (&w.paint, &patterns) {
|
||||
// The library's swatches by name (the first of a name wins), looked up once.
|
||||
let mut lib_by_name: std::collections::HashMap<&str, &Swatch> = std::collections::HashMap::new();
|
||||
for w in lib.swatches.iter().chain(lib.groups.iter().flat_map(|g| &g.swatches)) {
|
||||
lib_by_name.entry(w.name.as_str()).or_insert(w);
|
||||
}
|
||||
let group_names: HashSet<&str> = d.swatch_groups.iter().map(|g| g.name.as_str()).collect();
|
||||
// A color whose name the document gives another color, or a color group, is the numbered copy
|
||||
// of it that an earlier add or a pattern's art brought in, when that copy is the same color. A
|
||||
// numbered copy whose name the library gives a swatch of the same paint stands for that swatch
|
||||
// alone, as adding that swatch finds it under its own name. Paints are compared with their
|
||||
// colors linked as `links` says ([`relinked`]).
|
||||
let same_kind = |x: &Swatch, w: &Swatch| x.global == w.global && x.spot == w.spot;
|
||||
let numbered = |w: &Swatch, paint: &Paint, links: &std::collections::HashMap<String, String>| {
|
||||
let c = copies.get(w.name.as_str())?;
|
||||
let own = |x: &Swatch| lib_by_name.get(x.name.as_str()).is_some_and(|l| relinked(&l.paint, links) == x.paint);
|
||||
let found = c.iter().find(|x| !own(x) && x.paint == *paint && same_kind(x, w));
|
||||
found.map(|x| x.name.clone())
|
||||
};
|
||||
let unlinked = std::collections::HashMap::new();
|
||||
// `paint` is `w`'s paint with the colors it links to as `links` has them in the document.
|
||||
let there = |w: &Swatch, paint: &Paint, links: &std::collections::HashMap<String, String>| match (&w.paint, &patterns) {
|
||||
(Paint::Pattern { pattern, .. }, Some(src)) => {
|
||||
patternlib::present_pattern(d, src, pattern).and_then(|target| library_pattern_swatch(d, w, &target))
|
||||
}
|
||||
_ => match by_name.get(w.name.as_str()) {
|
||||
Some(x) if x.paint == *paint => Some(w.name.clone()),
|
||||
// A color whose name the document gives another color is the numbered copy of it that
|
||||
// an earlier add or a pattern's art brought in, when that copy is the same color.
|
||||
Some(_) => copies
|
||||
.get(w.name.as_str())
|
||||
.and_then(|c| {
|
||||
c.iter().find(|x| !picked_names.contains(x.name.as_str()) && x.paint == *paint && x.global == w.global && x.spot == w.spot)
|
||||
})
|
||||
.map(|x| x.name.clone()),
|
||||
Some(_) => numbered(w, paint, links),
|
||||
None if group_names.contains(w.name.as_str()) => numbered(w, paint, links),
|
||||
None => (w.name == REGISTRATION && d.swatch(&w.name).is_some_and(|x| x.paint == *paint)).then(|| w.name.clone()),
|
||||
},
|
||||
};
|
||||
let picked_names: HashSet<&str> = picked.iter().map(|(_, w)| w.name.as_str()).collect();
|
||||
// The global or spot color of the document that library color `b` is: its own name, or the
|
||||
// numbered copy of it that adding `b` would find. While no color or color group has its name,
|
||||
// a numbered copy is looked for only when this call does not add `b` under its own name.
|
||||
let base_in_doc = |b: &Swatch| match by_name.get(b.name.as_str()) {
|
||||
Some(x) if x.paint == b.paint && same_kind(x, b) => Some(b.name.clone()),
|
||||
Some(_) => numbered(b, &b.paint, &unlinked),
|
||||
None if group_names.contains(b.name.as_str()) || !picked_names.contains(b.name.as_str()) => numbered(b, &b.paint, &unlinked),
|
||||
None => None,
|
||||
};
|
||||
// The library's global and spot colors that the picked tints and gradients link to, with the
|
||||
// name each has in the document: library name → document name. Each is looked up for itself,
|
||||
// whether or not this call picks it, once.
|
||||
let mut base_names: std::collections::HashMap<String, String> = std::collections::HashMap::new();
|
||||
let mut looked_up: HashSet<&str> = HashSet::new();
|
||||
for (_, w) in &picked {
|
||||
for base in linked_names(&w.paint) {
|
||||
if !looked_up.insert(base) {
|
||||
continue;
|
||||
}
|
||||
if let Some(n) = lib_by_name.get(base).filter(|b| b.global || b.spot).and_then(|b| base_in_doc(b)) {
|
||||
base_names.insert(base.to_string(), n);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Library name → the name of the document's swatch.
|
||||
let mut existing: Vec<(String, String)> = vec![];
|
||||
let mut fresh = vec![];
|
||||
for &(group, w) in &picked {
|
||||
// A tint of a color the document has under a numbered name is compared linked to that name.
|
||||
let relinked = match &w.paint {
|
||||
Paint::Solid { swatch: Some(base), .. } => existing.iter().find(|(l, n)| l == base && n != base).map(|(_, n)| {
|
||||
let mut paint = w.paint.clone();
|
||||
if let Paint::Solid { swatch: Some(b), .. } = &mut paint {
|
||||
*b = n.clone();
|
||||
}
|
||||
paint
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
match there(w, relinked.as_ref().unwrap_or(&w.paint)) {
|
||||
// A tint or gradient is compared with its colors linked to the names they have here.
|
||||
let paint = relinked(&w.paint, &base_names);
|
||||
match there(w, &paint, &base_names) {
|
||||
Some(name) => existing.push((w.name.clone(), name)),
|
||||
None => fresh.push((group, w)),
|
||||
}
|
||||
@@ -1087,8 +1197,14 @@ fn add(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// library swatch of this call stands for are added too; they are listed after the others and
|
||||
// are never the one `apply` paints with.
|
||||
let mut brought_alone: Vec<(String, String)> = vec![];
|
||||
// Library name → the name of the document's swatch for it, for the tints added here.
|
||||
let mut links: std::collections::HashMap<String, String> = existing.iter().cloned().collect();
|
||||
// Library name → the name of the document's global or spot color for it, which the tints and
|
||||
// gradients added here link to: one that is global or spot as the library color is.
|
||||
let base_of = |l: &str, n: &str| {
|
||||
let (Some(w), Some(x)) = (lib_by_name.get(l), by_name.get(n)) else { return false };
|
||||
(x.global || x.spot) && same_kind(x, w)
|
||||
};
|
||||
let mut links: std::collections::HashMap<String, String> = existing.iter().filter(|(l, n)| base_of(l, n)).cloned().collect();
|
||||
links.extend(base_names);
|
||||
let added: Vec<(String, String)> = if fresh.is_empty() {
|
||||
vec![]
|
||||
} else {
|
||||
@@ -1104,13 +1220,40 @@ fn add(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// The swatches the patterns imported in this call brought with their art: (library
|
||||
// name, document name).
|
||||
let mut brought: Vec<(String, String)> = vec![];
|
||||
// The swatches added here with a link `links` did not name yet: (document name, library
|
||||
// swatch).
|
||||
let mut pending: Vec<(String, &Swatch)> = vec![];
|
||||
for (group, w) in fresh {
|
||||
let (name, sw) = if let (Paint::Pattern { pattern, .. }, Some(src)) = (&w.paint, &patterns) {
|
||||
// The pattern comes with its swatch; a pattern the document has without one
|
||||
// gets one. The swatch a pattern that comes in brings is named after the pattern:
|
||||
// it takes the library swatch's name and color group instead.
|
||||
// The tints and gradients added so far link to their colors first, so that the
|
||||
// pattern's art finds them. A color they wait for that the pattern's art brings
|
||||
// is named by importing the pattern into a copy first.
|
||||
let brings = if pending.is_empty() { Default::default() } else { patternlib::brought_names(src, pattern) };
|
||||
let waited = |n: &&str| !links.contains_key(*n) && brings.contains(*n);
|
||||
if pending.iter().any(|(_, w)| linked_names(&w.paint).iter().any(waited)) {
|
||||
let mut probe = d.clone();
|
||||
let (_, colors, took) = patternlib::import(&mut probe, src, pattern)?;
|
||||
for (from, to) in colors.iter().chain(took.iter().filter(|(from, _)| !picked_names.contains(from.as_str()))) {
|
||||
if probe.swatch(to).is_some_and(|x| x.global || x.spot) {
|
||||
links.entry(from.clone()).or_insert_with(|| to.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
settle(d, &mut pending, &links);
|
||||
let had = taken_names(d);
|
||||
let (target, colors) = patternlib::import(d, src, pattern)?;
|
||||
let (target, colors, took) = patternlib::import(d, src, pattern)?;
|
||||
// A global or spot color the pattern brought, or took from the document under
|
||||
// a numbered name, is the one the library's tints of it link to, unless the
|
||||
// document already has one for it. A color this call picks is added under
|
||||
// its own name instead of the one the pattern took.
|
||||
for (from, to) in colors.iter().chain(took.iter().filter(|(from, _)| !picked_names.contains(from.as_str()))) {
|
||||
if d.swatch(to).is_some_and(|x| x.global || x.spot) {
|
||||
links.entry(from.clone()).or_insert_with(|| to.clone());
|
||||
}
|
||||
}
|
||||
brought.extend(colors);
|
||||
if let Some(name) = library_pattern_swatch(d, w, &target).filter(|n| had.contains(n)) {
|
||||
reused.push((w.name.clone(), name));
|
||||
@@ -1137,9 +1280,20 @@ fn add(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
} else {
|
||||
// A color a pattern added earlier in this call brought with its art is that
|
||||
// swatch when it shows the library swatch's color: it moves to the library
|
||||
// swatch's place.
|
||||
let same =
|
||||
|to: &str| d.swatch(to).is_some_and(|x| x.paint.color() == w.paint.color() && x.global == w.global && x.spot == w.spot);
|
||||
// swatch's place, when its colors link where the library swatch's do: to the
|
||||
// names `links` gives them, and not elsewhere for a color this call has yet to
|
||||
// add.
|
||||
let fits = |x: &Paint| {
|
||||
let (ours, theirs) = (linked_names(&w.paint), linked_names(x));
|
||||
ours.len() == theirs.len()
|
||||
&& ours.iter().zip(&theirs).all(|(l, t)| match links.get(*l) {
|
||||
Some(to) => to == t,
|
||||
None => !picked_names.contains(l),
|
||||
})
|
||||
};
|
||||
let same = |to: &str| {
|
||||
d.swatch(to).is_some_and(|x| shows(&x.paint, &w.paint) && x.global == w.global && x.spot == w.spot && fits(&x.paint))
|
||||
};
|
||||
let at = brought.iter().position(|(from, to)| *from == w.name && same(to));
|
||||
let moved = at.map(|i| brought.swap_remove(i).1).and_then(|n| {
|
||||
let i = d.swatches.iter().position(|x| x.name == n)?;
|
||||
@@ -1148,20 +1302,23 @@ fn add(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
match moved {
|
||||
Some(sw) => (sw.name.clone(), sw),
|
||||
None => {
|
||||
let name = free_in(&mut taken, &w.name);
|
||||
let mut sw = Swatch { name: name.clone(), ..(*w).clone() };
|
||||
// A tint links to its base color under the name the base has in the
|
||||
// document.
|
||||
if let Paint::Solid { swatch: Some(base), .. } = &mut sw.paint
|
||||
&& let Some(to) = links.get(base.as_str())
|
||||
{
|
||||
*base = to.clone();
|
||||
// A numbered copy skips the names of the library's other swatches,
|
||||
// which a later add looks up as theirs.
|
||||
let name = free_copy_in(&mut taken, &w.name, |n| lib_by_name.contains_key(n));
|
||||
// A tint or gradient links to its colors under the names they have in
|
||||
// the document; a color that comes in later in this call is linked
|
||||
// when it has come in.
|
||||
let paint = relinked(&w.paint, &links);
|
||||
if !all_linked(&w.paint, &links) {
|
||||
pending.push((name.clone(), w));
|
||||
}
|
||||
(name, sw)
|
||||
(name.clone(), Swatch { name, paint, ..(*w).clone() })
|
||||
}
|
||||
}
|
||||
};
|
||||
links.insert(w.name.clone(), name.clone());
|
||||
if sw.global || sw.spot {
|
||||
links.insert(w.name.clone(), name.clone());
|
||||
}
|
||||
match group {
|
||||
Some(g) => {
|
||||
let found = placed.iter().find(|(n, _)| *n == g).map(|&(_, i)| i);
|
||||
@@ -1182,6 +1339,14 @@ fn add(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
out.push((w.name.clone(), name));
|
||||
}
|
||||
let later: std::collections::HashMap<String, Paint> = pending.into_iter().map(|(name, w)| (name, relinked(&w.paint, &links))).collect();
|
||||
if !later.is_empty() {
|
||||
for x in d.swatches_iter_mut() {
|
||||
if let Some(paint) = later.get(&x.name) {
|
||||
x.paint = paint.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok((out, reused, brought))
|
||||
})?;
|
||||
existing.extend(reused);
|
||||
|
||||
@@ -660,6 +660,153 @@ fn a_library_tint_follows_its_color_to_its_numbered_name() {
|
||||
assert_eq!((&again["added"], &again["existing"]), (&json!([]), &json!(["Ink 2", "Ink half"])), "{again}");
|
||||
}
|
||||
|
||||
/// A library tint picked before its global color still follows the color to its numbered name.
|
||||
#[test]
|
||||
fn a_library_tint_picked_before_its_color_follows_it_to_its_numbered_name() {
|
||||
let mut s = session();
|
||||
let id = tinted_ink_library_and_a_red_ink(&mut s);
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink half", "Ink"]}));
|
||||
assert_eq!(r["added"], json!(["Ink half", "Ink 2"]), "{r}");
|
||||
assert_eq!(tint_base(&s, "Ink half").as_deref(), Some("Ink 2"), "{r}");
|
||||
let again = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink half", "Ink"]}));
|
||||
assert_eq!((&again["added"], &again["existing"]), (&json!([]), &json!(["Ink half", "Ink 2"])), "{again}");
|
||||
}
|
||||
|
||||
/// A library tint added without its global color finds the numbered copy an earlier add brought.
|
||||
#[test]
|
||||
fn a_library_tint_added_alone_finds_its_colors_numbered_copy() {
|
||||
let mut s = session();
|
||||
let id = tinted_ink_library_and_a_red_ink(&mut s);
|
||||
run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink"]}));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink half"]}));
|
||||
assert_eq!(r["added"], json!(["Ink half"]), "{r}");
|
||||
assert_eq!(tint_base(&s, "Ink half").as_deref(), Some("Ink 2"), "{r}");
|
||||
let again = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink half"]}));
|
||||
assert_eq!((&again["added"], &again["existing"]), (&json!([]), &json!(["Ink half"])), "{again}");
|
||||
}
|
||||
|
||||
/// A library tint added alone links to the numbered copy of its own color, not to another library
|
||||
/// color's copy of the same paint.
|
||||
#[test]
|
||||
fn a_library_tint_added_alone_skips_another_library_colors_copy() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink 2", "color": "#0000ff", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink half", "swatch": "Ink", "tint": 50}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Inks.vectorcraft"}))["library"].clone();
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#ff0000", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink 2", "color": "#0000ff", "global": true}));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink", "Ink 2"]}));
|
||||
assert_eq!(r["added"], json!(["Ink 3"]), "{r}");
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink half"]}));
|
||||
assert_eq!(tint_base(&s, "Ink half").as_deref(), Some("Ink 3"), "{r}");
|
||||
}
|
||||
|
||||
/// A library tint added alone finds its color's numbered copy when a color group of the document
|
||||
/// has the color's name.
|
||||
#[test]
|
||||
fn a_library_tint_finds_its_colors_copy_beside_a_group_of_its_name() {
|
||||
let mut s = session();
|
||||
let id = tinted_ink_library_and_a_red_ink(&mut s);
|
||||
run(&mut s, "swatch.delete", json!({"names": ["Ink"]}));
|
||||
run(&mut s, "swatch.newGroup", json!({"name": "Ink", "colors": ["#123456"]}));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink"]}));
|
||||
assert_eq!(r["added"], json!(["Ink 2"]), "{r}");
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink half"]}));
|
||||
assert_eq!(tint_base(&s, "Ink half").as_deref(), Some("Ink 2"), "{r}");
|
||||
}
|
||||
|
||||
/// A library pattern whose art uses a tint of a library color added earlier in the same call
|
||||
/// does not bring a second copy of that tint, also when the call does not pick the color.
|
||||
#[test]
|
||||
fn a_pattern_after_its_tint_in_one_call_does_not_copy_the_tint() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink half", "swatch": "Ink", "tint": 50}));
|
||||
let dot = run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 6, "height": 6}))["id"].clone();
|
||||
run(&mut s, "paint.setFill", json!({"swatch": "Ink", "tint": 50, "ids": [dot]}));
|
||||
run(&mut s, "paint.setStroke", json!({"none": true, "ids": [dot]}));
|
||||
run(&mut s, "select.set", json!({"ids": [dot]}));
|
||||
run(&mut s, "object.pattern.make", json!({"name": "Squares", "width": 8, "height": 8}));
|
||||
run(&mut s, "object.pattern.done", json!({}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Squares.vectorcraft"}))["library"].clone();
|
||||
for names in [json!(["Ink", "Ink half", "Squares"]), json!(["Ink half", "Ink", "Squares"]), json!(["Ink half", "Squares"])] {
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#ff0000", "global": true}));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": names}));
|
||||
assert_eq!(named_after(&s, "Ink half"), ["Ink half"], "{names}: {r}");
|
||||
assert_eq!(tint_base(&s, "Ink half").as_deref(), Some("Ink 2"), "{names}: {r}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A library color added under a numbered name skips the names of the library's other swatches,
|
||||
/// so adding it again finds that copy.
|
||||
#[test]
|
||||
fn a_library_colors_copy_skips_the_librarys_other_names() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink 2", "color": "#0000ff", "global": true}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Inks.vectorcraft"}))["library"].clone();
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#ff0000", "global": true}));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink"]}));
|
||||
assert_eq!(r["added"], json!(["Ink 3"]), "{r}");
|
||||
let again = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink"]}));
|
||||
assert_eq!((&again["added"], &again["existing"]), (&json!([]), &json!(["Ink 3"])), "{again}");
|
||||
}
|
||||
|
||||
/// A library tint links to a global color even when the document has a process color of the same
|
||||
/// name and paint, which the picked library color matches: the pattern's art brings the global one.
|
||||
#[test]
|
||||
fn a_library_tint_links_to_the_global_color_a_pattern_brought() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink half", "swatch": "Ink", "tint": 50}));
|
||||
let dot = run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 6, "height": 6}))["id"].clone();
|
||||
run(&mut s, "paint.setFill", json!({"swatch": "Ink", "ids": [dot]}));
|
||||
run(&mut s, "paint.setStroke", json!({"none": true, "ids": [dot]}));
|
||||
run(&mut s, "select.set", json!({"ids": [dot]}));
|
||||
run(&mut s, "object.pattern.make", json!({"name": "Tiles", "width": 8, "height": 8}));
|
||||
run(&mut s, "object.pattern.done", json!({}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Tiles.vectorcraft"}))["library"].clone();
|
||||
for names in [json!(["Ink", "Tiles", "Ink half"]), json!(["Ink", "Ink half", "Tiles"])] {
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff"}));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": names}));
|
||||
let base = tint_base(&s, "Ink half").unwrap_or_default();
|
||||
assert!(doc(&s).swatch(&base).is_some_and(|w| w.global), "{names}: {r}");
|
||||
let again = run(&mut s, "swatch.library.add", json!({"library": id, "names": names}));
|
||||
assert_eq!(named_after(&s, "Ink half"), ["Ink half"], "{names}: {again}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A library tint added with a pattern whose art brought the tint's global color under a numbered
|
||||
/// name is a tint of that numbered color.
|
||||
#[test]
|
||||
fn a_library_tint_follows_the_color_a_pattern_brought() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink half", "swatch": "Ink", "tint": 50}));
|
||||
let dot = run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 6, "height": 6}))["id"].clone();
|
||||
run(&mut s, "paint.setFill", json!({"swatch": "Ink", "ids": [dot]}));
|
||||
run(&mut s, "paint.setStroke", json!({"none": true, "ids": [dot]}));
|
||||
run(&mut s, "select.set", json!({"ids": [dot]}));
|
||||
run(&mut s, "object.pattern.make", json!({"name": "Tiles", "width": 8, "height": 8}));
|
||||
run(&mut s, "object.pattern.done", json!({}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Tiles.vectorcraft"}))["library"].clone();
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#ff0000", "global": true}));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Tiles", "Ink half"]}));
|
||||
assert!(r["added"].as_array().is_some_and(|a| a.contains(&json!("Ink 2"))), "{r}");
|
||||
assert_eq!(tint_base(&s, "Ink half").as_deref(), Some("Ink 2"), "{r}");
|
||||
}
|
||||
|
||||
/// A numbered copy of a color's name that the library also has as a swatch of its own stands for
|
||||
/// that swatch alone, even when both library swatches have its color.
|
||||
#[test]
|
||||
@@ -676,6 +823,237 @@ fn a_numbered_copy_the_library_also_names_is_not_shared() {
|
||||
assert_eq!((&r["added"], &r["existing"]), (&json!(["Ink 3"]), &json!(["Ink 2"])), "{r}");
|
||||
}
|
||||
|
||||
/// A numbered copy of a color's name that the library also has as a swatch of another color is
|
||||
/// still the copy of the color: adding the color after a pattern brought it under that name adds
|
||||
/// no other copy.
|
||||
#[test]
|
||||
fn a_numbered_copy_named_like_another_library_color_is_found() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink 2", "color": "#00ff00", "global": true}));
|
||||
let dot = run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 6, "height": 6}))["id"].clone();
|
||||
run(&mut s, "paint.setFill", json!({"swatch": "Ink", "ids": [dot]}));
|
||||
run(&mut s, "paint.setStroke", json!({"none": true, "ids": [dot]}));
|
||||
run(&mut s, "select.set", json!({"ids": [dot]}));
|
||||
run(&mut s, "object.pattern.make", json!({"name": "Tiles", "width": 8, "height": 8}));
|
||||
run(&mut s, "object.pattern.done", json!({}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Tiles.vectorcraft"}))["library"].clone();
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#ff0000", "global": true}));
|
||||
run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Tiles"]}));
|
||||
assert_eq!(named_after(&s, "Ink"), ["Ink", "Ink 2"]);
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink"]}));
|
||||
assert_eq!((&r["added"], &r["existing"]), (&json!([]), &json!(["Ink 2"])), "{r}");
|
||||
}
|
||||
|
||||
/// A library tint picked before its global color links to the color under the name it comes in
|
||||
/// with, not to a numbered copy of the same color when the document has none of the color's name.
|
||||
#[test]
|
||||
fn a_library_tint_links_to_its_color_under_the_name_it_comes_in_with() {
|
||||
let mut s = session();
|
||||
let id = tinted_ink_library_and_a_red_ink(&mut s);
|
||||
run(&mut s, "swatch.delete", json!({"names": ["Ink"]}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink 2", "color": "#0000ff", "global": true}));
|
||||
for names in [json!(["Ink half", "Ink"]), json!(["Ink", "Ink half"])] {
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": names}));
|
||||
assert_eq!(tint_base(&s, "Ink half").as_deref(), Some("Ink"), "{names}: {r}");
|
||||
run(&mut s, "swatch.delete", json!({"names": ["Ink half", "Ink"]}));
|
||||
}
|
||||
}
|
||||
|
||||
/// A library tint of a spot color links to the spot color a pattern's art brought, not to the
|
||||
/// document's global process color of the same name and paint.
|
||||
#[test]
|
||||
fn a_library_spot_tint_links_to_the_spot_color_not_a_process_one() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "spot": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink half", "swatch": "Ink", "tint": 50}));
|
||||
let dot = run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 6, "height": 6}))["id"].clone();
|
||||
run(&mut s, "paint.setFill", json!({"swatch": "Ink", "ids": [dot]}));
|
||||
run(&mut s, "paint.setStroke", json!({"none": true, "ids": [dot]}));
|
||||
run(&mut s, "select.set", json!({"ids": [dot]}));
|
||||
run(&mut s, "object.pattern.make", json!({"name": "Tiles", "width": 8, "height": 8}));
|
||||
run(&mut s, "object.pattern.done", json!({}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Tiles.vectorcraft"}))["library"].clone();
|
||||
for names in [json!(["Ink", "Tiles", "Ink half"]), json!(["Ink half", "Tiles"])] {
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": names}));
|
||||
let base = tint_base(&s, "Ink half").unwrap_or_default();
|
||||
assert!(doc(&s).swatch(&base).is_some_and(|w| w.spot), "{names}: {r}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A numbered copy that the library's own swatch of that name is (the same paint, whatever its
|
||||
/// kind) is not also taken for the library color it is numbered after.
|
||||
#[test]
|
||||
fn a_numbered_copy_the_library_has_by_paint_is_not_shared() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink 2", "color": "#0000ff"}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Inks.vectorcraft"}))["library"].clone();
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#ff0000", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink 2", "color": "#0000ff", "global": true}));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink", "Ink 2"]}));
|
||||
assert_eq!((&r["added"], &r["existing"]), (&json!(["Ink 3"]), &json!(["Ink 2"])), "{r}");
|
||||
}
|
||||
|
||||
/// A library tint added with a pattern whose art took the document's numbered copy of the tint's
|
||||
/// color is a tint of that copy.
|
||||
#[test]
|
||||
fn a_library_tint_follows_the_numbered_color_a_pattern_took() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink half", "swatch": "Ink", "tint": 50}));
|
||||
let dot = run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 6, "height": 6}))["id"].clone();
|
||||
run(&mut s, "paint.setFill", json!({"swatch": "Ink", "ids": [dot]}));
|
||||
run(&mut s, "paint.setStroke", json!({"none": true, "ids": [dot]}));
|
||||
run(&mut s, "select.set", json!({"ids": [dot]}));
|
||||
run(&mut s, "object.pattern.make", json!({"name": "Tiles", "width": 8, "height": 8}));
|
||||
run(&mut s, "object.pattern.done", json!({}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Tiles.vectorcraft"}))["library"].clone();
|
||||
for names in [json!(["Tiles", "Ink half"]), json!(["Ink half", "Tiles"])] {
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink 2", "color": "#0000ff", "global": true}));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": names}));
|
||||
assert_eq!(named_after(&s, "Ink"), ["Ink 2"], "{names}: {r}");
|
||||
assert_eq!(tint_base(&s, "Ink half").as_deref(), Some("Ink 2"), "{names}: {r}");
|
||||
let again = run(&mut s, "swatch.library.add", json!({"library": id, "names": names}));
|
||||
assert_eq!(named_after(&s, "Ink half"), ["Ink half"], "{names}: {again}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A numbered copy that the library's own tint of that name is, once its color is linked as the
|
||||
/// document has it, is not also taken for the library tint it is numbered after.
|
||||
#[test]
|
||||
fn a_numbered_tint_the_library_has_is_not_shared() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Half", "swatch": "Ink", "tint": 50}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Half 2", "swatch": "Ink", "tint": 50}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Inks.vectorcraft"}))["library"].clone();
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#ff0000", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Half", "color": "#00ff00"}));
|
||||
run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink", "Half 2"]}));
|
||||
assert_eq!(tint_base(&s, "Half 2").as_deref(), Some("Ink 2"));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Half", "Half 2"]}));
|
||||
assert_eq!(r["existing"], json!(["Half 2"]), "{r}");
|
||||
assert_eq!(r["added"].as_array().map(Vec::len), Some(1), "{r}");
|
||||
}
|
||||
|
||||
/// Adding a library color the document has as a process color of the same paint, with its tint,
|
||||
/// again adds no other copy of the tint.
|
||||
#[test]
|
||||
fn a_library_tint_of_a_color_the_document_has_as_process_is_added_once() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink half", "swatch": "Ink", "tint": 50}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Inks.vectorcraft"}))["library"].clone();
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff"}));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink", "Ink half"]}));
|
||||
let before = named_after(&s, "Ink half");
|
||||
let again = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Ink", "Ink half"]}));
|
||||
assert_eq!(named_after(&s, "Ink half"), before, "{r} then {again}");
|
||||
}
|
||||
|
||||
/// A library tint added with a pattern the document already has (pasted with Merge, so it brings
|
||||
/// no colors), through the pattern's own swatch or another library swatch of it, is added once,
|
||||
/// however often the two are added.
|
||||
#[test]
|
||||
fn a_library_tint_with_a_pattern_the_document_has_is_added_once() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink half", "swatch": "Ink", "tint": 50}));
|
||||
let dot = run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 6, "height": 6}))["id"].clone();
|
||||
run(&mut s, "paint.setFill", json!({"swatch": "Ink", "ids": [dot]}));
|
||||
run(&mut s, "paint.setStroke", json!({"none": true, "ids": [dot]}));
|
||||
run(&mut s, "select.set", json!({"ids": [dot]}));
|
||||
run(&mut s, "object.pattern.make", json!({"name": "Squares", "width": 8, "height": 8}));
|
||||
run(&mut s, "object.pattern.done", json!({}));
|
||||
s.edit("Dots", |d, _| {
|
||||
let paint = vectorcraft_doc::pattern::pattern_paint("Squares");
|
||||
d.swatches.push(vectorcraft_color::Swatch { name: "Dots".into(), paint, global: false, spot: false });
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Squares.vectorcraft"}))["library"].clone();
|
||||
let r = run(&mut s, "shape.rectangle", json!({"x": 20, "y": 20, "width": 40, "height": 40}))["id"].clone();
|
||||
run(&mut s, "paint.setFill", json!({"swatch": "Squares", "ids": [r]}));
|
||||
run(&mut s, "select.set", json!({"ids": [r]}));
|
||||
run(&mut s, "edit.copy", json!({}));
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#ff0000", "global": true}));
|
||||
run(&mut s, "edit.paste", json!({"swatchConflict": "merge"}));
|
||||
let first = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Squares", "Ink half"]}));
|
||||
let before = named_after(&s, "Ink half");
|
||||
for pattern in ["Squares", "Dots"] {
|
||||
let again = run(&mut s, "swatch.library.add", json!({"library": id, "names": [pattern, "Ink half"]}));
|
||||
assert_eq!(named_after(&s, "Ink half"), before, "{pattern}: {first} then {again}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A library gradient whose stops link to a color and to the Registration swatch, picked before a
|
||||
/// pattern whose art brings the color under a numbered name, is not added a second time.
|
||||
#[test]
|
||||
fn a_gradient_with_a_registration_stop_before_its_pattern_is_not_copied() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
let fade = json!({"stops": [{"offset": 0, "swatch": "Ink"}, {"offset": 1, "swatch": "[Registration]"}]});
|
||||
run(&mut s, "swatch.new", json!({"name": "Fade", "gradient": fade}));
|
||||
let dot = run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 6, "height": 6}))["id"].clone();
|
||||
run(&mut s, "paint.setFill", json!({"swatch": "Fade", "ids": [dot]}));
|
||||
run(&mut s, "paint.setStroke", json!({"none": true, "ids": [dot]}));
|
||||
run(&mut s, "select.set", json!({"ids": [dot]}));
|
||||
run(&mut s, "object.pattern.make", json!({"name": "Squares", "width": 8, "height": 8}));
|
||||
run(&mut s, "object.pattern.done", json!({}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Squares.vectorcraft"}))["library"].clone();
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#ff0000", "global": true}));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Fade", "Squares"]}));
|
||||
assert_eq!(named_after(&s, "Fade"), ["Fade"], "{r}");
|
||||
}
|
||||
|
||||
/// A library tint follows its color when the call picks the color, even when a pattern added
|
||||
/// before it took the document's numbered copy of that color, with the color itself or with the
|
||||
/// tint in its art.
|
||||
#[test]
|
||||
fn a_library_tint_follows_its_picked_color_not_the_copy_a_pattern_took() {
|
||||
for tint in [100, 50] {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink half", "swatch": "Ink", "tint": 50}));
|
||||
let dot = run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 6, "height": 6}))["id"].clone();
|
||||
run(&mut s, "paint.setFill", json!({"swatch": "Ink", "tint": tint, "ids": [dot]}));
|
||||
run(&mut s, "paint.setStroke", json!({"none": true, "ids": [dot]}));
|
||||
run(&mut s, "select.set", json!({"ids": [dot]}));
|
||||
run(&mut s, "object.pattern.make", json!({"name": "Tiles", "width": 8, "height": 8}));
|
||||
run(&mut s, "object.pattern.done", json!({}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Tiles.vectorcraft"}))["library"].clone();
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink 2", "color": "#0000ff", "global": true}));
|
||||
let names = json!(["Tiles", "Ink half", "Ink"]);
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": names}));
|
||||
let picked = r["added"].as_array().and_then(|a| a.iter().find(|n| n.as_str().is_some_and(|n| n.starts_with("Ink half"))).cloned());
|
||||
let picked = picked.and_then(|n| n.as_str().map(str::to_string)).unwrap_or_default();
|
||||
assert_eq!(tint_base(&s, &picked).as_deref(), Some("Ink"), "tint {tint}: {r}");
|
||||
let before = named_after(&s, "Ink half");
|
||||
let again = run(&mut s, "swatch.library.add", json!({"library": id, "names": names}));
|
||||
assert_eq!(named_after(&s, "Ink half"), before, "tint {tint}: {again}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A library tint is not taken for the tint a pattern brought back in the library color's place
|
||||
/// when that tint shows the document's own color (the pattern's art links to it, as pasting with
|
||||
/// Merge leaves it): it comes in as a tint of the library color's numbered copy.
|
||||
@@ -708,6 +1086,46 @@ fn a_library_tint_is_not_the_one_a_merged_pattern_brought() {
|
||||
assert_eq!(tint_base(&s, &tint).as_deref(), Some("Ink 2"), "{r}");
|
||||
}
|
||||
|
||||
/// A library gradient is not taken for the gradient a pattern brought back in its place when that
|
||||
/// gradient's stops show the document's own color.
|
||||
#[test]
|
||||
fn a_library_gradient_is_not_the_one_a_merged_pattern_brought() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#0000ff", "global": true}));
|
||||
let fade = json!({"stops": [{"offset": 0, "swatch": "Ink"}, {"offset": 1, "color": "#ffffff"}]});
|
||||
run(&mut s, "swatch.new", json!({"name": "Fade", "gradient": fade}));
|
||||
let dot = run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 6, "height": 6}))["id"].clone();
|
||||
run(&mut s, "paint.setFill", json!({"swatch": "Fade", "ids": [dot]}));
|
||||
run(&mut s, "paint.setStroke", json!({"none": true, "ids": [dot]}));
|
||||
run(&mut s, "select.set", json!({"ids": [dot]}));
|
||||
run(&mut s, "object.pattern.make", json!({"name": "Squares", "width": 8, "height": 8}));
|
||||
run(&mut s, "object.pattern.done", json!({}));
|
||||
let b64 = run(&mut s, "document.serialize", json!({}))["dataBase64"].as_str().unwrap().to_string();
|
||||
let id = run(&mut s, "swatch.library.load", json!({"dataBase64": b64, "name": "Squares.vectorcraft"}))["library"].clone();
|
||||
let r = run(&mut s, "shape.rectangle", json!({"x": 20, "y": 20, "width": 40, "height": 40}))["id"].clone();
|
||||
run(&mut s, "paint.setFill", json!({"swatch": "Squares", "ids": [r]}));
|
||||
run(&mut s, "select.set", json!({"ids": [r]}));
|
||||
run(&mut s, "edit.copy", json!({}));
|
||||
run(&mut s, "file.new", json!({"width": 100, "height": 100}));
|
||||
run(&mut s, "swatch.new", json!({"name": "Ink", "color": "#ff0000", "global": true}));
|
||||
run(&mut s, "edit.paste", json!({"swatchConflict": "merge"}));
|
||||
run(&mut s, "swatch.delete", json!({"names": ["Fade"], "unlink": false}));
|
||||
let r = run(&mut s, "swatch.library.add", json!({"library": id, "names": ["Squares", "Ink", "Fade"]}));
|
||||
assert_eq!(doc(&s).patterns.len(), 1, "{r}");
|
||||
let fade = r["added"][1].as_str().unwrap_or_default().to_string();
|
||||
assert!(fade.starts_with("Fade"), "{r}");
|
||||
let (first, link) = match doc(&s).swatch(&fade).map(|w| &w.paint) {
|
||||
Some(Paint::Gradient(g)) => (g.gradient.stops.first().map(|stop| stop.color), g.gradient.stops.first().and_then(|stop| stop.swatch.clone())),
|
||||
_ => (None, None),
|
||||
};
|
||||
assert_eq!(link.as_deref(), Some("Ink 2"), "the stop links to the library's color: {r}");
|
||||
let blue = match doc(&s).swatch("Ink 2").map(|w| &w.paint) {
|
||||
Some(Paint::Solid { color, .. }) => Some(*color),
|
||||
_ => None,
|
||||
};
|
||||
assert!(blue.is_some() && first == blue, "{r}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn swatch_exchange_files_load_add_and_list_as_user_libraries() {
|
||||
let bytes = vectorcraft_testkit::ase::sample();
|
||||
|
||||
+4
-3
@@ -5805,7 +5805,9 @@ color the pattern's art links to keeps the library's color: when the document gi
|
||||
in under a numbered name ("Ink 2") and the pattern links to that. A library color whose name the document gives
|
||||
another color is the document's numbered copy of the same color when it has one, so adding the pattern and its color
|
||||
again adds nothing. A pattern the document already holds with its art linked to the document's own color of that name
|
||||
is used as it is. `added` lists the colors the pattern's art brings too. A document with
|
||||
is used as it is. A library tint or gradient links to its colors under the names those colors have in the document,
|
||||
whether a color is picked before or after it, was added earlier or came with a pattern's art. `added` lists the colors
|
||||
the pattern's art brings too. A document with
|
||||
no swatches, and a `.ai`, `.eps` or PostScript file whose swatches are only the default ones, are refused with
|
||||
"`<file>` has no swatches of its own", unless the document has graph designs: it then loads with no swatches. The
|
||||
Swatch Libraries filter of Other Library… lists `.ai`, `.ait` and `.eps` (`.epsf`) files as well as the library files.
|
||||
@@ -6022,8 +6024,7 @@ fill or stroke with it, as one undo step, and returns the pattern's name in the
|
||||
color the pattern's art links to keeps the item's color, as with `swatch.library.add`: when the document gives its name
|
||||
another color, it comes in under a numbered name ("Ink 2"), or as the document's numbered copy of the same color, and
|
||||
the pattern links to it. A pattern the document holds with its art linked to the document's own color of that name is
|
||||
reused. `library.get`
|
||||
lists them as `gradients: [{name, gradient}]` and `patterns: [{name, pattern, thumbnail}]`.
|
||||
reused. `library.get` lists them as `gradients: [{name, gradient}]` and `patterns: [{name, pattern, thumbnail}]`.
|
||||
|
||||
Items can be put in user-named groups, which the panel shows as collapsible sections after the ungrouped items (its
|
||||
search field filters every item by name; `library.get` lists them all to filter). `library.createGroup {library?,
|
||||
|
||||
@@ -2237,7 +2237,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
A symbol instance written as its art, and a blend, mesh, repeat, placed document, intertwine or envelope written as a group of its art, likewise still wraps area type by its bounds when the file is opened, as it did before saving, not by the members of that art: the group starts with the same unpainted rectangle, which takes the object's lock and visibility, and the group keeps the object's name and transparency without options of its own. Area type in that art is above the rectangle, so the rectangle does not wrap it. The rectangle takes its place in the object limit before the art; without room for it, the options are left out with the limit's warning. An object without finite bounds keeps the options on its group. This is VectorCraft's own round-trip rule (`crates/eps/src/ai_editing/tests.rs` `live_art_written_as_a_group_keeps_wrapping_by_its_bounds`, `wrap_bounds_of_live_art_fit_the_object_limit_and_leave_area_type_in_the_art_unwrapped`, `live_art_without_bounds_keeps_its_text_wrap_on_the_group`).
|
||||
In a `.ai` or EPS opened from its editing data, type has its text object's opacity, blend mode and knockout shape flag, whether it is made from the file's text document or taken from the page, and type made from the text document takes its text object's lock. Where such type has transparency and comes in with other art (the rest of its look, or page type and strokes that go with it), a group of them has it. Where the page draws its type, or the strokes around it, with transparency that is neither its text object's nor its text object's combined with that of the objects around it, the page's type and strokes keep their own instead (`crates/eps/src/import/tests_native.rs`). Where the page draws type of no text object over text objects made from the text document, with their words in any case, that type is theirs as the page draws it and is left out; the page's other type of no text object goes only to text objects whose type the text document can't make, or else is left out with a warning.
|
||||
`.ai` editing-data import restores the document's listed graphic styles in panel order and links objects that use a listed style; unsupported appearances keep their drawn look (`crates/eps/src/import/ai/tests.rs`).
|
||||
Swatches › Open Swatch Library › Other Library… lists `.ai` and `.eps` files in its Swatch Libraries filter and loads another document's swatches ([importing swatches from another document](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=134)): its colors, tints, gradients and pattern swatches, in its order and color groups. Adding a pattern swatch from such a library brings the pattern with its tile and art as a pattern swatch, under the library swatch's name and in its color group. A document with no swatches, and a `.ai` or EPS whose swatches are only the default ones, are refused with a message (`cmd::fileio::tests_aiimport::a_swatch_library_in_a_ai_file_lists_and_adds_its_pattern_swatches`, `a_pattern_from_a_ai_library_keeps_a_color_the_library_lacks`, `swatch_library_documents_without_swatches_or_damaged_are_refused`, `cmd::fileio::tests::the_swatch_library_filter_lists_ai_and_eps_files`).
|
||||
Swatches › Open Swatch Library › Other Library… lists `.ai` and `.eps` files in its Swatch Libraries filter and loads another document's swatches ([importing swatches from another document](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=134)): its colors, tints, gradients and pattern swatches, in its order and color groups. Adding a pattern swatch from such a library brings the pattern with its tile and art as a pattern swatch, under the library swatch's name and in its color group. A document with no swatches, and a `.ai` or EPS whose swatches are only the default ones, are refused with a message (`cmd::fileio::tests_aiimport::a_swatch_library_in_a_ai_file_lists_and_adds_its_pattern_swatches`, `a_pattern_from_a_ai_library_keeps_a_color_the_library_lacks`, `swatch_library_documents_without_swatches_or_damaged_are_refused`, `cmd::fileio::tests::the_swatch_library_filter_lists_ai_and_eps_files`). A global or spot color whose name the document gives another color, added from a library on its own, with a tint or with a pattern's art, comes in under a numbered name, and adding it again uses that numbered copy; a library tint links to it. Use Library Item adds a library pattern's colors the same way (`tests::swatchlib::adding_a_library_pattern_and_its_color_again_reuses_the_numbered_color`, `a_library_tint_follows_its_color_to_its_numbered_name`, `a_library_tint_picked_before_its_color_follows_it_to_its_numbered_name`, `tests::library::a_pattern_item_keeps_its_global_color_when_the_document_has_that_name_in_another_color`).
|
||||
A `.ai` or EPS graphic style library, whose editing data holds the styles and their list but no layers, opens with those styles in list order. Other Library… loads another document's graphic styles ([Apply graphic styles](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/apply-graphic-styles/apply-graphic-styles.html)) and lists such a library's styles in a library panel. A `.ai` or EPS read as its PDF part or page because its layers can't be used also gets the styles of its list in place of the default ones (`crates/eps/src/import/tests_native.rs`, `cmd::fileio::tests_aiimport::a_graphic_style_library_in_a_ai_file_without_layers_loads_its_styles`).
|
||||
A `.ai` or EPS symbol library, whose editing data holds symbol definitions and their list but no layers, opens with those symbols in list order, each with its registration point. Other Library… in the Symbols panel's Symbol Libraries Menu imports the symbols of the file you pick ([Create or import symbol libraries](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/create-or-import-symbol-libraries.html)) and lists such a library's symbols in a library panel. A `.ai` or EPS read as its PDF part or page because its layers can't be used also gets the symbols defined before its layers (`crates/eps/src/import/tests_native.rs`, `crates/eps/src/import/ai/tests.rs`, `cmd::fileio::tests_aiimport::a_symbol_library_in_a_ai_file_without_layers_loads_its_symbols`).
|
||||
In a large canvas `.ai` or EPS ([Large canvas FAQ](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/start-a-new-file/large-canvas-faq.html)), or a `.ai` whose page is in larger units, opened from its editing data, VectorCraft reads the symbol definitions in the same units as the layers. When the file opens at its full size, each symbol's art, strokes and effects are scaled with the layers, and each instance keeps its own scale and rotation and draws where and as large as before. A new instance comes in at the symbol's full size, the size of an instance at 100% in the file. A symbol library from such a file comes in at the same size, and opacity masks on the layers that don't move with their object are scaled with the layers too. Editing data that VectorCraft wrote keeps its symbols and those masks at their own size, as its `.ai` save writes them (`tests_native::a_large_canvas_eps_keeps_its_symbols_at_the_pages_size`, `a_large_canvas_ai_keeps_its_symbols_at_the_pages_size`, `a_large_canvas_ai_vectorcraft_wrote_keeps_its_symbols_at_their_own_size`, `a_symbol_library_in_larger_units_comes_in_at_the_pages_size`, `build::candidate_tests::scaling_the_symbols_keeps_their_instances_in_place`, `scaling_a_read_document_scales_unlinked_opacity_masks`).
|
||||
|
||||
Reference in new issue
Block a user