Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Fix #1486: a template layer stays in Preview in Outline view

bflatastica787fb487c5c
diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs
index b6ef2db21..ceb153f2e 100644
--- a/crates/render/src/lib.rs
+++ b/crates/render/src/lib.rs
@@ -1023,7 +1023,13 @@ impl Renderer {
&& f.opts.dim_templates
&& !f.opts.skip_templates
{
- if !preview && !f.opts.outline {
+ // A template layer stays in Preview while the view is in Outline (and whatever its own
+ // Preview option says): its picture is there to be traced (#1486).
+ if *template && f.opts.outline {
+ let opts = RenderOptions { outline: false, ..f.opts.clone() };
+ return self.draw_node(ctx, &Frame { opts: &opts, ..*f }, n, force);
+ }
+ if !preview && !template && !f.opts.outline {
let opts = RenderOptions { outline: true, ..f.opts.clone() };
return self.draw_node(ctx, &Frame { opts: &opts, ..*f }, n, force);
}
diff --git a/crates/render/src/tests_layeropts.rs b/crates/render/src/tests_layeropts.rs
index c20e191d8..a2864cc61 100644
--- a/crates/render/src/tests_layeropts.rs
+++ b/crates/render/src/tests_layeropts.rs
@@ -67,6 +67,34 @@ fn dim_images_fades_only_the_images() {
assert_eq!(render(&d, true).pixel(65, 25), [255, 0, 0, 255], "exports are not dimmed");
}
+/// In Outline view a template layer still draws in Preview, dimmed, so its picture can be traced;
+/// the layer above it draws in outline (#1486).
+#[test]
+fn a_template_layer_stays_in_preview_in_outline_view() {
+ let mut d = doc(|k| {
+ if let NodeKind::Layer { template, preview, .. } = k {
+ *template = true;
+ // Preview off doesn't put a template in outline either.
+ *preview = false;
+ }
+ });
+ let top = Node::layer(d.alloc_id(), "Drawing", vectorcraft_doc::LayerColor::Preset(0));
+ let top_id = d.insert(None, 9, top).unwrap();
+ let red = Appearance::basic(Paint::solid(Color::rgb(1.0, 0.0, 0.0)), Paint::None, 0.0);
+ let sq = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(10.0, 60.0, 40.0, 90.0)), red);
+ d.insert(Some(top_id), 0, sq).unwrap();
+ let draw = |outline: bool| {
+ let opts = RenderOptions { background: Some([255, 255, 255, 255]), outline, ..Default::default() };
+ Renderer::new().render(&d, 100, 100, Affine::IDENTITY, &opts)
+ };
+ let (preview, outline) = (draw(false), draw(true));
+ let [r, g, b, _] = outline.pixel(65, 25);
+ assert!(r == 255 && (120..=135).contains(&g) && g == b, "the template's image, dimmed: {:?}", outline.pixel(65, 25));
+ assert_eq!(outline.pixel(65, 25), preview.pixel(65, 25), "as in Preview");
+ assert_eq!(outline.pixel(25, 75), [255, 255, 255, 255], "the drawing layer has no fill in outline");
+ assert_eq!(preview.pixel(25, 75), [255, 0, 0, 255]);
+}
+
/// A guide path draws on screen only: exports leave it out, as they leave templates out (and as
/// the SVG, PSD and PDF exports and printing already do).
#[test]