Effects: kept filtered rasters follow placed type, placed plug-ins and painted patterns

A whole-object effect keeps its filtered raster and reuses it after a
whole-pixel pan while the raster's inputs key is unchanged. Three inputs
were missing from that key:

- Type inside a placed document: the placed art draws with the frame's
  type options, but a placed document did not mark the content as
  reading type, so turning off Highlight Substituted Fonts (or another
  type option) kept the old pixels.
- Plug-ins used inside a placed document: installing or removing a
  plug-in that only the placed art uses did not change the key.
- Patterns painted by a plug-in: a plug-in's painted pieces can use any
  of the document's patterns, whose art can hold symbols, images,
  brushes and type, so editing a symbol in such a pattern kept the old
  pixels.

A placed document now sets Reads::text and a new holds_placed_documents
flag, which adds the plug-in revision to the key. When a plug-in counts,
an installed plug-in paints its pieces and the document has patterns,
the key also covers what pattern art can hold.
This commit is contained in:
dotCooCoo committed 2026-12-05 19:29:50 -08:00
1 parent efd00371e5
commit bdcb4c3c26
5 files changed
+226 -19

No files matched your search

+1 -1
View File
@@ -45,7 +45,7 @@ vectorcraft-testkit = { workspace = true }
# A variable font built in code (no font file is committed).
vectorcraft-text = { workspace = true, features = ["test-fonts"] }
# Live-effect plug-ins the cache tests install, written in WebAssembly text.
vectorcraft-plugins = { workspace = true }
vectorcraft-plugins = { workspace = true, features = ["test-steady"] }
wat = { workspace = true }
# Decoders the export tests read their files back with.
image = { workspace = true }
+16 -2
View File
@@ -231,11 +231,14 @@ pub(crate) struct Reads {
/// progressive previews are on. Symbol and brush art can hold placed documents. Pattern tiles
/// draw with progressive previews off.
pub(super) placed_documents: bool,
/// Placed document nodes in the content or its opacity masks: the installed plug-ins that
/// effects in the placed art draw with.
pub(super) holds_placed_documents: bool,
/// 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.
/// Type and placed documents, whose art can hold type: the fonts, whether overprinting shows
/// ([`crate::proof::overprints`]) and the substitution highlights.
pub(super) text: bool,
/// Plug-in effects on its objects: the plug-ins installed. Those in the symbol and pattern art
/// it shows are found with the document's inputs ([`DocInputs`]). Those in brush art are found
@@ -263,6 +266,7 @@ impl Reads {
symbols: true,
images: true,
placed_documents: reads.placed_documents,
holds_placed_documents: reads.holds_placed_documents,
brushes: true,
text: true,
plugins: reads.plugins,
@@ -287,6 +291,13 @@ impl Reads {
self.symbols || self.patterns
}
/// What content that reads `self` and shows pattern art reads: the patterns, symbols, images,
/// brushes and type that art can hold, with progressive bitmap readiness, placed documents and
/// the plug-ins as `self` reads them.
pub(super) fn with_definitions(self) -> Self {
Self { patterns: true, symbols: true, images: true, brushes: true, text: true, ..self }
}
fn add(&mut self, n: &Node) {
let pattern = |p: &vectorcraft_color::Paint| matches!(p, vectorcraft_color::Paint::Pattern { .. });
n.walk(&mut |c| {
@@ -298,7 +309,10 @@ impl Reads {
match &c.kind {
NodeKind::SymbolInstance { .. } => self.symbols = true,
NodeKind::Image(_) => self.images = true,
// A placed document's art can hold type, drawn with the frame's type options.
NodeKind::PlacedDocument(_) => {
self.holds_placed_documents = true;
self.text = true;
self.images = true;
self.placed_documents = true;
}
+31 -15
View File
@@ -613,15 +613,26 @@ impl Renderer {
/// image store holds); for content that holds placed documents, shows symbol art or uses
/// brushed strokes, whether placed documents draw from background bitmaps
/// ([`crate::placed_document::progressive_bitmaps`]) and, when progressive previews are on,
/// how many bitmaps are ready ([`crate::placed_document::generation`]); for type the fonts and the
/// hyphenation exceptions, whether overprinting shows ([`crate::proof::overprints`]) and
/// Document Setup's substitution highlights; and the plug-ins installed, with the names of the
/// document's swatches and patterns and its pattern definitions (a plug-in's painted pieces
/// can name them), when an object in the content has a plug-in effect, when it uses brushed
/// strokes and an object in the document's brush art has one, and when it shows symbol or
/// pattern art and an object in the document's symbol or pattern art has one.
/// how many bitmaps are ready ([`crate::placed_document::generation`]); for placed document
/// nodes in the content or its opacity masks, the installed plug-ins that effects in the placed
/// art draw with; for type and placed documents the fonts and the hyphenation exceptions,
/// whether overprinting shows ([`crate::proof::overprints`]) and Document Setup's substitution
/// highlights; and the plug-ins installed, with the names of the document's swatches and
/// patterns and its pattern definitions (a plug-in's painted pieces can name them), when an
/// object in the content has a plug-in effect, when it uses brushed strokes and an object in the
/// document's brush art has one, and when it shows symbol or pattern art and an object in the
/// document's symbol or pattern art has one. When those plug-ins count, an installed plug-in can
/// return painted output and the document has patterns, the content also reads what pattern art
/// can hold ([`Reads::with_definitions`]).
pub(crate) fn raster_inputs(&mut self, f: &Frame, n: &Node, reads: Reads) -> Inputs {
let doc = self.doc_inputs(f.doc);
// The frame's brush library is found before asking whether its art has a plug-in effect.
let library = reads.brushes.then(|| self.brushes.library_key(f.doc, self.stamp));
let plugins = reads.plugins || (library.is_some() && self.brushes.has_plugins()) || (doc.plugins && reads.shows_definitions());
// A plug-in's painted pieces can be painted with any of the document's patterns, and
// pattern art can hold anything. `painting_plugins` is the renderer's record of whether
// an installed plug-in paints its pieces.
let hashed = if plugins && !f.doc.patterns.is_empty() && self.painting_plugins { reads.with_definitions() } else { reads };
let mut h = DefaultHasher::new();
(doc.cms, f.opts.precise, std::mem::discriminant(&f.opts.anti_alias), self.knockout, f.doc.raster_effects_ppi.to_bits()).hash(&mut h);
// Cached effects on containers can include paths made into guides, drawn in the guide
@@ -638,13 +649,13 @@ impl Renderer {
{
isolated.hash(&mut h);
}
if reads.patterns {
if hashed.patterns {
doc.patterns.hash(&mut h);
}
if reads.symbols {
if hashed.symbols {
doc.symbols.hash(&mut h);
}
if reads.images {
if hashed.images {
let o = f.opts;
(doc.images, self.dim_images.map(f32::to_bits), o.smooth_images, o.image_mips, o.trace_views, o.progressive_placed).hash(&mut h);
self.shows_outline_images(f).hash(&mut h);
@@ -654,17 +665,22 @@ impl Renderer {
// or notes an image as undecodable.
o.kept_images_only.then(|| crate::images::store().added()).hash(&mut h);
}
if reads.placed_documents {
if hashed.placed_documents {
let progressive = crate::placed_document::progressive_bitmaps(f);
progressive.hash(&mut h);
if f.opts.progressive_placed {
crate::placed_document::generation().hash(&mut h);
}
}
if reads.brushes {
self.brushes.library_key(f.doc, self.stamp).hash(&mut h);
// A placed document too large to keep as a bitmap draws its art exactly, with progressive
// previews on too.
if hashed.holds_placed_documents {
effects::plugin_revision().hash(&mut h);
}
if reads.text {
if hashed.brushes {
library.unwrap_or_else(|| self.brushes.library_key(f.doc, self.stamp)).hash(&mut h);
}
if hashed.text {
let o = f.opts;
let highlights = o.highlight_substitutions.then_some((
o.highlight_substituted_fonts,
@@ -674,7 +690,7 @@ impl Renderer {
// Color bitmap glyphs are sampled as images are (`draw_glyph_image`).
(vectorcraft_text::layout_inputs(), crate::proof::overprints(f.opts), highlights, o.smooth_images).hash(&mut h);
}
if reads.plugins || (reads.brushes && self.brushes.has_plugins()) || (doc.plugins && (reads.symbols || reads.patterns)) {
if plugins {
(effects::plugin_revision(), doc.names, doc.patterns).hash(&mut h);
}
Inputs { reads, key: h.finish(), _doc: doc }
+77
View File
@@ -31,14 +31,17 @@ fn reads_follow_progressive_placed_documents_in_content_and_art() {
})),
);
assert!(Reads::of(&placed).placed_documents, "a placed document reads progressive bitmap readiness");
assert!(Reads::of(&placed).holds_placed_documents, "a placed document reads plug-in revisions in its art");
let symbol = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: "Stamp".into(), xf: Affine::IDENTITY });
assert!(Reads::of(&symbol).placed_documents, "a symbol instance reads progressive bitmap readiness");
assert!(!Reads::of(&symbol).holds_placed_documents, "a symbol instance does not hold placed document nodes");
let mut appearance = Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0);
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).placed_documents, "a brushed stroke reads progressive bitmap readiness");
assert!(!Reads::of(&brushed).holds_placed_documents, "a brushed stroke does not hold placed document nodes");
let image = Node::new(
d.alloc_id(),
@@ -80,6 +83,80 @@ fn reads_follow_images_in_brush_and_symbol_art() {
assert!(Reads::of(&symbol).images, "a symbol instance reads images");
}
/// Editing a symbol in a pattern's art filters an object again after a whole-pixel pan when a
/// plug-in on it paints its piece with that pattern, which the object's own paints do not name.
#[test]
fn editing_a_symbol_in_pattern_art_filters_a_painted_plugins_raster_again_after_a_pan() {
use vectorcraft_doc::pattern::PatternDef;
use vectorcraft_doc::{NodeKind, Symbol};
use vectorcraft_geom::{PathData, SubPath};
let _fonts = fonts_steady();
const ID: &str = "test.render.fx.painted-pattern";
let piece = PathData::single(SubPath::polyline(
&[Point::new(40.0, 30.0), Point::new(120.0, 30.0), Point::new(120.0, 70.0), Point::new(40.0, 70.0)],
true,
));
let stamps = serde_json::to_value(Paint::Pattern { pattern: "Stamps".into(), xf: Affine::IDENTITY }).unwrap();
let output = json!({"objects": [{"path": piece, "fills": [stamps]}]}).to_string();
let manifest = format!(r#"{{"id":"{ID}","name":"Test {ID}","version":"1","kind":"effect","api":3,"paintOutput":true,"params":{{}}}}"#);
let module = wat::parse_str(vectorcraft_plugins::wat::returning(&manifest, &output)).unwrap();
vectorcraft_plugins::registry::install_bytes(&module).unwrap();
let plugins = vectorcraft_plugins::steady::steady_plugins();
let mut d = Document::new(160.0, 100.0);
let art = Node::path(
d.alloc_id(),
shapes::rectangle(Rect::new(0.0, 0.0, 10.0, 10.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 });
let mut def = PatternDef::new("Stamps", vec![Arc::new(instance)]);
def.tile = Rect::new(0.0, 0.0, 20.0, 20.0);
d.patterns.push(def);
let mut n = Node::path(
d.alloc_id(),
shapes::rectangle(Rect::new(40.0, 30.0, 120.0, 70.0)),
Appearance::basic(Paint::solid(Color::BLACK), Paint::None, 0.0),
);
n.appearance.effects = vec![
Effect { id: format!("plugin.{ID}"), params: json!({}), visible: true },
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 { precise: true, background: Some([255, 255, 255, 255]), ..Default::default() };
for _ in 0..5 {
let mut d = d.clone();
let mut art = art.clone();
let mut r = Renderer::new();
let before = vectorcraft_text::layout_inputs();
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;
let fresh = Renderer::new().render(&d, 160, 100, view, &opts).pixels;
if before != vectorcraft_text::layout_inputs() {
continue;
}
assert!(!r.pixel_fx.values().any(|e| Arc::ptr_eq(&e.image, &image)), "editing a symbol in the painted pattern filters the content again");
assert!(pixels == fresh, "the edited symbol draws as a new renderer does");
assert!(pixels != unchanged, "the edited symbol changes the painted piece through the effect");
drop(plugins);
assert!(vectorcraft_plugins::registry::remove(ID), "the plug-in was installed");
return;
}
drop(plugins);
assert!(vectorcraft_plugins::registry::remove(ID), "the plug-in was installed");
panic!("the fonts changed during all 5 painted pattern attempts");
}
/// Rasterize and culling include the complete rendered image under lights from opposite sides.
#[test]
fn rendered_three_d_painted_bounds_hold_both_shadows() {
+101 -1
View File
@@ -12,7 +12,9 @@ use crate::*;
/// image whose pixels can't be decoded over its left half, one whose bytes start with `pict` also
/// shows a linked red image over its left half (its own Show Images in Outline Mode off), one
/// whose bytes start with `checker` also shows a 2×2 black and white checker image over all of it,
/// and one whose bytes start with `bad` can't be read.
/// one whose bytes start with `missing-type` also shows type in a family no font has, one whose
/// bytes start with `plugin` also shows a 20×20 black square at its top left with live-effect
/// plug-in [`PLACED_PLUGIN`] as its effect, and one whose bytes start with `bad` can't be read.
fn blue_page(p: &PlacedDocument, bytes: &[u8]) -> Option<(Document, Node, Rect)> {
if bytes.starts_with(b"bad") {
return None;
@@ -67,6 +69,22 @@ fn blue_page(p: &PlacedDocument, bytes: &[u8]) -> Option<(Document, Node, Rect)>
};
children.push(Arc::new(Node::new(NodeId(5), NodeKind::Image(Box::new(im)))));
}
if bytes.starts_with(b"missing-type") {
use vectorcraft_doc::text::{CharStyle, TextObject};
let style = CharStyle { size: 12.0, font_family: "No Such Family".into(), ..Default::default() };
let t = TextObject::point(vectorcraft_geom::Point::new(2.0, 14.0), "Hamburg", style);
children.push(Arc::new(Node::new(NodeId(6), NodeKind::Text(Box::new(t)))));
}
if bytes.starts_with(b"plugin") {
let mut square = Node::path(
NodeId(7),
shapes::rectangle(Rect::new(0.0, 0.0, 20.0, 20.0)),
Appearance::basic(Paint::solid(Color::BLACK), Paint::None, 0.0),
);
square.appearance.effects =
vec![vectorcraft_doc::Effect { id: format!("plugin.{PLACED_PLUGIN}"), params: serde_json::json!({}), visible: true }];
children.push(Arc::new(square));
}
if bytes.starts_with(b"loop") {
d.images.insert(p.key.clone(), ImageBlob::new("application/json", bytes.to_vec()));
let me = PlacedDocument { xf: Affine::translate((10.0, 5.0)) * Affine::scale(0.5), ..p.clone() };
@@ -75,6 +93,9 @@ fn blue_page(p: &PlacedDocument, bytes: &[u8]) -> Option<(Document, Node, Rect)>
Some((d, Node::new(NodeId(0), NodeKind::Group { children, clip: false }), Rect::new(0.0, 0.0, 40.0, 20.0)))
}
/// The live-effect plug-in that files read by [`blue_page`] whose bytes start with `plugin` use.
const PLACED_PLUGIN: &str = "test.render.placed-art";
/// A 100×100 document showing one placed file (`bytes` under `key`) in the box (10, 10)–(90, 50).
fn doc_with(key: &str, bytes: &[u8]) -> Document {
vectorcraft_doc::placed_document::set_loader(gated_blue_page);
@@ -650,6 +671,85 @@ fn overprint_preview_filters_the_whole_object_raster_again_after_a_pan() {
settle();
}
/// A 100×100 document showing one placed file (`bytes` under `key`) in the box (10, 10)–(90, 50),
/// in a group with a Gaussian blur.
fn blurred_placed(key: &str, bytes: &[u8]) -> Document {
vectorcraft_doc::placed_document::set_loader(gated_blue_page);
let mut d = Document::new(100.0, 100.0);
d.images.insert(key.into(), ImageBlob::new("application/json", bytes.to_vec()));
let placed = placed_node(d.alloc_id().0, key, 40.0, 20.0, Affine::translate((10.0, 10.0)) * Affine::scale(2.0));
let mut group = Node::group(d.alloc_id(), vec![Arc::new(placed)]);
group.appearance.effects = vec![vectorcraft_doc::Effect { id: "blur.gaussian".into(), params: serde_json::json!({"radius": 1}), visible: true }];
let l = d.layers[0].id;
d.insert(Some(l), 0, group).unwrap();
d
}
/// A group with a whole-object effect whose only type is in a placed document filters its content
/// again when Highlight Substituted Fonts turns off and the view pans by whole pixels.
#[test]
fn turning_off_substitution_highlights_filters_a_placed_documents_raster_again_after_a_pan() {
let _serial = serial();
let _fonts = crate::tests_fontchange::fonts_steady();
let _plugins = vectorcraft_plugins::steady::steady_plugins();
let d = blurred_placed("whole-object-highlights-1", b"missing-type whole-object highlights");
let on = RenderOptions { background: Some([255, 255, 255, 255]), progressive_placed: false, highlight_substitutions: true, ..Default::default() };
let off = RenderOptions { highlight_substituted_fonts: false, ..on.clone() };
// The first lookup of the missing family catalogs the installed fonts, which changes the font
// generation: a frame drawn first does that.
Renderer::new().render(&d, 100, 100, Affine::IDENTITY, &on);
for _ in 0..5 {
let mut r = Renderer::new();
let before = vectorcraft_text::layout_inputs();
let _ = r.render(&d, 100, 100, Affine::IDENTITY, &on);
let view = Affine::translate((4.0, 0.0));
let highlighted = Renderer::new().render(&d, 100, 100, view, &on).pixels;
let pixels = r.render(&d, 100, 100, view, &off).pixels;
let fresh = Renderer::new().render(&d, 100, 100, view, &off).pixels;
if before != vectorcraft_text::layout_inputs() {
continue;
}
assert!(fresh != highlighted, "the highlight shows on the placed type");
assert!(pixels == fresh, "turning off the highlight filters the content again after a whole-pixel pan");
return;
}
panic!("the fonts changed during all 5 placed document highlight attempts");
}
/// A group with a whole-object effect that holds a placed document filters its content again when
/// a plug-in used only in the placed art is installed and the view pans by whole pixels.
#[test]
fn installing_a_plugin_used_in_a_placed_document_filters_its_raster_again_after_a_pan() {
use vectorcraft_geom::{PathData, Point, SubPath};
use vectorcraft_plugins::wat as tpl;
let _serial = serial();
let _fonts = crate::tests_fontchange::fonts_steady();
let d = blurred_placed("whole-object-plugin-1", b"plugin whole-object");
let opts = RenderOptions { background: Some([255, 255, 255, 255]), progressive_placed: false, ..Default::default() };
let triangle = PathData::single(SubPath::polyline(&[Point::new(0.0, 0.0), Point::new(20.0, 0.0), Point::new(0.0, 20.0)], true));
let output = serde_json::json!({"objects": [{"path": triangle}]}).to_string();
let module = wat::parse_str(tpl::returning(&tpl::manifest(PLACED_PLUGIN, "effect", "{}"), &output)).unwrap();
for _ in 0..5 {
let mut r = Renderer::new();
let before = vectorcraft_text::layout_inputs();
let _ = r.render(&d, 100, 100, Affine::IDENTITY, &opts);
let view = Affine::translate((4.0, 0.0));
let without = Renderer::new().render(&d, 100, 100, view, &opts).pixels;
vectorcraft_plugins::registry::install_bytes(&module).unwrap();
let pixels = r.render(&d, 100, 100, view, &opts).pixels;
let fresh = Renderer::new().render(&d, 100, 100, view, &opts).pixels;
assert!(vectorcraft_plugins::registry::remove(PLACED_PLUGIN), "the plug-in was installed");
if before != vectorcraft_text::layout_inputs() {
continue;
}
assert!(fresh != without, "the plug-in changes the placed art through the effect");
assert!(pixels == fresh, "installing the placed art's plug-in filters the content again after a whole-pixel pan");
return;
}
panic!("the fonts changed during all 5 placed document plug-in attempts");
}
/// A group with a whole-object effect that holds only an ordinary image keeps its raster after a
/// placed document's bitmap in another document is ready and the view pans by whole pixels.
#[test]