diff --git a/crates/render/src/fx/pixels.rs b/crates/render/src/fx/pixels.rs index 6b84b66ee4..e67df81622 100644 --- a/crates/render/src/fx/pixels.rs +++ b/crates/render/src/fx/pixels.rs @@ -593,8 +593,8 @@ impl Renderer { } /// The inputs a raster of `n`'s content, which reads `reads`, is drawn with in frame `f`: the - /// color settings, the edge smoothing, the hidden objects, whether dashed strokes draw as solid - /// lines, the document's raster effects resolution (which a Rasterize or De-Interlace anywhere + /// color settings, the edge smoothing, the hidden objects, whether guides and template layers + /// are left out, whether dashed strokes draw as solid lines, the document's raster effects resolution (which a Rasterize or De-Interlace anywhere /// in the content follows), the knockout `n` inherits and, while `n` holds the isolated group, /// isolation mode; the pattern definitions, symbols and /// brush library it reads; for images and placed documents their pixels and files, the @@ -610,8 +610,8 @@ impl Renderer { let doc = self.doc_inputs(f.doc); let mut h = DefaultHasher::new(); (doc.cms, f.opts.anti_alias.threshold(), self.knockout, f.doc.raster_effects_ppi.to_bits()).hash(&mut h); - // Cached effects on containers can include paths made into guides. - f.opts.hide_guides.hash(&mut h); + // Cached effects on containers can include paths made into guides and template layers. + (f.opts.hide_guides, f.opts.hide_templates, f.opts.skip_templates).hash(&mut h); // Cached effects can include dashed strokes drawn as solid lines. f.opts.solid_dashes.hash(&mut h); f.hidden_inputs.hash(&mut h); diff --git a/crates/render/src/fx/tests.rs b/crates/render/src/fx/tests.rs index 727a09996f..7d85347e7c 100644 --- a/crates/render/src/fx/tests.rs +++ b/crates/render/src/fx/tests.rs @@ -1973,6 +1973,40 @@ fn hiding_a_member_filters_the_whole_object_raster_again_after_a_pan() { assert!(pixels == Renderer::new().render(&d, 1280, 800, view(40.0), &opts).pixels, "hiding a member filters the content again"); } +/// Hiding or skipping template layers filters the whole-object raster of a layer with effects +/// that holds a template sublayer again after a pan by whole pixels. +#[test] +fn hiding_templates_filters_the_whole_object_raster_again_after_a_pan() { + let mut d = Document::new(100.0, 100.0); + let l = d.layers[0].id; + let mut square = + |r: Rect, c: Color| Arc::new(Node::path(d.alloc_id(), shapes::rectangle(r), Appearance::basic(Paint::solid(c), Paint::None, 0.0))); + let white = square(Rect::new(100.0, 100.0, 300.0, 250.0), Color::WHITE); + let black = square(Rect::new(200.0, 100.0, 300.0, 250.0), Color::BLACK); + let mut template = Node::layer(d.alloc_id(), "Template", vectorcraft_doc::LayerColor::Preset(0)); + if let vectorcraft_doc::NodeKind::Layer { template: flag, children, .. } = &mut template.kind { + *flag = true; + children.push(black); + } + d.insert(Some(l), 0, Arc::unwrap_or_clone(white)).unwrap(); + d.insert(Some(l), 1, template).unwrap(); + d.node_mut(l).unwrap().appearance.effects = vec![Effect { id: "sketch.tornEdges".into(), params: json!({}), visible: true }]; + let opts = RenderOptions { background: Some([255, 255, 255, 255]), dim_templates: false, ..Default::default() }; + let view = |dx: f64| Affine::translate((640.0 + dx, 400.0)) * Affine::scale(64.0) * Affine::translate((-295.0, -175.0)); + for (left_out, what) in + [(RenderOptions { hide_templates: true, ..opts.clone() }, "hiding"), (RenderOptions { skip_templates: true, ..opts.clone() }, "skipping")] + { + let mut r = Renderer::new(); + let _ = r.render(&d, 1280, 800, view(0.0), &opts); + let kept = r.pixel_fx.values().next().unwrap(); + assert!(kept.k < 1.0 && kept.view.is_none(), "a raster of the whole object at a lower resolution"); + let fresh = Renderer::new().render(&d, 1280, 800, view(40.0), &left_out).pixels; + assert!(fresh != Renderer::new().render(&d, 1280, 800, view(40.0), &opts).pixels, "the template shows through the effect"); + let pixels = r.render(&d, 1280, 800, view(40.0), &left_out).pixels; + assert!(pixels == fresh, "{what} templates filters the content again"); + } +} + /// A whole-object raster gives way to its view copy when the cache budget cannot hold both. /// The same view draws the copy again without filtering the content. #[test]