mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 18:32:23 +00:00
Expand Appearance: Safe Mode skips symbol art of a hidden instance in a group's image
The image a group's or layer's raster effect makes leaves out hidden objects and everything in them, as the renderer does. The Safe Mode plug-in check looked into every object of such a group, so a hidden plain symbol instance whose symbol art holds a plug-in effect stopped Expand Appearance of the group. The check now skips hidden objects inside the group's image. The group itself still counts when it, or a group around it, is hidden, since expansion still makes its image.
This commit is contained in:
@@ -97,7 +97,7 @@ fn effect_specs() -> Vec<CommandSpec> {
|
||||
"Expand Appearance",
|
||||
["Object"],
|
||||
None,
|
||||
"{ids?|id?: [..], target?} turn each object's appearance into objects: every fill and stroke becomes an object of its own (a stroke stays a stroke, with its weight, dashes, arrowheads and width profile, on its own copy of the path, which object.expand or object.path.outlineStroke outline; brushed strokes become their brush art) grouped in paint order under the object's id and transparency, geometry effects are baked, raster effects become an embedded image (shadows and outer glows below the art; blur, feather and inner glow replace it; an object whose only raster effect is its own Rasterize becomes the image object.rasterize makes with the effect's options), type with effects or fills of its own is outlined; Crop Marks become a group of the object and its marks; Vector Halftone (addon.color.halftone) becomes a group of its dot paths, one per ink; a group's or layer's own fills and strokes become objects among its members, which are expanded too; a symbol instance whose topmost fill or stroke is visible, has an opacity above 0 and has a geometry or raster effect becomes a group of its art, that fill's effects reshaping the art's filled shapes and that stroke's effects reshaping its stroked shapes, as the canvas draws them, its raster effects an image as for other objects; a symbol instance in that art whose topmost fill or stroke has such an effect (its own or one the outer instance passes on) becomes its art and image in turn. An outlined frame of threaded text leaves its thread with the text it shows, and a frame kept as type in a group stays in its thread. A dimension whose art it changes becomes a plain group of its art, except one selected with art it measures, directly or in groups without fills, strokes or effects of their own: its lines and label stay as they are, and if the new art no longer fits its link it stays where it was, no longer linked. Hidden fills, strokes and effects are dropped. One expansion makes at most 1,024 images of raster effects, 256 megapixels in all (VectorCraft's own limits): an object or symbol instance whose image would go past them stays as it is, with its effects, and when nothing else expands that is an error. In Safe Mode, an object with a visible plug-in effect (in it, or in a symbol it places, a plain instance in a group or layer whose raster effect makes an image of it included) is an error and nothing changes. Enabled when a selected or targeted object's appearance isn't basic (`ids` then pick which objects) → {ids, warning? (an image in the art couldn't be decoded, as object.rasterize says; or raster effects were left past the limits), rasterLeft? (how many objects were left so)}",
|
||||
"{ids?|id?: [..], target?} turn each object's appearance into objects: every fill and stroke becomes an object of its own (a stroke stays a stroke, with its weight, dashes, arrowheads and width profile, on its own copy of the path, which object.expand or object.path.outlineStroke outline; brushed strokes become their brush art) grouped in paint order under the object's id and transparency, geometry effects are baked, raster effects become an embedded image (shadows and outer glows below the art; blur, feather and inner glow replace it; an object whose only raster effect is its own Rasterize becomes the image object.rasterize makes with the effect's options), type with effects or fills of its own is outlined; Crop Marks become a group of the object and its marks; Vector Halftone (addon.color.halftone) becomes a group of its dot paths, one per ink; a group's or layer's own fills and strokes become objects among its members, which are expanded too; a symbol instance whose topmost fill or stroke is visible, has an opacity above 0 and has a geometry or raster effect becomes a group of its art, that fill's effects reshaping the art's filled shapes and that stroke's effects reshaping its stroked shapes, as the canvas draws them, its raster effects an image as for other objects; a symbol instance in that art whose topmost fill or stroke has such an effect (its own or one the outer instance passes on) becomes its art and image in turn. An outlined frame of threaded text leaves its thread with the text it shows, and a frame kept as type in a group stays in its thread. A dimension whose art it changes becomes a plain group of its art, except one selected with art it measures, directly or in groups without fills, strokes or effects of their own: its lines and label stay as they are, and if the new art no longer fits its link it stays where it was, no longer linked. Hidden fills, strokes and effects are dropped. One expansion makes at most 1,024 images of raster effects, 256 megapixels in all (VectorCraft's own limits): an object or symbol instance whose image would go past them stays as it is, with its effects, and when nothing else expands that is an error. In Safe Mode, an object with a visible plug-in effect (in it, or in a symbol it places, a visible plain instance in a group or layer whose raster effect makes an image of it included) is an error and nothing changes. Enabled when a selected or targeted object's appearance isn't basic (`ids` then pick which objects) → {ids, warning? (an image in the art couldn't be decoded, as object.rasterize says; or raster effects were left past the limits), rasterLeft? (how many objects were left so)}",
|
||||
can_expand,
|
||||
expand_appearance
|
||||
),
|
||||
@@ -1611,33 +1611,63 @@ fn expanded_node(
|
||||
|
||||
/// Does `n`, an object in it, or the art of a symbol placed in it hold a plug-in effect that
|
||||
/// expanding it draws: a visible one, the object's own or a visible fill's or stroke's, on an
|
||||
/// object that expands ([`expandable`]; in a symbol's art, `in_art`, every object does, and so does
|
||||
/// every object in a group or layer with a raster effect, whose image draws all of it). A symbol's
|
||||
/// object that expands ([`expandable`]; in a symbol's art, `in_art`, every object does), or that the
|
||||
/// image of a group or layer with a raster effect draws ([`rasterizes_plugin_effect`]). A symbol's
|
||||
/// art counts where an instance of it expands. `seen` holds the symbols already looked into.
|
||||
fn holds_plugin_effect(d: &Document, n: &Node, in_art: bool, seen: &mut std::collections::HashSet<String>) -> bool {
|
||||
let plugin = |e: &Effect| e.visible && vectorcraft_plugins::effect::plugin_id(&e.id).is_some();
|
||||
let mut symbols = vec![];
|
||||
let mut drawn = vec![];
|
||||
let mut holds = false;
|
||||
n.walk(&mut |c| {
|
||||
if !in_art && is_container(c) && !rasterfx::raster_fx(c).is_empty() {
|
||||
drawn.push(c);
|
||||
}
|
||||
if !in_art && !expandable(c) {
|
||||
return;
|
||||
}
|
||||
holds |= c.appearance.effects.iter().any(plugin) || c.appearance.items.iter().any(|i| i.visible() && i.effects().iter().any(plugin));
|
||||
holds |= has_own_plugin_effect(c);
|
||||
if let NodeKind::SymbolInstance { symbol, .. } = &c.kind {
|
||||
symbols.push(symbol.clone());
|
||||
}
|
||||
});
|
||||
holds
|
||||
|| drawn.into_iter().any(|g| holds_plugin_effect(d, g, true, seen))
|
||||
|| (!in_art && rasterizes_plugin_effect(d, n, &mut std::collections::HashSet::new()))
|
||||
|| symbols.into_iter().any(|name| {
|
||||
seen.insert(name.clone()) && d.symbols.iter().find(|s| s.name == name).is_some_and(|s| holds_plugin_effect(d, &s.art, true, seen))
|
||||
})
|
||||
}
|
||||
|
||||
/// Does `n` have a visible plug-in effect of its own, or on a visible fill or stroke?
|
||||
fn has_own_plugin_effect(n: &Node) -> bool {
|
||||
let plugin = |e: &Effect| e.visible && vectorcraft_plugins::effect::plugin_id(&e.id).is_some();
|
||||
n.appearance.effects.iter().any(plugin) || n.appearance.items.iter().any(|i| i.visible() && i.effects().iter().any(plugin))
|
||||
}
|
||||
|
||||
/// Does a group or layer in `n` with a raster effect make an image of a visible plug-in effect
|
||||
/// ([`draws_plugin_effect`])? Expansion makes the image of such a group or layer even when it, or
|
||||
/// a group around it, is hidden.
|
||||
fn rasterizes_plugin_effect(d: &Document, n: &Node, seen: &mut std::collections::HashSet<String>) -> bool {
|
||||
let mut drawn = vec![];
|
||||
n.walk(&mut |c| {
|
||||
if is_container(c) && !rasterfx::raster_fx(c).is_empty() {
|
||||
drawn.push(c);
|
||||
}
|
||||
});
|
||||
drawn.into_iter().any(|g| draws_plugin_effect(d, g, seen))
|
||||
}
|
||||
|
||||
/// Does `n`, an object the image of `n` draws in it, or the art of a symbol such an instance places,
|
||||
/// have a visible plug-in effect ([`has_own_plugin_effect`])? The image leaves out a hidden object
|
||||
/// in `n`, and everything in it, as the renderer does. `seen` holds the symbols already looked into.
|
||||
fn draws_plugin_effect(d: &Document, n: &Node, seen: &mut std::collections::HashSet<String>) -> bool {
|
||||
if has_own_plugin_effect(n) {
|
||||
return true;
|
||||
}
|
||||
if let NodeKind::SymbolInstance { symbol, .. } = &n.kind
|
||||
&& seen.insert(symbol.clone())
|
||||
&& d.symbols.iter().find(|s| s.name == *symbol).is_some_and(|s| draws_plugin_effect(d, &s.art, seen))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
n.children().into_iter().flatten().any(|c| c.visible && draws_plugin_effect(d, c, seen))
|
||||
}
|
||||
|
||||
fn expand_appearance(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let roots = edit_targets(s, p, "effect.expandAppearance")?;
|
||||
// In Safe Mode a plug-in effect draws nothing: expanding it would drop the effect and keep the
|
||||
|
||||
@@ -506,6 +506,58 @@ fn expand_appearance_in_safe_mode_checks_symbol_art_a_group_image_draws() {
|
||||
refused(&mut s, &json!(outer));
|
||||
}
|
||||
|
||||
/// In Safe Mode, a hidden plain instance draws nothing in the image a group's raster effect makes,
|
||||
/// so its symbol art's plug-in effect doesn't stop Expand Appearance of the group; shown, it does.
|
||||
#[test]
|
||||
fn expand_appearance_in_safe_mode_skips_symbol_art_of_a_hidden_instance_a_group_image_leaves_out() {
|
||||
let _f = fresh();
|
||||
let mut s = Session::new();
|
||||
let fx = wat::parse_str(tpl::returning(&tpl::manifest("test.sm.hid", "effect", "{}"), r#"{"objects":[]}"#)).unwrap();
|
||||
s.execute("plugin.install", &json!({"dataBase64": vectorcraft_format::base64_encode(&fx)})).unwrap();
|
||||
s.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap();
|
||||
s.execute("effect.apply", &json!({"effect": "plugin.test.sm.hid"})).unwrap();
|
||||
s.execute("symbol.new", &json!({"name": "fx"})).unwrap();
|
||||
let hide = |s: &mut Session, id: u64| {
|
||||
std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc).node_mut(vectorcraft_engine::doc::NodeId(id)).unwrap().visible = false;
|
||||
};
|
||||
let expand = |s: &mut Session, group: u64| {
|
||||
safe_mode::set_active(Some(safe_mode::Source::Flag));
|
||||
let r = s.execute("effect.expandAppearance", &json!({"ids": [group]}));
|
||||
safe_mode::set_active(None);
|
||||
r
|
||||
};
|
||||
// A blurred group of a visible rectangle and an instance, then one of a visible rectangle and a
|
||||
// group around an instance; the instance, or the group around it, is shown and then hidden.
|
||||
for wrap in [false, true] {
|
||||
let rect = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 20, "height": 20})).unwrap()["id"].clone();
|
||||
let mut hidden = s.execute("symbol.place", &json!({"name": "fx", "x": 150, "y": 150})).unwrap()["id"].clone();
|
||||
if wrap {
|
||||
hidden = s.execute("object.group", &json!({"ids": [hidden]})).unwrap()["id"].clone();
|
||||
}
|
||||
let group = s.execute("object.group", &json!({"ids": [rect, hidden]})).unwrap()["id"].clone();
|
||||
s.execute("effect.apply", &json!({"effect": "blur.gaussian", "ids": [group], "params": {"radius": 2}})).unwrap();
|
||||
let (hidden, group) = (hidden.as_u64().unwrap(), group.as_u64().unwrap());
|
||||
let err = expand(&mut s, group).unwrap_err().to_string();
|
||||
assert!(err.contains("a plug-in effect in the selection can't be expanded in Safe Mode"), "{err}");
|
||||
hide(&mut s, hidden);
|
||||
expand(&mut s, group).unwrap();
|
||||
}
|
||||
// Expansion still makes the image of a hidden blurred group, or of one in a hidden group, so
|
||||
// a shown instance in it still stops it.
|
||||
let plain = s.execute("symbol.place", &json!({"name": "fx", "x": 150, "y": 20})).unwrap()["id"].clone();
|
||||
let blurred = s.execute("object.group", &json!({"ids": [plain]})).unwrap()["id"].clone();
|
||||
s.execute("effect.apply", &json!({"effect": "blur.gaussian", "ids": [blurred], "params": {"radius": 2}})).unwrap();
|
||||
let parent = s.execute("object.group", &json!({"ids": [blurred]})).unwrap()["id"].as_u64().unwrap();
|
||||
hide(&mut s, parent);
|
||||
let err = expand(&mut s, parent).unwrap_err().to_string();
|
||||
assert!(err.contains("a plug-in effect in the selection can't be expanded in Safe Mode"), "{err}");
|
||||
let blurred = blurred.as_u64().unwrap();
|
||||
hide(&mut s, blurred);
|
||||
let err = expand(&mut s, blurred).unwrap_err().to_string();
|
||||
assert!(err.contains("a plug-in effect in the selection can't be expanded in Safe Mode"), "{err}");
|
||||
}
|
||||
|
||||
/// In Safe Mode, a plug-in effect in the art of a graph design in a series stops Expand Appearance of the graph only
|
||||
/// when an effect of the series group draws that art with the group.
|
||||
#[test]
|
||||
|
||||
+2
-1
@@ -13275,7 +13275,8 @@ runs: `plugin.install`, `plugin.run`, `plugin.reload` and exporters return an er
|
||||
object's geometry unchanged while the object keeps the effect: `effect.list` gives that effect `skipped: true`, and the
|
||||
Appearance panel shows "(Safe Mode)" after its name and the plug-in's id in its tooltip. `effect.expandAppearance` returns an
|
||||
error and changes nothing when an object it would expand holds such an effect, in it or in a symbol it places. That includes a
|
||||
plain symbol instance in a group or layer with a raster effect, since the group's image draws the symbol's art. `vectorcraft` rejects an option it does not know (such as
|
||||
visible plain symbol instance in a group or layer with a raster effect, since the group's image draws the symbol's art. A
|
||||
hidden instance draws nothing in that image, so its symbol's art does not count. `vectorcraft` rejects an option it does not know (such as
|
||||
`--safe-mod`) instead of opening it as a file; `--` before a file name that starts with `-` opens it. The web build keeps
|
||||
no installed plug-ins from one page load to the next and has no launch marker, so it never offers the choice. `plugin.safeMode` returns `{active, source, disabled,
|
||||
pendingItem}`; a command does not turn Safe Mode on or off. `plugin.setEnabled {id | file, enabled}` turns a plug-in on or
|
||||
|
||||
Reference in New Issue
Block a user