Merge pull request #11043 from dotCooCoo/fix/kept-filtered-raster-key

Effects: kept filtered rasters follow placed type, placed plug-ins and painted patterns
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-06 00:55:30 -08:00
commit 5d79bd23a3
9 files changed
+342 -24

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 }
+10
View File
@@ -63,6 +63,9 @@ pub(crate) struct BrushCache {
lib: HashMap<String, Arc<Brush>>,
/// Whether brush art or an opacity mask there has a visible plug-in effect.
plugins: bool,
/// Whether brush art or an opacity mask there holds a placed document, whose art can have
/// plug-in effects.
placed: bool,
/// The names and art of the document's patterns and symbols ([`definitions`]) when the library
/// was last validated, the art held weakly as the pattern tiles hold theirs.
definitions: Vec<(String, Weak<Node>)>,
@@ -81,6 +84,7 @@ impl Default for BrushCache {
checked: (0, 0),
lib: HashMap::new(),
plugins: false,
placed: false,
definitions: Vec::new(),
entries: FrameCache::new(lru::BRUSH_BUDGET, 512),
#[cfg(test)]
@@ -117,6 +121,7 @@ impl BrushCache {
self.lib.entry(b.name.clone()).or_insert_with(|| Arc::new(b));
}
self.plugins = self.lib.values().any(|b| b.art().into_iter().any(crate::holds_plugin_effect));
self.placed = self.lib.values().any(|b| b.art().into_iter().any(crate::holds_placed_document));
}
/// [`Self::key`] for the brush library `doc` holds (checked once a frame, `stamp`).
@@ -130,6 +135,11 @@ impl BrushCache {
self.plugins
}
/// Whether brush art holds a placed document, valid after [`Self::library_key`] for the frame.
pub(crate) fn has_placed_documents(&self) -> bool {
self.placed
}
/// [`Self::library_key`] checked now, between frames: `doc` may be the document of the last
/// frame, edited in place.
pub(crate) fn library_key_now(&mut self, doc: &Document, stamp: u64) -> u64 {
+22 -4
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,
@@ -277,9 +281,10 @@ impl Reads {
}
/// Can installing or removing a plug-in change what the content draws? It can when an object in
/// it has a plug-in effect, and when it shows symbol or pattern art.
/// it has a plug-in effect, when it holds a placed document, and when it shows symbol or pattern
/// art.
pub(crate) fn plugins_can_change(self) -> bool {
self.plugins || self.symbols || self.patterns
self.plugins || self.holds_placed_documents || self.symbols || self.patterns
}
/// Does the content show symbol or pattern art?
@@ -287,6 +292,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 +310,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;
}
@@ -369,6 +384,9 @@ pub(crate) struct DocInputs {
/// Whether an object in a pattern's or a symbol's art, or in an opacity mask there, has a
/// visible plug-in effect.
pub(super) plugins: bool,
/// Whether a pattern's or a symbol's art, or an opacity mask there, holds a placed document,
/// whose art can have plug-in effects.
pub(super) placed_documents: bool,
/// Weak references to the values whose addresses the hashes hold: a weak reference keeps the
/// allocation, not the value, so no other value gets one of those addresses while these
/// inputs are kept.
+38 -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 documents in
/// the content or its opacity masks, in the symbol and pattern art it shows and in the brush art
/// it uses, 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,27 @@ 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);
let library = hashed.brushes.then(|| library.unwrap_or_else(|| self.brushes.library_key(f.doc, self.stamp)));
if let Some(key) = library {
key.hash(&mut h);
}
if reads.text {
// A placed document too large to keep as a bitmap draws its art exactly, with progressive
// previews on too. Placed documents can be in the content, in the symbol and pattern art it
// shows and in the brush art it uses.
if hashed.holds_placed_documents
|| (doc.placed_documents && hashed.shows_definitions())
|| (library.is_some() && self.brushes.has_placed_documents())
{
effects::plugin_revision().hash(&mut h);
}
if hashed.text {
let o = f.opts;
let highlights = o.highlight_substitutions.then_some((
o.highlight_substituted_fonts,
@@ -674,7 +695,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 }
@@ -713,6 +734,7 @@ impl Renderer {
let art = doc_art().map(Arc::downgrade).collect();
let pixels = doc.images.values().flat_map(|b| std::iter::once(&b.bytes).chain(&b.proxy)).map(Arc::downgrade).collect();
let plugins = doc_art().any(|a| crate::holds_plugin_effect(a));
let placed_documents = doc_art().any(|a| crate::holds_placed_document(a));
Arc::new(DocInputs {
patterns,
symbols,
@@ -721,6 +743,7 @@ impl Renderer {
cms: found.4,
raster_ppi,
plugins,
placed_documents,
_held: (art, pixels, Arc::downgrade(&cms)),
})
}
+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() {
+1 -1
View File
@@ -310,9 +310,9 @@ use frame::{
use frame::{OFFSCREEN_PIXELS, Slices};
pub use geometry::region_pixels;
pub use node_checks::draws_plugin_effects;
use node_checks::holds_plugin_effect;
#[cfg(test)]
use node_checks::painted_items;
use node_checks::{holds_placed_document, holds_plugin_effect};
pub use options::{AntiAlias, ISOLATION_DIM, MAX_RASTER_PIXELS, MAX_RASTER_SIDE, RenderOptions, Rendered, raster_size, supersample_factor};
pub(crate) use paint::blend_mode;
use paint::fill_rule;
+9
View File
@@ -100,6 +100,15 @@ pub(crate) fn holds_type(n: &Node) -> bool {
holds
}
/// Does `n` hold a placed document, in it or in the opacity masks of the objects in it?
pub(crate) fn holds_placed_document(n: &Node) -> bool {
let mut holds = false;
n.walk(&mut |c| {
holds |= matches!(c.kind, NodeKind::PlacedDocument(_)) || c.extras().mask.as_ref().is_some_and(|m| holds_placed_document(&m.art))
});
holds
}
/// Is `n` a symbol instance, or does it hold one? Its cull bounds measure the instance by its
/// symbol's art.
pub(crate) fn holds_instance(n: &Node) -> bool {
+2 -2
View File
@@ -118,8 +118,8 @@ impl Default for PatternCache {
impl PatternCache {
/// When a plug-in has been installed or removed since the last check, drop the tiles whose art
/// can draw differently with it: art with a plug-in effect, and art that shows symbols or
/// patterns ([`crate::fx::Reads::plugins_can_change`]).
/// can draw differently with it: art with a plug-in effect, art that holds a placed document,
/// and art that shows symbols or patterns ([`crate::fx::Reads::plugins_can_change`]).
fn check_plugins(&mut self) {
let revision = crate::effects::plugin_revision();
if revision == self.plugin_revision {
+182 -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,166 @@ 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() {
let _serial = serial();
let _fonts = crate::tests_fontchange::fonts_steady();
let d = blurred_placed("whole-object-plugin-1", b"plugin whole-object");
installing_the_placed_plugin_filters_again(&d, "a placed document");
}
/// A group with a whole-object effect that shows a symbol whose art 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_in_symbol_art_filters_its_raster_again_after_a_pan() {
let _serial = serial();
let _fonts = crate::tests_fontchange::fonts_steady();
vectorcraft_doc::placed_document::set_loader(gated_blue_page);
let key = "whole-object-plugin-symbol-1";
let mut d = Document::new(100.0, 100.0);
d.images.insert(key.into(), ImageBlob::new("application/json", b"plugin whole-object symbol".to_vec()));
let placed = placed_node(d.alloc_id().0, key, 40.0, 20.0, Affine::scale(2.0));
d.symbols.push(vectorcraft_doc::Symbol { dynamic: false, name: "Card".into(), art: Arc::new(placed) });
let instance = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: "Card".into(), xf: Affine::translate((10.0, 10.0)) });
let mut group = Node::group(d.alloc_id(), vec![Arc::new(instance)]);
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();
installing_the_placed_plugin_filters_again(&d, "a placed document in symbol art");
}
/// A stroke with a whole-object effect whose scatter brush shows 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_in_brush_art_filters_its_raster_again_after_a_pan() {
use vectorcraft_brush::{Brush, BrushKind, Colorization, Scatter};
let _serial = serial();
let _fonts = crate::tests_fontchange::fonts_steady();
vectorcraft_doc::placed_document::set_loader(gated_blue_page);
let key = "whole-object-plugin-brush-1";
let mut d = Document::new(100.0, 100.0);
d.images.insert(key.into(), ImageBlob::new("application/json", b"plugin whole-object brush".to_vec()));
let art = placed_node(d.alloc_id().0, key, 40.0, 20.0, Affine::translate((-20.0, -10.0)));
vectorcraft_brush::store(
&mut d,
&[Brush { name: "Cards".into(), kind: BrushKind::Scatter(Scatter { art, colorization: Colorization::None, ..Default::default() }) }],
);
let mut appearance = Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 2.0);
if let Some(s) = appearance.stroke_mut() {
s.brush = Some("Cards".into());
}
let mut n = Node::path(d.alloc_id(), shapes::line((20.0, 50.0).into(), (80.0, 50.0).into()), appearance);
n.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, n).unwrap();
installing_the_placed_plugin_filters_again(&d, "a placed document in brush art");
}
/// A path with a whole-object effect filled with a pattern whose art is 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_in_pattern_art_filters_its_raster_again_after_a_pan() {
let _serial = serial();
let _fonts = crate::tests_fontchange::fonts_steady();
vectorcraft_doc::placed_document::set_loader(gated_blue_page);
let key = "whole-object-plugin-pattern-1";
let mut d = Document::new(100.0, 100.0);
d.images.insert(key.into(), ImageBlob::new("application/json", b"plugin whole-object pattern".to_vec()));
let art = placed_node(d.alloc_id().0, key, 40.0, 20.0, Affine::IDENTITY);
let mut def = vectorcraft_doc::pattern::PatternDef::new("Cards", vec![Arc::new(art)]);
def.tile = Rect::new(0.0, 0.0, 50.0, 30.0);
d.patterns.push(def);
let fill = vectorcraft_doc::pattern::pattern_paint("Cards");
let mut n = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(10.0, 10.0, 90.0, 90.0)), Appearance::basic(fill, Paint::None, 0.0));
n.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, n).unwrap();
installing_the_placed_plugin_filters_again(&d, "a placed document in pattern art");
}
/// Draws `d` (100×100), whose only plug-in effect is [`PLACED_PLUGIN`] in the art of a placed
/// document it shows somewhere (`what`), installs that plug-in and draws it again after a 4 px pan
/// with the same renderer. Checks that the plug-in changes the pixels and that the renderer draws
/// what a new renderer draws.
fn installing_the_placed_plugin_filters_again(d: &Document, what: &str) {
use vectorcraft_geom::{PathData, Point, SubPath};
use vectorcraft_plugins::wat as tpl;
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 {what} through the effect");
assert!(pixels == fresh, "installing the plug-in used in {what} filters the content again after a whole-pixel pan");
return;
}
panic!("the fonts changed during all 5 attempts with {what}");
}
/// 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]