From a84a398a3f7e29e7a84c5a766ae6cde563284c6a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 20:06:07 -0800 Subject: [PATCH] Expand Appearance: Safe Mode skips symbol art in a template layer of a group's image The image a group's or layer's raster effect makes is drawn with templates skipped, so it leaves out template layers, guides and ruler guides with everything in them. The Safe Mode plug-in check still looked into a template sublayer, so a plain symbol instance there whose symbol art holds a plug-in effect stopped Expand Appearance of the layer. The check now skips them as the renderer does. --- crates/engine/src/cmd/effectcmd.rs | 9 ++++--- crates/engine/tests/plugin_safe_mode.rs | 35 +++++++++++++++++++++++++ docs/mcp.md | 2 +- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/effectcmd.rs b/crates/engine/src/cmd/effectcmd.rs index 2b28cd64ff..c33ebb61d7 100644 --- a/crates/engine/src/cmd/effectcmd.rs +++ b/crates/engine/src/cmd/effectcmd.rs @@ -97,7 +97,7 @@ fn effect_specs() -> Vec { "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 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)}", + "{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 outside template layers 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 ), @@ -1654,7 +1654,8 @@ fn rasterizes_plugin_effect(d: &Document, n: &Node, seen: &mut std::collections: /// 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. +/// in `n`, a template layer, a guide or a ruler guide, and everything in it, as the renderer does +/// with templates skipped. `seen` holds the symbols already looked into. fn draws_plugin_effect(d: &Document, n: &Node, seen: &mut std::collections::HashSet) -> bool { if has_own_plugin_effect(n) { return true; @@ -1665,7 +1666,9 @@ fn draws_plugin_effect(d: &Document, n: &Node, seen: &mut std::collections::Hash { return true; } - n.children().into_iter().flatten().any(|c| c.visible && draws_plugin_effect(d, c, seen)) + let drawn = + |c: &Node| c.visible && !c.is_ruler_guide() && !matches!(c.kind, NodeKind::Layer { template: true, .. } | NodeKind::Path { guide: true, .. }); + n.children().into_iter().flatten().any(|c| drawn(c) && draws_plugin_effect(d, c, seen)) } fn expand_appearance(s: &mut Session, p: &Value) -> Result { diff --git a/crates/engine/tests/plugin_safe_mode.rs b/crates/engine/tests/plugin_safe_mode.rs index 98047a2d86..c2213a930a 100644 --- a/crates/engine/tests/plugin_safe_mode.rs +++ b/crates/engine/tests/plugin_safe_mode.rs @@ -558,6 +558,41 @@ fn expand_appearance_in_safe_mode_skips_symbol_art_of_a_hidden_instance_a_group_ assert!(err.contains("a plug-in effect in the selection can't be expanded in Safe Mode"), "{err}"); } +/// In Safe Mode, the image a layer's raster effect makes leaves out a template sublayer, so the symbol +/// art of a plain instance in it doesn't stop Expand Appearance of the layer; in a plain sublayer, it does. +#[test] +fn expand_appearance_in_safe_mode_skips_symbol_art_in_a_template_sublayer_a_layer_image_leaves_out() { + let _f = fresh(); + let mut s = Session::new(); + let fx = wat::parse_str(tpl::returning(&tpl::manifest("test.sm.tpl", "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.tpl"})).unwrap(); + s.execute("symbol.new", &json!({"name": "fx"})).unwrap(); + let layer = s.execute("layer.new", &json!({})).unwrap()["id"].as_u64().unwrap(); + s.execute("layer.setCurrent", &json!({"id": layer})).unwrap(); + s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 20, "height": 20})).unwrap(); + let instance = s.execute("symbol.place", &json!({"name": "fx", "x": 150, "y": 150})).unwrap()["id"].as_u64().unwrap(); + let sub = s.execute("layer.newSublayer", &json!({"parent": layer})).unwrap()["id"].as_u64().unwrap(); + s.execute("layer.move", &json!({"ids": [instance], "target": sub})).unwrap(); + s.execute("layer.target", &json!({"id": layer})).unwrap(); + s.execute("effect.apply", &json!({"effect": "blur.gaussian", "ids": [layer], "item": null, "params": {"radius": 2}})).unwrap(); + let blurred = |s: &Session| s.doc().unwrap().doc.node(vectorcraft_engine::doc::NodeId(layer)).unwrap().appearance.effects.len(); + assert_eq!(blurred(&s), 1, "the layer has its own Gaussian Blur"); + let expand = |s: &mut Session| { + s.execute("layer.target", &json!({"id": layer})).unwrap(); + safe_mode::set_active(Some(safe_mode::Source::Flag)); + let r = s.execute("effect.expandAppearance", &json!({})); + safe_mode::set_active(None); + r + }; + let err = expand(&mut s).unwrap_err().to_string(); + assert!(err.contains("a plug-in effect in the selection can't be expanded in Safe Mode"), "{err}"); + s.execute("layer.setProps", &json!({"id": sub, "template": true})).unwrap(); + expand(&mut s).unwrap(); +} + /// 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] diff --git a/docs/mcp.md b/docs/mcp.md index a6af3a0d23..11e8bb47f4 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -13276,7 +13276,7 @@ object's geometry unchanged while the object keeps the effect: `effect.list` giv 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 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 +hidden instance, or one in a template sublayer, 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