diff --git a/crates/render/src/fx/entries.rs b/crates/render/src/fx/entries.rs index 32df616e25..9714d5f8a8 100644 --- a/crates/render/src/fx/entries.rs +++ b/crates/render/src/fx/entries.rs @@ -221,17 +221,18 @@ pub(crate) struct Reads { /// Pattern paints: the pattern definitions. Their art can hold anything, so content painted /// with a pattern reads everything else too. pub(super) patterns: bool, - /// Symbol instances and type with inline graphics: the symbols' art. Symbol art can hold - /// anything, so content that shows a symbol reads everything else too. + /// Symbol instances, type with inline graphics, pattern art and brush art: the symbols' art. + /// Symbol art can hold anything, so content that shows a symbol reads everything else too. pub(super) symbols: bool, - /// Images, placed documents and brush art: their pixels and files, and the options and the - /// layer's Dim Images they are drawn with. + /// Images, placed documents, symbol art, pattern art and brush art: their pixels and files, + /// and the options and the layer's Dim Images they are drawn with. pub(super) images: bool, /// Placed documents, symbol art and brushed strokes: the global bitmap generation while /// progressive previews are on. Symbol and brush art can hold placed documents. Pattern tiles /// draw with progressive previews off. pub(super) placed_documents: bool, - /// Brushed strokes: the brush library. + /// Brushed strokes, symbol art and pattern art: the brush library. Brush art can hold + /// anything, so content that uses a brushed stroke reads everything else too. pub(super) brushes: bool, /// Type: the fonts, whether overprinting shows ([`crate::proof::overprints`]) and the /// substitution highlights. @@ -247,16 +248,15 @@ impl Reads { Self::of_all(std::iter::once(n)) } - /// What the content of `nodes` reads together. Pattern and symbol art can hold anything, so - /// content showing either reads the other document resources too (#1723). Progressive bitmap + /// What the content of `nodes` reads together. Pattern, symbol and brush art can hold anything, + /// so content showing any of them reads the other document resources too (#1723). Progressive bitmap /// readiness follows content that holds placed documents, shows symbol art or uses brushed /// strokes. Pattern tiles draw with progressive previews off. pub(crate) fn of_all<'a>(nodes: impl Iterator) -> Self { let mut reads = Self::default(); nodes.for_each(|n| reads.add(n)); reads.placed_documents |= reads.symbols || reads.brushes; - reads.images |= reads.brushes; - if reads.symbols || reads.patterns { + if reads.symbols || reads.patterns || reads.brushes { return Self { patterns: true, symbols: true, diff --git a/crates/render/src/fx/tests.rs b/crates/render/src/fx/tests.rs index 3c866b6aaf..a0e1f9e61a 100644 --- a/crates/render/src/fx/tests.rs +++ b/crates/render/src/fx/tests.rs @@ -62,7 +62,8 @@ fn reads_follow_progressive_placed_documents_in_content_and_art() { assert!(!Reads::of(&patterned).placed_documents, "a pattern-only path does not read progressive bitmap readiness"); } -/// Brush and symbol art can hold images drawn with the frame's image options. +/// Brush and symbol art can hold images drawn with the frame's image options, and brush art can +/// show symbols. #[test] fn reads_follow_images_in_brush_and_symbol_art() { use super::Reads; @@ -73,6 +74,7 @@ fn reads_follow_images_in_brush_and_symbol_art() { appearance.stroke_mut().unwrap().brush = Some("Stamp".into()); let brushed = Node::path(d.alloc_id(), shapes::line((0.0, 0.0).into(), (20.0, 20.0).into()), appearance); assert!(Reads::of(&brushed).images, "a brushed stroke reads images"); + assert!(Reads::of(&brushed).symbols, "a brushed stroke reads symbol art"); let symbol = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: "Stamp".into(), xf: Affine::IDENTITY }); assert!(Reads::of(&symbol).images, "a symbol instance reads images"); @@ -2136,6 +2138,49 @@ fn image_smoothing_filters_a_brushed_strokes_raster_again_after_a_pan() { assert!(pixels == Renderer::new().render(&d, 160, 100, view, &opts).pixels, "image smoothing draws as a new renderer does"); } +/// A symbol's fill color changes the pixels of an effected stroke whose scatter brush shows it. +#[test] +fn editing_a_symbol_in_brush_art_filters_a_brushed_strokes_raster_again_after_a_pan() { + use vectorcraft_brush::{Brush, BrushKind, Colorization, Scatter}; + use vectorcraft_doc::{NodeKind, Symbol}; + + let mut d = Document::new(160.0, 100.0); + let mut art = Node::path( + d.alloc_id(), + shapes::rectangle(Rect::new(-4.0, -4.0, 4.0, 4.0)), + Appearance::basic(Paint::solid(Color::rgb(0.9, 0.1, 0.1)), Paint::None, 0.0), + ); + d.symbols.push(Symbol { dynamic: false, name: "Stamp".into(), art: Arc::new(art.clone()) }); + let instance = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: "Stamp".into(), xf: Affine::IDENTITY }); + vectorcraft_brush::store( + &mut d, + &[Brush { + name: "Stamps".into(), + kind: BrushKind::Scatter(Scatter { art: instance, colorization: Colorization::None, ..Default::default() }), + }], + ); + let mut appearance = Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 2.0); + appearance.stroke_mut().unwrap().brush = Some("Stamps".into()); + let mut n = Node::path(d.alloc_id(), shapes::line((20.0, 50.0).into(), (100.0, 50.0).into()), appearance); + n.appearance.effects = vec![Effect { id: "blur.gaussian".into(), params: json!({"radius": 1}), visible: true }]; + let l = d.layers[0].id; + d.insert(Some(l), 0, n).unwrap(); + let opts = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() }; + let mut r = Renderer::new(); + let _ = r.render(&d, 160, 100, Affine::IDENTITY, &opts); + let kept = r.pixel_fx.values().next().unwrap(); + assert!(kept.view.is_none(), "a raster of the whole object"); + let image = kept.image.clone(); + let view = Affine::translate((4.0, 0.0)); + let unchanged = Renderer::new().render(&d, 160, 100, view, &opts).pixels; + art.appearance = Appearance::basic(Paint::solid(Color::rgb(0.1, 0.4, 0.9)), Paint::None, 0.0).into(); + d.symbols[0].art = Arc::new(art); + let pixels = r.render(&d, 160, 100, view, &opts).pixels; + assert!(!r.pixel_fx.values().any(|e| Arc::ptr_eq(&e.image, &image)), "editing a symbol in brush art filters the content again"); + assert!(pixels == Renderer::new().render(&d, 160, 100, view, &opts).pixels, "the edited symbol draws as a new renderer does"); + assert!(pixels != unchanged, "the edited symbol changes the brush art through the effect"); +} + /// Symbol editing leaves out the original instance inside a group's whole-object raster. #[test] fn symbol_editing_filters_the_whole_object_raster_again_after_a_pan() {