mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
Scripts: retrace refuses a tracing that holds artwork its trace did not make
imageTrace.make records the ids of the objects it made in the tracing's trace settings as `made`, and copying the tracing records the ids of their copies. Tracing again through the scripting API throws, with nothing changed, when the tracing holds any other object, whether it was added in this run, an earlier run or by a command. A tracing saved without `made` is checked only for objects added in the same run, as before.
This commit is contained in:
1 parent
374b31b6f6
commit
795bef8b29
8 files changed
+284
-6
No files matched your search
@@ -24,6 +24,10 @@
|
||||
//! so. Tracing again makes a new object: the `PluginItem`, its `TracingObject` and its
|
||||
//! `TracingOptions` follow it. A tracing that another command traced again, expanded or
|
||||
//! released, or whose source image was deleted, is stale.
|
||||
//! - Tracing again throws [`ADDED_ARTWORK`], with nothing changed, when the tracing holds an object
|
||||
//! its trace did not make, whether this run, an earlier run or a command added it. The tracing records the
|
||||
//! objects its trace made ([`crate::doc::TraceMade`]), and a copy of it records their copies. A
|
||||
//! tracing saved without that record is checked only for objects added in this run.
|
||||
//! - `palette` is `""` for the automatic palette, or `"Limited"`, `"Full Tone"` or
|
||||
//! `"Document Library"`. `minArea` is the Noise setting in pixels: an area smaller than it is not
|
||||
//! traced. `tracingMode` has no value for the Flat Logo mode. The options with no VectorCraft
|
||||
@@ -50,6 +54,8 @@ use crate::{NodeId, NodeKind};
|
||||
|
||||
/// The error of `trace()` on an image that is the source of a tracing.
|
||||
pub const ALREADY_TRACED: &str = "The image is the source art of a tracing";
|
||||
/// The error of tracing again a tracing that holds an object its trace did not make.
|
||||
pub const ADDED_ARTWORK: &str = "Cannot retrace a tracing containing added artwork";
|
||||
/// The error of options that trace with neither fills nor strokes.
|
||||
pub const NEEDS_FILLS_OR_STROKES: &str = "TracingOptions requires fills or strokes";
|
||||
/// The error of `expandTracing(true)`.
|
||||
@@ -286,10 +292,15 @@ fn retrace(h: &Host, item: Item, mut params: Map<String, Value>) -> Result<(), H
|
||||
remember_source(h, item.doc.uid, group);
|
||||
let descendants = h.dom.tracing.descendants.borrow();
|
||||
let ids = descendants.get(&(item.doc.uid, item.id.0)).ok_or_else(stale)?;
|
||||
// The objects the trace made, as the tracing records them; a tracing saved without that
|
||||
// record is checked against the objects it held when this run first saw it.
|
||||
let made = group.trace_made();
|
||||
let mut added = false;
|
||||
group.walk(&mut |n| added |= n.id != group.id && !ids.contains(&n.id));
|
||||
group.walk(&mut |n| {
|
||||
added |= n.id != group.id && made.as_ref().map_or(!ids.contains(&n.id), |m| !m.contains(n.id));
|
||||
});
|
||||
if added {
|
||||
return Err(HostError::Error("Cannot retrace a tracing containing added artwork".into()));
|
||||
return Err(HostError::Error(ADDED_ARTWORK.into()));
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
Reference in new issue
Block a user