From 92c63bb8cf0ae10101da593c47b577e51c8dd470 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 21:03:29 -0800 Subject: [PATCH] Expand Appearance: Safe Mode skips raster groups inside a blurred group's image A group or layer whose raster effects are not all shadows and outer glows (a blur, feather or inner glow) becomes one image of what it draws, and the groups and layers in it make no images of their own. The Safe Mode plug-in check still looked into every group with a raster effect inside it, so a hidden blurred group there holding a plain symbol instance with a plug-in effect in its art stopped the expansion. The check now stops at such a group. Under shadows and outer glows the members still expand on their own, so their groups are still checked. --- crates/engine/src/cmd/effectcmd.rs | 20 +++++++----- crates/engine/tests/plugin_safe_mode.rs | 41 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/effectcmd.rs b/crates/engine/src/cmd/effectcmd.rs index c33ebb61d7..90176831a4 100644 --- a/crates/engine/src/cmd/effectcmd.rs +++ b/crates/engine/src/cmd/effectcmd.rs @@ -1641,15 +1641,21 @@ fn has_own_plugin_effect(n: &Node) -> bool { /// 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. +/// a group around it, is hidden. A group or layer that paints something and whose raster effects +/// are not all shadows and outer glows becomes one image of what it draws, so the groups and layers +/// in it make no images of their own; one that paints nothing makes no image, and its members +/// expand on their own. fn rasterizes_plugin_effect(d: &Document, n: &Node, seen: &mut std::collections::HashSet) -> bool { - let mut drawn = vec![]; - n.walk(&mut |c| { - if is_container(c) && !rasterfx::raster_fx(c).is_empty() { - drawn.push(c); + let fx = if is_container(n) { rasterfx::raster_fx(n) } else { vec![] }; + if !fx.is_empty() { + if draws_plugin_effect(d, n, seen) { + return true; } - }); - drawn.into_iter().any(|g| draws_plugin_effect(d, g, seen)) + if !fx.iter().all(effects::RasterFx::is_below) && vectorcraft_render::painted_bounds(d, n).is_some() { + return false; + } + } + n.children().into_iter().flatten().any(|c| rasterizes_plugin_effect(d, c, seen)) } /// Does `n`, an object the image of `n` draws in it, or the art of a symbol such an instance places, diff --git a/crates/engine/tests/plugin_safe_mode.rs b/crates/engine/tests/plugin_safe_mode.rs index c2213a930a..6cb261dd0f 100644 --- a/crates/engine/tests/plugin_safe_mode.rs +++ b/crates/engine/tests/plugin_safe_mode.rs @@ -593,6 +593,47 @@ fn expand_appearance_in_safe_mode_skips_symbol_art_in_a_template_sublayer_a_laye expand(&mut s).unwrap(); } +/// In Safe Mode, a group whose Gaussian Blur makes it one image leaves out a hidden blurred group in +/// it, which makes no image of its own, so the symbol art of a plain instance there doesn't stop +/// Expand Appearance. Under a Drop Shadow, whose members expand on their own, the hidden group still +/// makes its image, so it does. +#[test] +fn expand_appearance_in_safe_mode_skips_a_hidden_blurred_group_that_a_blurred_group_image_leaves_out() { + let _f = fresh(); + let mut s = Session::new(); + let fx = wat::parse_str(tpl::returning(&tpl::manifest("test.sm.nest", "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.nest"})).unwrap(); + s.execute("symbol.new", &json!({"name": "fx"})).unwrap(); + 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 + }; + for (outer, allowed) in [("blur.gaussian", true), ("stylize.dropShadow", false)] { + let rect = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 20, "height": 20})).unwrap()["id"].clone(); + let plain = s.execute("symbol.place", &json!({"name": "fx", "x": 150, "y": 150})).unwrap()["id"].clone(); + let inner = s.execute("object.group", &json!({"ids": [plain]})).unwrap()["id"].clone(); + s.execute("effect.apply", &json!({"effect": "blur.gaussian", "ids": [inner], "params": {"radius": 2}})).unwrap(); + let group = s.execute("object.group", &json!({"ids": [rect, inner]})).unwrap()["id"].as_u64().unwrap(); + s.execute("effect.apply", &json!({"effect": outer, "ids": [group]})).unwrap(); + let inner = vectorcraft_engine::doc::NodeId(inner.as_u64().unwrap()); + std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc).node_mut(inner).unwrap().visible = false; + let r = expand(&mut s, group); + if allowed { + r.unwrap(); + // The blurred group became its image: the hidden group in it was not expanded on its own. + assert!(s.doc().unwrap().doc.node(inner).is_none(), "the hidden group went into the image"); + } else { + let err = r.unwrap_err().to_string(); + assert!(err.contains("a plug-in effect in the selection can't be expanded in Safe Mode"), "{outer}: {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]