VectorCraft: An open-source, vector art tool written by scratch in pure Rust
Fix #743: raster export leaves guides out
Juan Manuel Verges Solanasad8458832d53
diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rsindex 3bf40288f..a50cadc59 100644--- a/crates/render/src/lib.rs+++ b/crates/render/src/lib.rs@@ -85,7 +85,8 @@ pub struct RenderOptions {pub overprint_preview: bool,/// Trim View: clip the artwork to the artboards (nothing on the pasteboard is drawn).pub trim: bool,- /// Leave template layers out (exports and thumbnails: templates are guides, not artwork).+ /// Leave template layers and guides out (exports and thumbnails: they're aids to drawing, not+ /// artwork).pub skip_templates: bool,/// Pattern editing mode's tile edge and swatch bounds colour (Object → Pattern → Tile Edge/// Color), RGB.@@ -725,9 +726,9 @@ impl Renderer {Some(p)}- /// Whether `a` is left out of this frame: hidden, a skipped template, or culled.+ /// Whether `a` is left out of this frame: hidden, a skipped template or guide, or culled.fn skipped(&mut self, f: &Frame, a: &Arc<Node>) -> bool {- let skipped_template = f.opts.skip_templates && matches!(a.kind, NodeKind::Layer { template: true, .. });+ let skipped_template = f.opts.skip_templates && matches!(a.kind, NodeKind::Layer { template: true, .. } | NodeKind::Path { guide: true, .. });if !a.visible || skipped_template || f.opts.hidden.contains(&a.id) {return true;}diff --git a/crates/render/src/tests_layeropts.rs b/crates/render/src/tests_layeropts.rsindex 53e757584..db8b6eb26 100644--- a/crates/render/src/tests_layeropts.rs+++ b/crates/render/src/tests_layeropts.rs@@ -66,3 +66,22 @@ fn dim_images_fades_only_the_images() {assert_eq!(img.pixel(25, 25), [255, 0, 0, 255], "vector art stays");assert_eq!(render(&d, true).pixel(65, 25), [255, 0, 0, 255], "exports are not dimmed");}++/// 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]+fn guides_draw_on_screen_only() {+ let mut d = Document::new(100.0, 100.0);+ let l = d.layers[0].id;+ let mut g = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(70.0, 70.0, 90.0, 90.0)), Appearance::default());+ if let NodeKind::Path { guide, .. } = &mut g.kind {+ *guide = true;+ }+ d.insert(Some(l), 0, g).unwrap();+ let drawn = |export: bool| {+ let r = render(&d, export);+ (60..100).flat_map(|y| (60..100).map(move |x| (x, y))).filter(|&(x, y)| r.pixel(x, y) != [255, 255, 255, 255]).count()+ };+ assert!(drawn(false) > 0, "on screen the guide shows");+ assert_eq!(drawn(true), 0, "exports leave it out");+}