diff --git a/crates/engine-core/src/cmd/frame_cmds/from_layers_hidden_tests.rs b/crates/engine-core/src/cmd/frame_cmds/from_layers_hidden_tests.rs index fac04fadbe..dc01c19470 100644 --- a/crates/engine-core/src/cmd/frame_cmds/from_layers_hidden_tests.rs +++ b/crates/engine-core/src/cmd/frame_cmds/from_layers_hidden_tests.rs @@ -83,6 +83,39 @@ fn a_hidden_layer_beside_a_visible_one_stays_out_of_the_content() { assert_eq!((cache.content_bounds().width(), cache.content_bounds().height()), (40, 40), "the hidden layer's pixels stay out of the content"); } +/// The measured rule is that a frame shows what it frames, not that exactly one hidden layer may +/// be framed: two hidden layers frame into one visible smart object holding both, where they +/// used to be refused as empty. +#[test] +fn two_hidden_layers_frame_into_one_visible_smart_object() { + let mut s = crate::session(); + s.execute("file.new", json!({"width": 300, "height": 220})).unwrap(); + let (red, blue) = s + .edit("setup", |doc, _| { + let fmt = doc.pixel_format(); + let mut red = Layer::raster("Red", fmt); + red.surface_mut().unwrap().fill_rect(Rect::new(50, 50, 150, 130), &photocraft_raster::from_rgba(&fmt, [1.0, 0.0, 0.0, 1.0])); + red.visible = false; + let mut blue = Layer::raster("Blue", fmt); + blue.surface_mut().unwrap().fill_rect(Rect::new(180, 100, 260, 180), &photocraft_raster::from_rgba(&fmt, [0.0, 0.0, 1.0, 1.0])); + blue.visible = false; + let ids = (red.id, blue.id); + doc.layers.push(red); + doc.layers.push(blue); + Ok(ids) + }) + .unwrap(); + s.execute("layer.select", json!({"layer": red.0, "mode": "replace"})).unwrap(); + s.execute("layer.select", json!({"layer": blue.0, "mode": "add"})).unwrap(); + let r = s.execute("layer.new.frameFromLayers", json!({})).expect("two hidden layers can be framed"); + assert_eq!(r["frame"], json!([50, 50, 210, 130]), "the frame covers both layers"); + let child = framed_child(&s, &r); + assert!(child.visible, "the framed content is visible"); + let LayerContent::Smart(smart) = &child.content else { panic!("the content is a smart object") }; + let cache = smart.cache.as_ref().expect("the smart object holds the rendered pixels"); + assert_eq!((cache.content_bounds().width(), cache.content_bounds().height()), (210, 130), "both layers' pixels came through"); +} + #[test] fn a_locked_layer_keeps_framing_and_comes_out_unlocked() { let (mut s, id) = session_with_layer("Red", true, true);