mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 16:07:33 +00:00
Merge main into feat/character-anti-aliasing-method
This commit is contained in:
+112
-20
@@ -1,17 +1,23 @@
|
||||
//! Brushed strokes and symbol-instance staining in the renderer.
|
||||
//!
|
||||
//! A stroke with `brush: Some(name)` is painted as the filled art `vectorcraft_brush::stroke_pieces`
|
||||
//! generates. Pieces are cached per (node, stroke item) and validated by the node's path, the
|
||||
//! generates. Pieces are cached per (node id, stroke item, path) and validated by the path, the
|
||||
//! stroke layer and the brush definition (an `Arc` from the per-frame parsed library), so edits to
|
||||
//! any of them regenerate the art and nothing else does.
|
||||
//! any of them regenerate the art and nothing else does. The copies of an object that share its id
|
||||
//! (symbol instances, inline graphics, repeat copies) have their own paths, so each keeps its own
|
||||
//! pieces. The pieces keep their `Arc`s while they are cached, so their stroke outlines, live-effect
|
||||
//! geometry and the evaluations of live objects come from the renderer's caches too. Brush art
|
||||
//! leaves out the symbol instances and pattern paints whose art draws a brushed stroke, so when
|
||||
//! the art of a symbol or pattern changes, the pieces of brushes and strokes that can show one are
|
||||
//! made again.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Weak};
|
||||
|
||||
use vectorcraft_brush::Brush;
|
||||
use vectorcraft_brush::{Brush, BrushKind};
|
||||
use vectorcraft_doc::{AppearanceItem, Document, Node, NodeKind, StrokeLayer, SymbolBoxes};
|
||||
use vectorcraft_geom::{BezPath, Rect};
|
||||
use vectorcraft_geom::{BezPath, PathEl, Point, Rect};
|
||||
use vello_cpu::RenderContext;
|
||||
|
||||
use crate::lru::{self, FrameCache};
|
||||
@@ -21,7 +27,28 @@ pub(crate) struct Entry {
|
||||
path: BezPath,
|
||||
stroke: StrokeLayer,
|
||||
brush: Arc<Brush>,
|
||||
pieces: Arc<Vec<Node>>,
|
||||
pieces: Arc<Vec<Arc<Node>>>,
|
||||
/// Can the pieces show symbol or pattern art ([`shows_definitions`])?
|
||||
definitions: bool,
|
||||
}
|
||||
|
||||
/// Can the brush art of `brush` along a stroke `st` show symbol or pattern art: does the stroke
|
||||
/// paint with a pattern, or does the brush's own art show a symbol or a pattern?
|
||||
fn shows_definitions(brush: &Brush, st: &StrokeLayer) -> bool {
|
||||
let art: Vec<&Node> = match &brush.kind {
|
||||
BrushKind::Art(a) => vec![&a.art],
|
||||
BrushKind::Scatter(s) => vec![&s.art],
|
||||
BrushKind::Pattern(p) => {
|
||||
[Some(&p.side), p.outer_corner.as_ref(), p.inner_corner.as_ref(), p.start.as_ref(), p.end.as_ref()].into_iter().flatten().collect()
|
||||
}
|
||||
BrushKind::Calligraphic(_) | BrushKind::Bristle(_) => vec![],
|
||||
};
|
||||
matches!(st.paint, vectorcraft_color::Paint::Pattern { .. }) || crate::fx::Reads::of_all(art.into_iter()).shows_definitions()
|
||||
}
|
||||
|
||||
/// The art of `doc`'s patterns and symbols, in order.
|
||||
fn definitions(doc: &Document) -> impl Iterator<Item = &Arc<Node>> {
|
||||
doc.patterns.iter().flat_map(|p| &p.art).chain(doc.symbols.iter().map(|s| &s.art))
|
||||
}
|
||||
|
||||
/// Parsed brush library and generated brush art.
|
||||
@@ -34,12 +61,28 @@ pub(crate) struct BrushCache {
|
||||
/// (frame stamp, document address) the library was last validated for.
|
||||
checked: (u64, usize),
|
||||
lib: HashMap<String, Arc<Brush>>,
|
||||
pub(crate) entries: FrameCache<(u64, usize), Entry>,
|
||||
/// The art of the document's patterns and symbols ([`definitions`]) when the library was last
|
||||
/// validated, held weakly as the pattern tiles hold theirs.
|
||||
definitions: Vec<Weak<Node>>,
|
||||
/// Brush art per (node id, stroke item index, [`path_key`] of the stroked path).
|
||||
pub(crate) entries: FrameCache<(u64, usize, u64), Entry>,
|
||||
/// How many times [`Renderer::draw_brush`] made brush art.
|
||||
#[cfg(test)]
|
||||
pub(crate) made: usize,
|
||||
}
|
||||
|
||||
impl Default for BrushCache {
|
||||
fn default() -> Self {
|
||||
Self { src: None, key: 0, checked: (0, 0), lib: HashMap::new(), entries: FrameCache::new(lru::BRUSH_BUDGET, 512) }
|
||||
Self {
|
||||
src: None,
|
||||
key: 0,
|
||||
checked: (0, 0),
|
||||
lib: HashMap::new(),
|
||||
definitions: Vec::new(),
|
||||
entries: FrameCache::new(lru::BRUSH_BUDGET, 512),
|
||||
#[cfg(test)]
|
||||
made: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +93,10 @@ impl BrushCache {
|
||||
return;
|
||||
}
|
||||
self.checked = key;
|
||||
if !self.definitions.iter().map(Weak::as_ptr).eq(definitions(doc).map(Arc::as_ptr)) {
|
||||
self.definitions = definitions(doc).map(Arc::downgrade).collect();
|
||||
self.entries.retain(|e| !e.definitions);
|
||||
}
|
||||
let cur = doc.unknown.get(vectorcraft_brush::DOC_KEY);
|
||||
if self.src.as_ref().is_some_and(|s| s.as_ref() == cur) {
|
||||
return;
|
||||
@@ -94,6 +141,26 @@ pub(crate) fn pad(symbols: &SymbolBoxes, n: &Node) -> f64 {
|
||||
|
||||
pub use vectorcraft_brush::instance_art;
|
||||
|
||||
/// A hash of the kinds and points of `bp`'s elements. With the node id and the stroke item, it
|
||||
/// forms the key of the brush art made along `bp`.
|
||||
fn path_key(bp: &BezPath) -> u64 {
|
||||
let mut h = DefaultHasher::new();
|
||||
for el in bp.elements() {
|
||||
let (kind, points) = match *el {
|
||||
PathEl::MoveTo(p) => (0u8, [p, Point::ZERO, Point::ZERO]),
|
||||
PathEl::LineTo(p) => (1, [p, Point::ZERO, Point::ZERO]),
|
||||
PathEl::QuadTo(a, b) => (2, [a, b, Point::ZERO]),
|
||||
PathEl::CurveTo(a, b, c) => (3, [a, b, c]),
|
||||
PathEl::ClosePath => (4, [Point::ZERO; 3]),
|
||||
};
|
||||
kind.hash(&mut h);
|
||||
for p in points {
|
||||
(p.x.to_bits(), p.y.to_bits()).hash(&mut h);
|
||||
}
|
||||
}
|
||||
h.finish()
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
/// Paint stroke `st` of `n` (outline `bp`) with its brush. Returns false when the brush is
|
||||
/// unknown (the caller then draws a plain stroke).
|
||||
@@ -102,22 +169,25 @@ impl Renderer {
|
||||
self.brushes.library(f.doc, self.stamp);
|
||||
let Some(brush) = self.brushes.lib.get(name).cloned() else { return false };
|
||||
let idx = n.appearance.items.iter().position(|i| matches!(i, AppearanceItem::Stroke(s) if std::ptr::eq(s, st))).unwrap_or(usize::MAX);
|
||||
let key = (n.id.0, idx);
|
||||
let key = (n.id.0, idx, path_key(bp));
|
||||
let stamp = self.stamp;
|
||||
let pieces = match self.brushes.entries.get(&key, stamp) {
|
||||
Some(e) if Arc::ptr_eq(&e.brush, &brush) && e.stroke == *st && e.path == *bp => e.pieces.clone(),
|
||||
let (pieces, kept) = match self.brushes.entries.get(&key, stamp) {
|
||||
Some(e) if Arc::ptr_eq(&e.brush, &brush) && e.stroke == *st && e.path == *bp => (e.pieces.clone(), true),
|
||||
_ => {
|
||||
let pieces = Arc::new(vectorcraft_brush::stroke_pieces(f.doc, &brush, bp, st));
|
||||
let bytes = size_of::<Entry>() + lru::path_bytes(bp) + pieces.iter().map(lru::node_bytes).sum::<usize>();
|
||||
self.brushes.entries.insert(key, Entry { path: bp.clone(), stroke: st.clone(), brush, pieces: pieces.clone() }, bytes, stamp);
|
||||
pieces
|
||||
}
|
||||
};
|
||||
let mut draw = |r: &mut Self, c: &mut RenderContext, fr: &Frame| {
|
||||
for p in pieces.iter() {
|
||||
r.draw_node(c, fr, p, true);
|
||||
#[cfg(test)]
|
||||
{
|
||||
self.brushes.made += 1;
|
||||
}
|
||||
let pieces: Arc<Vec<Arc<Node>>> =
|
||||
Arc::new(vectorcraft_brush::stroke_pieces(f.doc, &brush, bp, st).into_iter().map(Arc::new).collect());
|
||||
let bytes = size_of::<Entry>() + lru::path_bytes(bp) + pieces.iter().map(|p| lru::node_bytes(p)).sum::<usize>();
|
||||
let definitions = shows_definitions(&brush, st);
|
||||
let entry = Entry { path: bp.clone(), stroke: st.clone(), brush, pieces: pieces.clone(), definitions };
|
||||
let kept = self.brushes.entries.insert(key, entry, bytes, stamp);
|
||||
(pieces, kept)
|
||||
}
|
||||
};
|
||||
let mut draw = |r: &mut Self, c: &mut RenderContext, fr: &Frame| r.draw_brush_pieces(c, fr, &pieces, kept);
|
||||
if st.opacity < 1.0 || st.blend != vectorcraft_color::BlendMode::Normal {
|
||||
self.group(ctx, f, crate::group::Composite { blend: st.blend, opacity: st.opacity, ..Default::default() }, &mut draw);
|
||||
} else {
|
||||
@@ -125,6 +195,28 @@ impl Renderer {
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// Draw brush art `pieces`, each whatever its visibility and bounds. A piece that is a path
|
||||
/// without effects is drawn as `cur`. When the brush cache keeps the pieces (`kept`), their
|
||||
/// `Arc`s stay the same from frame to frame: such a path piece takes its stroke outlines from the
|
||||
/// stroke cache as on the fast path ([`Self::cached_stroke`]), and each piece is also drawn as
|
||||
/// `fx_owner` through [`Self::draw_kept_node`], so its live-effect geometry and, when it is a
|
||||
/// live object, its evaluation come from the caches. Pieces the cache does not keep are drawn as
|
||||
/// art made again ([`Self::made_again`]).
|
||||
fn draw_brush_pieces(&mut self, ctx: &mut RenderContext, f: &Frame, pieces: &[Arc<Node>], kept: bool) {
|
||||
let outer = (std::mem::replace(&mut self.made_again, !kept), self.cur.take());
|
||||
for p in pieces {
|
||||
self.cur = (matches!(p.kind, NodeKind::Path { guide: false, .. }) && !crate::fx::has_fx(p)).then(|| p.clone());
|
||||
if kept {
|
||||
let owner = self.fx_owner.replace(p.clone());
|
||||
self.draw_kept_node(ctx, f, p);
|
||||
self.fx_owner = owner;
|
||||
} else {
|
||||
self.draw_node(ctx, f, p, true);
|
||||
}
|
||||
}
|
||||
(self.made_again, self.cur) = outer;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
+17
-2
@@ -978,6 +978,11 @@ impl Reads {
|
||||
self.plugins || self.symbols || self.patterns
|
||||
}
|
||||
|
||||
/// Does the content show symbol or pattern art?
|
||||
pub(crate) fn shows_definitions(self) -> bool {
|
||||
self.symbols || self.patterns
|
||||
}
|
||||
|
||||
fn add(&mut self, n: &Node) {
|
||||
let pattern = |p: &vectorcraft_color::Paint| matches!(p, vectorcraft_color::Paint::Pattern { .. });
|
||||
n.walk(&mut |c| {
|
||||
@@ -1040,7 +1045,8 @@ impl Inputs {
|
||||
/// pixels, the address of the color settings, and whether the patterns' and symbols' art has a
|
||||
/// plug-in effect. Art, pixels and previews are hashed by the addresses of their shared values,
|
||||
/// and names, keys, tiles, tile types and overlaps are hashed by value. The live cache keeps these
|
||||
/// inputs with each evaluated live object and with each mesh's quads (`crate::live`), and
|
||||
/// inputs with each evaluated live object, with each mesh's quads and with what each walk of a
|
||||
/// live object or of effect art found when it found no placed file (`crate::live`), and
|
||||
/// [`Renderer::fx_art`] keeps them with art that can be made from evaluated live objects.
|
||||
pub(crate) struct DocInputs {
|
||||
patterns: u64,
|
||||
@@ -1056,6 +1062,14 @@ pub(crate) struct DocInputs {
|
||||
_held: Held,
|
||||
}
|
||||
|
||||
impl DocInputs {
|
||||
/// Whether `self` and `other` were made from the same patterns and symbols: their names,
|
||||
/// tilings and art.
|
||||
pub(crate) fn same_art(&self, other: &DocInputs) -> bool {
|
||||
(self.patterns, self.symbols) == (other.patterns, other.symbols)
|
||||
}
|
||||
}
|
||||
|
||||
/// The pattern and symbol art, the image pixels and the color settings, held weakly.
|
||||
type Held = (Vec<Weak<Node>>, Vec<Weak<Vec<u8>>>, Weak<Cms>);
|
||||
|
||||
@@ -2117,6 +2131,7 @@ impl Renderer {
|
||||
if reads.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);
|
||||
o.trace_source.as_deref().hash(&mut h);
|
||||
}
|
||||
if reads.brushes {
|
||||
self.brushes.library_key(f.doc, self.stamp).hash(&mut h);
|
||||
@@ -2383,7 +2398,7 @@ impl Renderer {
|
||||
if st.brush.is_some() && self.draw_brush(ctx, f, n, ig, st) {
|
||||
return;
|
||||
}
|
||||
self.draw_stroke(ctx, f, Affine::IDENTITY, ig, rule, st, ib);
|
||||
self.draw_stroke(ctx, f, Affine::IDENTITY, ig, rule, st, None, ib);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,10 @@ pub(crate) struct Region {
|
||||
pub h: u16,
|
||||
}
|
||||
|
||||
/// Groups drawn twice ([`Renderer::group_offscreen`]: blending with their backdrop) that may be
|
||||
/// nested in each other before deeper ones are drawn isolated, once.
|
||||
const MAX_TWICE_DRAWN: u32 = 4;
|
||||
|
||||
impl Renderer {
|
||||
/// Draw a group's content with `draw` and composite it as `c` says. Blending content is drawn
|
||||
/// offscreen: over a copy of the backdrop when the group isn't isolated (possible only with
|
||||
@@ -110,6 +114,12 @@ impl Renderer {
|
||||
|
||||
fn group_offscreen(&mut self, ctx: &mut RenderContext, f: &Frame, c: Composite, r: Region, draw: &mut Content) {
|
||||
let Composite { clip, blend, opacity, mask, isolated, .. } = c;
|
||||
// A group that blends with its backdrop is drawn twice (over the backdrop, and alone for
|
||||
// its coverage), and so is everything in it, so such groups nested in each other cost 2ⁿ.
|
||||
// Past [`MAX_TWICE_DRAWN`] of them, a deeper one is drawn as an isolated group.
|
||||
let twice = !isolated && blend != Blend::Normal;
|
||||
let isolated = isolated || twice && self.twice_drawn >= MAX_TWICE_DRAWN;
|
||||
let twice = twice && !isolated;
|
||||
if self.offscreen_live == 0 {
|
||||
self.offscreen_budget = OFFSCREEN_FRAMES * u64::from(ctx.width()) * u64::from(ctx.height());
|
||||
}
|
||||
@@ -117,6 +127,7 @@ impl Renderer {
|
||||
self.offscreen_live = self.offscreen_live.saturating_add(cost);
|
||||
let sub = frame_over(f, r);
|
||||
let backdrop = (!isolated).then(|| self.flatten(ctx, r));
|
||||
self.twice_drawn += u32::from(twice);
|
||||
let content = self.offscreen(r, &sub, backdrop.clone(), draw);
|
||||
let at = (r.x as f64, r.y as f64);
|
||||
let push = |ctx: &mut RenderContext, mode: BlendMode| {
|
||||
@@ -162,6 +173,7 @@ impl Renderer {
|
||||
}
|
||||
}
|
||||
ctx.pop_layer();
|
||||
self.twice_drawn -= u32::from(twice);
|
||||
self.offscreen_live = self.offscreen_live.saturating_sub(cost);
|
||||
}
|
||||
|
||||
|
||||
@@ -157,6 +157,12 @@ impl ImageStore {
|
||||
}
|
||||
}
|
||||
|
||||
/// Bytes of the entries someone besides the store holds (images being painted): eviction can't
|
||||
/// free them.
|
||||
pub(crate) fn pinned_bytes(&self) -> usize {
|
||||
self.entries.values().filter(|e| Arc::strong_count(&e.pm) > 1).map(|e| pixmap_bytes(&e.pm)).sum()
|
||||
}
|
||||
|
||||
pub(crate) fn set_budget(&mut self, budget: usize) {
|
||||
self.budget = budget;
|
||||
self.evict();
|
||||
|
||||
+160
-46
@@ -160,6 +160,10 @@ pub struct RenderOptions {
|
||||
/// Screen view: Image Trace objects draw as their View asks (outlines, the source image…);
|
||||
/// off, they draw their tracing result, as exports and printing do.
|
||||
pub trace_views: bool,
|
||||
/// Screen view with `trace_views` on: the Image Trace objects drawn with the Source Image view
|
||||
/// for this render only, whatever View they have (the Image Trace panel's eye button, while it
|
||||
/// is held down).
|
||||
pub trace_source: Option<Arc<Vec<NodeId>>>,
|
||||
/// Images are sampled smoothly when scaled or rotated; off, each pixel takes its nearest image
|
||||
/// pixel (Pixel Preview with File Handling › Display Bitmaps as Anti-aliased Images off).
|
||||
pub smooth_images: bool,
|
||||
@@ -267,6 +271,7 @@ impl Default for RenderOptions {
|
||||
anti_alias: AntiAlias::Art,
|
||||
progressive_placed: false,
|
||||
trace_views: false,
|
||||
trace_source: None,
|
||||
smooth_images: true,
|
||||
isolated: None,
|
||||
precise: false,
|
||||
@@ -391,6 +396,10 @@ impl std::hash::Hasher for PtrHasher {
|
||||
|
||||
type PtrMap<K, V> = HashMap<K, V, std::hash::BuildHasherDefault<PtrHasher>>;
|
||||
|
||||
/// The key of a cached stroke outline: ([`Renderer::stroke_owner`] of what owns the stroke, the
|
||||
/// stroke's place in it, width bits, tolerance level).
|
||||
type StrokeKey = (usize, usize, u64, i32);
|
||||
|
||||
/// A stroke expanded to a fill outline: (owning node, outline, last frame used).
|
||||
struct StrokeEntry {
|
||||
node: Arc<Node>,
|
||||
@@ -486,12 +495,19 @@ pub struct Renderer {
|
||||
plugin_revision: u64,
|
||||
/// Expanded stroke outlines keyed by ([`Self::stroke_owner`], stroke layer address, width bits,
|
||||
/// tolerance level): panning re-renders reuse them instead of re-expanding every stroke.
|
||||
strokes: PtrMap<(usize, usize, u64, i32), StrokeEntry>,
|
||||
/// The node being drawn on the plain-path fast path (owner of cached stroke outlines).
|
||||
strokes: PtrMap<StrokeKey, StrokeEntry>,
|
||||
/// Expanded character stroke outlines, with the glyph geometry kept in `texts` they belong to,
|
||||
/// keyed by ([`Self::stroke_owner`] of that geometry, run, width bits, tolerance level): type
|
||||
/// that doesn't change draws them again instead of expanding its strokes in every frame. Within
|
||||
/// a byte budget, and swept by frame, so the outlines of type that changes in every frame go
|
||||
/// within a few frames.
|
||||
char_strokes: FrameCache<StrokeKey, (Arc<TextGeom>, Arc<BezPath>)>,
|
||||
/// The node being drawn on the plain-path fast path, or the path of brush art being drawn
|
||||
/// ([`Self::draw_brush_pieces`]): the owner of cached stroke outlines.
|
||||
cur: Option<Arc<Node>>,
|
||||
/// Whether the art being drawn is made again in every frame: symbol art that
|
||||
/// [`Self::placed_art`] did not keep, and evaluations of live objects and effect art that their
|
||||
/// caches did not keep.
|
||||
/// [`Self::placed_art`] did not keep, evaluations of live objects and effect art that their
|
||||
/// caches did not keep, and brush art that the brush cache did not keep.
|
||||
made_again: bool,
|
||||
/// The node `draw_shape_fx` may cache the live-effect geometry of (the one `draw_arc` is drawing).
|
||||
/// In Outline view its path comes from `geom` too ([`Self::outline_path`]), and
|
||||
@@ -499,8 +515,8 @@ pub struct Renderer {
|
||||
/// Trace object that it draws.
|
||||
fx_owner: Option<Arc<Node>>,
|
||||
/// The live object [`Self::draw_kept_node`] is drawing (kept symbol art, an opacity mask's art,
|
||||
/// a member of a clip group in Outline view): [`Self::draw_content`] draws its evaluation from
|
||||
/// the live cache.
|
||||
/// a member of a clip group in Outline view, kept brush art): [`Self::draw_content`] draws its
|
||||
/// evaluation from the live cache.
|
||||
live_root: Option<Arc<Node>>,
|
||||
/// Live-effect geometry per node ([`fx::FxGeom`]), keyed by `Arc` identity like `geom`.
|
||||
fx_geom: PtrMap<usize, fx::FxGeom>,
|
||||
@@ -561,6 +577,10 @@ pub struct Renderer {
|
||||
/// at the start of every frame.
|
||||
offscreen_live: u64,
|
||||
offscreen_budget: u64,
|
||||
/// Objects the symbol instances drawn in this frame held, together ([`vectorcraft_doc::MAX_SYMBOL_NODES`]).
|
||||
symbol_nodes: u64,
|
||||
/// Groups drawn twice (blending with their backdrop) that hold what is being drawn.
|
||||
twice_drawn: u32,
|
||||
/// What clipping paths paint, per clipping path (see [`Self::clip_paint_of`]).
|
||||
clip_paints: FrameCache<usize, ClipPaintEntry>,
|
||||
/// Gradients along or across strokes (see [`Self::fill_path_gradient`]), keyed by
|
||||
@@ -671,6 +691,7 @@ impl Renderer {
|
||||
symbols: vec![],
|
||||
plugin_revision: 0,
|
||||
strokes: PtrMap::default(),
|
||||
char_strokes: FrameCache::new(lru::CHAR_STROKE_BUDGET, 0),
|
||||
cur: None,
|
||||
made_again: false,
|
||||
fx_owner: None,
|
||||
@@ -699,6 +720,8 @@ impl Renderer {
|
||||
picture: None,
|
||||
offscreen_live: 0,
|
||||
offscreen_budget: 0,
|
||||
symbol_nodes: 0,
|
||||
twice_drawn: 0,
|
||||
clip_paints: FrameCache::new(lru::CLIP_BUDGET, 256),
|
||||
stroke_slices: PtrMap::default(),
|
||||
adjusts: HashMap::new(),
|
||||
@@ -789,6 +812,8 @@ impl Renderer {
|
||||
self.inline_depth = 0;
|
||||
// Nothing is drawn offscreen yet (even if an earlier frame stopped part way).
|
||||
(self.offscreen_live, self.offscreen_budget) = (0, 0);
|
||||
self.symbol_nodes = 0;
|
||||
self.twice_drawn = 0;
|
||||
}
|
||||
|
||||
/// End a frame: drop cache entries not used for a few frames (every render, thumbnails too,
|
||||
@@ -814,6 +839,7 @@ impl Renderer {
|
||||
self.pixel_fx.retain(|_, e| e.stamp == g);
|
||||
self.type_edges.sweep(g);
|
||||
self.texts.sweep(g);
|
||||
self.char_strokes.sweep(g);
|
||||
self.clips.sweep(g);
|
||||
self.clip_paints.sweep(g);
|
||||
self.fx_arts.sweep(g);
|
||||
@@ -1199,11 +1225,11 @@ impl Renderer {
|
||||
&& !fx::has_fx(a)
|
||||
{
|
||||
let t = &*f.doc.inline_resolved(t);
|
||||
let g = match f.text_snap(t) {
|
||||
Some(xf) => Arc::new(text_geom_snapped(t, Some(xf))),
|
||||
let (g, kept) = match f.text_snap(t) {
|
||||
Some(xf) => (Arc::new(text_geom_snapped(t, Some(xf))), false),
|
||||
None => self.text_geom_of(a, t),
|
||||
};
|
||||
self.draw_text_geom(ctx, f, a, t, &g);
|
||||
self.draw_text_geom(ctx, f, a, t, &g, kept);
|
||||
self.stats.drawn += 1;
|
||||
return;
|
||||
}
|
||||
@@ -1332,8 +1358,8 @@ impl Renderer {
|
||||
/// What `n` draws inside its transparency group (`knockout`: its children knock each other out).
|
||||
fn draw_content(&mut self, ctx: &mut RenderContext, f: &Frame, n: &Node, knockout: bool) {
|
||||
match &n.kind {
|
||||
NodeKind::Group { children, clip: false } if f.opts.trace_views && !f.opts.outline && n.trace_view() != TraceView::Result => {
|
||||
self.draw_trace_view(ctx, f, children, n.trace_view(), knockout)
|
||||
NodeKind::Group { children, clip: false } if f.opts.trace_views && !f.opts.outline && Self::trace_view(f, n) != TraceView::Result => {
|
||||
self.draw_trace_view(ctx, f, children, Self::trace_view(f, n), knockout)
|
||||
}
|
||||
NodeKind::Layer { children, clip: false, .. } | NodeKind::Group { children, clip: false } => {
|
||||
self.draw_children(ctx, f, children, knockout)
|
||||
@@ -1379,9 +1405,13 @@ impl Renderer {
|
||||
let bp = self.outline_path(f, n).unwrap_or_else(|| Arc::new(path.to_bezpath()));
|
||||
if *guide {
|
||||
let ([r, g, b], dots) = f.opts.guide;
|
||||
if dots {
|
||||
let mut screen = BezPath::clone(&bp);
|
||||
screen.apply_affine(f.view);
|
||||
let mut screen = BezPath::clone(&bp);
|
||||
screen.apply_affine(f.view);
|
||||
// The rasterizer makes every dash of the whole path before clipping: a guide
|
||||
// running far off screen (from a file) asked for millions of them. Past
|
||||
// [`MAX_GUIDE_DASHES`] (by its control polygon, which is at least as long) it
|
||||
// is drawn solid.
|
||||
if dots && polygon_length(&screen) / 4.0 <= MAX_GUIDE_DASHES {
|
||||
ctx.set_transform(Affine::IDENTITY);
|
||||
ctx.set_stroke(kurbo::Stroke::new(1.5).with_dashes(0.0, [1.5, 2.5]));
|
||||
ctx.set_paint(f.ink.fixed([r, g, b, 255]));
|
||||
@@ -1408,7 +1438,9 @@ impl Renderer {
|
||||
NodeKind::Text(t) => self.draw_text(ctx, f, n, t),
|
||||
NodeKind::Image(im) => self.draw_image(ctx, f, im),
|
||||
NodeKind::SymbolInstance { symbol, xf } => {
|
||||
if let Some(sym) = f.doc.symbols.iter().find(|s| &s.name == symbol) {
|
||||
if let Some(sym) = f.doc.symbols.iter().find(|s| &s.name == symbol)
|
||||
&& self.charge_symbol(&sym.art)
|
||||
{
|
||||
let (art, kept) = self.placed_art(&sym.art, *xf, false, Some(n));
|
||||
self.draw_placed_art(ctx, f, &art, kept);
|
||||
}
|
||||
@@ -1425,6 +1457,13 @@ impl Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
/// Count symbol art `art`'s objects against the frame's [`vectorcraft_doc::MAX_SYMBOL_NODES`]: `false` (the
|
||||
/// instance isn't drawn) once they would pass it.
|
||||
fn charge_symbol(&mut self, art: &Node) -> bool {
|
||||
let total = self.symbol_nodes.saturating_add(art.count() as u64);
|
||||
(total <= vectorcraft_doc::MAX_SYMBOL_NODES).then(|| self.symbol_nodes = total).is_some()
|
||||
}
|
||||
|
||||
/// Draw symbol art `art` as [`Self::placed_art`] placed it for an instance or an inline graphic
|
||||
/// (`kept`: kept between frames, see [`Self::draw_kept_node`]).
|
||||
fn draw_placed_art(&mut self, ctx: &mut RenderContext, f: &Frame, art: &Arc<Node>, kept: bool) {
|
||||
@@ -1447,6 +1486,15 @@ impl Renderer {
|
||||
self.live_root = outer;
|
||||
}
|
||||
|
||||
/// The View `n` draws with on screen: Source Image when it is an Image Trace object listed in
|
||||
/// [`RenderOptions::trace_source`], else its own.
|
||||
fn trace_view(f: &Frame, n: &Node) -> TraceView {
|
||||
match &f.opts.trace_source {
|
||||
Some(ids) if n.extras().trace.is_some() && ids.contains(&n.id) => TraceView::Source,
|
||||
_ => n.trace_view(),
|
||||
}
|
||||
}
|
||||
|
||||
/// An Image Trace object's `children` (the hidden source image, then the traced shapes) as
|
||||
/// `view` shows them on screen.
|
||||
fn draw_trace_view(&mut self, ctx: &mut RenderContext, f: &Frame, children: &[Arc<Node>], view: TraceView, knockout: bool) {
|
||||
@@ -1613,7 +1661,7 @@ impl Renderer {
|
||||
if st.brush.is_some() && self.draw_brush(ctx, f, n, bp, st) {
|
||||
continue;
|
||||
}
|
||||
self.draw_stroke(ctx, f, Affine::IDENTITY, bp, rule, st, bounds);
|
||||
self.draw_stroke(ctx, f, Affine::IDENTITY, bp, rule, st, None, bounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1630,8 +1678,20 @@ impl Renderer {
|
||||
|
||||
/// Paint stroke `st` of the shape `bp` (in the space `xf` maps to the document; `bounds`: its
|
||||
/// geometric bounds there) with its alignment, dashes, profile, arrowheads, opacity and blend.
|
||||
/// `chars` is the glyph geometry kept in `texts` and the run that `st` is the character stroke
|
||||
/// of, when it is one.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn draw_stroke(&mut self, ctx: &mut RenderContext, f: &Frame, xf: Affine, bp: &BezPath, rule: FillRule, st: &StrokeLayer, bounds: Rect) {
|
||||
fn draw_stroke(
|
||||
&mut self,
|
||||
ctx: &mut RenderContext,
|
||||
f: &Frame,
|
||||
xf: Affine,
|
||||
bp: &BezPath,
|
||||
rule: FillRule,
|
||||
st: &StrokeLayer,
|
||||
chars: Option<(&Arc<TextGeom>, usize)>,
|
||||
bounds: Rect,
|
||||
) {
|
||||
let pieces = effects::stroke::stroke_pieces(bp, st);
|
||||
// The line and its heads overlap: they take the opacity once, in one layer, instead of
|
||||
// each folding it into its paint.
|
||||
@@ -1654,11 +1714,11 @@ impl Renderer {
|
||||
// One paint box for the line and the heads, so a gradient runs on into the heads.
|
||||
let paint_bounds = bounds.inflate(st.width / 2.0, st.width / 2.0);
|
||||
if let Some(g) = st.path_gradient() {
|
||||
self.fill_path_gradient(ctx, f, bp, rule, st, &pieces, width, &g.gradient);
|
||||
self.fill_path_gradient(ctx, f, bp, rule, st, chars, &pieces, width, &g.gradient);
|
||||
} else if paint::set_paint(ctx, &st.paint, paint_bounds, f) {
|
||||
self.fold_alpha(ctx, f.ink, &st.paint);
|
||||
ctx.set_fill_rule(peniko::Fill::NonZero);
|
||||
match self.cached_stroke(f, &pieces.line, st, width) {
|
||||
match self.cached_stroke(f, chars, &pieces.line, st, width) {
|
||||
Some(o) => ctx.fill_path(&o),
|
||||
None => ctx.fill_path(&effects::stroke::line_outline(&pieces.line, st, width, f.px * 0.25)),
|
||||
}
|
||||
@@ -1697,6 +1757,7 @@ impl Renderer {
|
||||
bp: &BezPath,
|
||||
rule: FillRule,
|
||||
st: &StrokeLayer,
|
||||
chars: Option<(&Arc<TextGeom>, usize)>,
|
||||
pieces: &effects::stroke::StrokePieces,
|
||||
width: f64,
|
||||
g: &vectorcraft_color::Gradient,
|
||||
@@ -1718,7 +1779,7 @@ impl Renderer {
|
||||
};
|
||||
let slices = match self.cur.clone().filter(|n| owns_stroke(n, st)) {
|
||||
Some(node) => {
|
||||
let key = (self.stroke_owner(&node), st as *const StrokeLayer as usize, level);
|
||||
let key = (self.stroke_owner(Arc::as_ptr(&node) as usize), st as *const StrokeLayer as usize, level);
|
||||
match self.stroke_slices.get_mut(&key) {
|
||||
Some(e) if Arc::ptr_eq(&e.node, &node) => {
|
||||
e.stamp = self.stamp;
|
||||
@@ -1733,7 +1794,7 @@ impl Renderer {
|
||||
}
|
||||
None => make(),
|
||||
};
|
||||
let line = match self.cached_stroke(f, &pieces.line, st, width) {
|
||||
let line = match self.cached_stroke(f, chars, &pieces.line, st, width) {
|
||||
Some(o) => o,
|
||||
None => Arc::new(effects::stroke::line_outline(&pieces.line, st, width, f.px * 0.25)),
|
||||
};
|
||||
@@ -1755,30 +1816,51 @@ impl Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
/// The line part of a stroke of the fast-path node `self.cur` (see
|
||||
/// [`effects::stroke::line_outline`]), cached across frames under [`Self::stroke_owner`] and
|
||||
/// the stroke layer. The tolerance (vello's 0.25 device px) is bucketed to powers of two, never
|
||||
/// coarser than needed, so zooming reuses outlines until the level changes. Only the node's own
|
||||
/// strokes are cached: for the strokes of the brush art drawn for it, this returns `None`.
|
||||
fn cached_stroke(&mut self, f: &Frame, line: &BezPath, st: &StrokeLayer, width: f64) -> Option<Arc<BezPath>> {
|
||||
let node = self.cur.clone().filter(|n| owns_stroke(n, st))?;
|
||||
/// The line part of a stroke (see [`effects::stroke::line_outline`]), cached across frames: a
|
||||
/// character stroke of run `chars.1` of kept glyph geometry `chars.0` in `char_strokes`, a
|
||||
/// stroke of `self.cur` in `strokes` (under [`Self::stroke_owner`] and the stroke layer). The
|
||||
/// tolerance (vello's 0.25 device px) is bucketed to powers of two, never coarser than needed,
|
||||
/// so zooming reuses outlines until the level changes. Other strokes aren't cached: for them
|
||||
/// this returns `None`.
|
||||
fn cached_stroke(
|
||||
&mut self,
|
||||
f: &Frame,
|
||||
chars: Option<(&Arc<TextGeom>, usize)>,
|
||||
line: &BezPath,
|
||||
st: &StrokeLayer,
|
||||
width: f64,
|
||||
) -> Option<Arc<BezPath>> {
|
||||
let level = (f.px * 0.25).log2().floor() as i32;
|
||||
let key = (self.stroke_owner(&node), st as *const StrokeLayer as usize, width.to_bits(), level);
|
||||
let expand = || Arc::new(effects::stroke::line_outline(line, st, width, 2f64.powi(level)));
|
||||
if let Some((g, run)) = chars {
|
||||
let key = (self.stroke_owner(Arc::as_ptr(g) as usize), run, width.to_bits(), level);
|
||||
if let Some((kept, outline)) = self.char_strokes.get(&key, self.stamp)
|
||||
&& Arc::ptr_eq(kept, g)
|
||||
{
|
||||
return Some(outline.clone());
|
||||
}
|
||||
let outline = expand();
|
||||
self.char_strokes.insert(key, (g.clone(), outline.clone()), lru::path_bytes(&outline), self.stamp);
|
||||
return Some(outline);
|
||||
}
|
||||
let node = self.cur.clone().filter(|n| owns_stroke(n, st))?;
|
||||
let key = (self.stroke_owner(Arc::as_ptr(&node) as usize), st as *const StrokeLayer as usize, width.to_bits(), level);
|
||||
if let Some(e) = self.strokes.get_mut(&key)
|
||||
&& Arc::ptr_eq(&e.node, &node)
|
||||
{
|
||||
e.stamp = self.stamp;
|
||||
return Some(e.outline.clone());
|
||||
}
|
||||
let outline = Arc::new(effects::stroke::line_outline(line, st, width, 2f64.powi(level)));
|
||||
let outline = expand();
|
||||
self.strokes.insert(key, StrokeEntry { node, outline: outline.clone(), stamp: self.stamp });
|
||||
Some(outline)
|
||||
}
|
||||
|
||||
/// What the `strokes` and `stroke_slices` keys hold for the fast-path node `node`: its address,
|
||||
/// or 0 while art made again in every frame is drawn ([`Self::made_again`]).
|
||||
fn stroke_owner(&self, node: &Arc<Node>) -> usize {
|
||||
if self.made_again { 0 } else { Arc::as_ptr(node) as usize }
|
||||
/// What the `strokes`, `char_strokes` and `stroke_slices` keys hold for a stroke owner at
|
||||
/// `address` (`self.cur` or kept glyph geometry): the address, or 0 while art made again in
|
||||
/// every frame is drawn ([`Self::made_again`]).
|
||||
fn stroke_owner(&self, address: usize) -> usize {
|
||||
if self.made_again { 0 } else { address }
|
||||
}
|
||||
|
||||
fn draw_text(&mut self, ctx: &mut RenderContext, f: &Frame, n: &Node, t: &TextObject) {
|
||||
@@ -1787,11 +1869,11 @@ impl Renderer {
|
||||
// keeps, see `draw_fx_art`) takes its glyph geometry from `texts`, as on the fast path,
|
||||
// except in frames that snap type to pixels.
|
||||
let owner = self.fx_owner.as_ref().filter(|o| std::ptr::eq(&***o, n)).cloned();
|
||||
let g = match (f.text_snap(t), owner) {
|
||||
let (g, kept) = match (f.text_snap(t), owner) {
|
||||
(None, Some(a)) => self.text_geom_of(&a, t),
|
||||
(snap, _) => Arc::new(text_geom_snapped(t, snap)),
|
||||
(snap, _) => (Arc::new(text_geom_snapped(t, snap)), false),
|
||||
};
|
||||
self.draw_text_geom(ctx, f, n, t, &g);
|
||||
self.draw_text_geom(ctx, f, n, t, &g, kept);
|
||||
}
|
||||
|
||||
/// Draw the inline graphics of type `t` (laid out in `g`): each symbol's art through the
|
||||
@@ -1858,28 +1940,32 @@ impl Renderer {
|
||||
|
||||
/// Cached glyph geometry for a text node (keyed by Arc identity like paths).
|
||||
/// Text `t` that is not the node's own, such as the copy whose inline graphics
|
||||
/// `Document::inline_resolved` sized again, is laid out without the cache.
|
||||
fn text_geom_of(&mut self, a: &Arc<Node>, t: &TextObject) -> Arc<TextGeom> {
|
||||
/// `Document::inline_resolved` sized again, is laid out without the cache. Also returns
|
||||
/// whether the geometry is kept in the cache.
|
||||
fn text_geom_of(&mut self, a: &Arc<Node>, t: &TextObject) -> (Arc<TextGeom>, bool) {
|
||||
if !matches!(&a.kind, NodeKind::Text(own) if std::ptr::eq(&**own, t)) {
|
||||
return Arc::new(text_geom(t));
|
||||
return (Arc::new(text_geom(t)), false);
|
||||
}
|
||||
let fonts = vectorcraft_text::FontDb::global().generation();
|
||||
if fonts != self.text_fonts {
|
||||
self.texts.clear();
|
||||
self.char_strokes.clear();
|
||||
self.text_fonts = fonts;
|
||||
}
|
||||
let key = Arc::as_ptr(a) as usize;
|
||||
if let Some((node, g)) = self.texts.get(&key, self.stamp)
|
||||
&& Arc::ptr_eq(node, a)
|
||||
{
|
||||
return g.clone();
|
||||
return (g.clone(), true);
|
||||
}
|
||||
let g = Arc::new(text_geom(t));
|
||||
self.texts.insert(key, (a.clone(), g.clone()), g.bytes(), self.stamp);
|
||||
g
|
||||
let kept = self.texts.insert(key, (a.clone(), g.clone()), g.bytes(), self.stamp);
|
||||
(g, kept)
|
||||
}
|
||||
|
||||
fn draw_text_geom(&mut self, ctx: &mut RenderContext, f: &Frame, n: &Node, t: &TextObject, g: &TextGeom) {
|
||||
/// Draw type `n` (`t`, laid out in `g`). The outlines of its character strokes are cached
|
||||
/// when `g` is kept in `texts` (`kept`).
|
||||
fn draw_text_geom(&mut self, ctx: &mut RenderContext, f: &Frame, n: &Node, t: &TextObject, g: &Arc<TextGeom>, kept: bool) {
|
||||
let xf = f.view * t.xf;
|
||||
if f.opts.outline {
|
||||
let mut p = g.all.clone();
|
||||
@@ -1965,7 +2051,8 @@ impl Renderer {
|
||||
if run.style.has_stroke() {
|
||||
// Character strokes are drawn in text space, with their cap, join and dashes.
|
||||
overprint(ctx, run.style.overprint_stroke);
|
||||
self.draw_stroke(ctx, f, t.xf, path, FillRule::NonZero, &run.style.stroke_layer(), g.bounds);
|
||||
let chars = kept.then_some((g, i));
|
||||
self.draw_stroke(ctx, f, t.xf, path, FillRule::NonZero, &run.style.stroke_layer(), chars, g.bounds);
|
||||
}
|
||||
}
|
||||
overprint(ctx, false);
|
||||
@@ -2170,7 +2257,7 @@ impl Renderer {
|
||||
}
|
||||
AppearanceItem::Stroke(st) if st.width > 0.0 => {
|
||||
if st.brush.is_none() || !self.draw_brush(ctx, f, n, all, st) {
|
||||
self.draw_stroke(ctx, f, Affine::IDENTITY, all, FillRule::NonZero, st, tb);
|
||||
self.draw_stroke(ctx, f, Affine::IDENTITY, all, FillRule::NonZero, st, None, tb);
|
||||
}
|
||||
}
|
||||
AppearanceItem::Stroke(_) => {}
|
||||
@@ -2647,6 +2734,33 @@ fn stain_bits(stain: Option<(vectorcraft_color::Color, f32)>) -> [u32; 6] {
|
||||
/// Preferred rasterizer thread count set by the app (Preferences → Performance); negative = automatic.
|
||||
static THREADS_OVERRIDE: std::sync::atomic::AtomicI32 = std::sync::atomic::AtomicI32::new(-1);
|
||||
|
||||
/// Most dashes a dotted guide is drawn with (1.5 on, 2.5 off on screen); a longer one is solid.
|
||||
const MAX_GUIDE_DASHES: f64 = 100_000.0;
|
||||
|
||||
/// The length of `p`'s control polygon: at least its own length (infinite when a point is).
|
||||
fn polygon_length(p: &BezPath) -> f64 {
|
||||
let (mut last, mut len): (Option<kurbo::Point>, f64) = (None, 0.0);
|
||||
for el in p.elements() {
|
||||
let points = match *el {
|
||||
kurbo::PathEl::MoveTo(q) => {
|
||||
last = Some(q);
|
||||
continue;
|
||||
}
|
||||
kurbo::PathEl::LineTo(q) => [Some(q), None, None],
|
||||
kurbo::PathEl::QuadTo(a, b) => [Some(a), Some(b), None],
|
||||
kurbo::PathEl::CurveTo(a, b, c) => [Some(a), Some(b), Some(c)],
|
||||
kurbo::PathEl::ClosePath => continue,
|
||||
};
|
||||
for q in points.into_iter().flatten() {
|
||||
if let Some(l) = last {
|
||||
len += l.distance(q);
|
||||
}
|
||||
last = Some(q);
|
||||
}
|
||||
}
|
||||
if len.is_nan() { f64::INFINITY } else { len }
|
||||
}
|
||||
|
||||
/// Override the worker-thread count used by renderers created from now on (`None` = automatic).
|
||||
pub fn set_default_threads(n: Option<u16>) {
|
||||
THREADS_OVERRIDE.store(n.map_or(-1, i32::from), std::sync::atomic::Ordering::Relaxed);
|
||||
|
||||
+86
-19
@@ -6,7 +6,11 @@
|
||||
//! the symbols, patterns and placed files it shows, the fonts for type, the plug-ins for plug-in
|
||||
//! effects, and the color settings (so the steps keep
|
||||
//! stable `Arc`s and hit the geometry cache frame after frame, and editing a symbol redraws an
|
||||
//! envelope around an instance of it). Gradient meshes are tessellated into many small solid-colour quads (vello
|
||||
//! envelope around an instance of it). What the walk behind that key found is kept with the node
|
||||
//! and with the document's symbols and patterns as the walk read them ([`Walk`]). A later frame
|
||||
//! makes the key from what was kept while the node and the document's symbols and patterns stay
|
||||
//! the same. A walk that found a placed file is not kept.
|
||||
//! Gradient meshes are tessellated into many small solid-colour quads (vello
|
||||
//! has no mesh shading), with the density chosen from the on-screen patch size; each quad is
|
||||
//! grown by half a device pixel along its edges so neighbours overlap and no antialiasing seams
|
||||
//! show. The quads are made again when the color settings change.
|
||||
@@ -33,16 +37,25 @@ type Quads = Arc<Vec<MeshQuad>>;
|
||||
pub(crate) type Found = (u64, Arc<DocInputs>, Vec<Weak<ReadDocument>>);
|
||||
/// A mesh node, its quads, and the [`DocInputs`] whose color settings colored them.
|
||||
type MeshEntry = (Arc<Node>, Quads, Arc<DocInputs>);
|
||||
/// A node, held weakly (the reference keeps its allocation, so no other node gets its address),
|
||||
/// what the walk of [`resources_key`] found in it, and the frame's [`DocInputs`] the walk read
|
||||
/// the symbols and patterns of.
|
||||
type Walk = (Weak<Node>, Walked, Arc<DocInputs>);
|
||||
|
||||
/// Per-renderer cache of evaluated live objects: (live node, its evaluation, [`Found`]), and a
|
||||
/// [`MeshEntry`] per mesh node and subdivision level.
|
||||
/// Per-renderer cache of evaluated live objects: (live node, its evaluation, [`Found`]), a
|
||||
/// [`MeshEntry`] per mesh node and subdivision level, and a [`Walk`] per node whose key
|
||||
/// [`Renderer::live_found`] found without finding a placed file.
|
||||
pub(crate) struct LiveCache {
|
||||
expanded: FrameCache<usize, (Arc<Node>, Expanded, Found)>,
|
||||
meshes: FrameCache<(usize, usize), MeshEntry>,
|
||||
walks: FrameCache<usize, Walk>,
|
||||
/// How many live objects [`Renderer::live_expanded`] evaluated and how many meshes
|
||||
/// [`Renderer::mesh_quads`] tessellated.
|
||||
#[cfg(test)]
|
||||
pub(crate) evaluated: usize,
|
||||
/// How many walks [`Renderer::live_found`] made.
|
||||
#[cfg(test)]
|
||||
pub(crate) walked: usize,
|
||||
}
|
||||
|
||||
impl Default for LiveCache {
|
||||
@@ -50,8 +63,11 @@ impl Default for LiveCache {
|
||||
Self {
|
||||
expanded: FrameCache::new(lru::LIVE_BUDGET, 256),
|
||||
meshes: FrameCache::new(lru::MESH_BUDGET, 256),
|
||||
walks: FrameCache::new(lru::WALK_BUDGET, 256),
|
||||
#[cfg(test)]
|
||||
evaluated: 0,
|
||||
#[cfg(test)]
|
||||
walked: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,6 +77,7 @@ impl LiveCache {
|
||||
pub(crate) fn sweep(&mut self, stamp: u64) {
|
||||
self.expanded.sweep(stamp);
|
||||
self.meshes.sweep(stamp);
|
||||
self.walks.sweep(stamp);
|
||||
}
|
||||
|
||||
/// A cache whose evaluations take at most `budget` bytes.
|
||||
@@ -85,19 +102,41 @@ pub fn expand_live(n: &Node) -> Vec<Node> {
|
||||
/// plug-in revision ([`crate::effects::plugin_revision`]) when it shows an object with a plug-in
|
||||
/// effect, and the color settings (`cms`, their address). Art is hashed by the addresses of its
|
||||
/// `Arc`s, which copies of the document share: a copy of the document has the same key. It also
|
||||
/// returns weak references to the reads found.
|
||||
fn resources_key(doc: &Document, cms: usize, n: &Node) -> (u64, Vec<Weak<ReadDocument>>) {
|
||||
/// returns weak references to the reads found, and what the walk found ([`Walked`]) when it found
|
||||
/// no placed file.
|
||||
fn resources_key(doc: &Document, cms: usize, n: &Node) -> (u64, Vec<Weak<ReadDocument>>, Option<Walked>) {
|
||||
let mut h = DefaultHasher::new();
|
||||
let mut shown = Shown::default();
|
||||
hash_resources(doc, n, &mut shown, &mut h);
|
||||
if shown.text {
|
||||
vectorcraft_text::FontDb::global().generation().hash(&mut h);
|
||||
let walked = Walked { hash: h.finish(), text: shown.text, plugins: shown.plugins };
|
||||
(walked.key(cms), shown.reads, (!shown.placed).then_some(walked))
|
||||
}
|
||||
|
||||
/// What [`hash_resources`] found in a node: the hash of what it walked, whether it found type or
|
||||
/// a placed file, and whether it found an object with a visible plug-in effect.
|
||||
#[derive(Clone, Copy)]
|
||||
struct Walked {
|
||||
hash: u64,
|
||||
text: bool,
|
||||
plugins: bool,
|
||||
}
|
||||
|
||||
impl Walked {
|
||||
/// The [`resources_key`] of the node walked: the walk's hash, the font generation when it found
|
||||
/// type or a placed file, the plug-in revision when it found a plug-in effect, and the color
|
||||
/// settings `cms`.
|
||||
fn key(self, cms: usize) -> u64 {
|
||||
let mut h = DefaultHasher::new();
|
||||
self.hash.hash(&mut h);
|
||||
if self.text {
|
||||
vectorcraft_text::FontDb::global().generation().hash(&mut h);
|
||||
}
|
||||
if self.plugins {
|
||||
crate::effects::plugin_revision().hash(&mut h);
|
||||
}
|
||||
cms.hash(&mut h);
|
||||
h.finish()
|
||||
}
|
||||
if shown.plugins {
|
||||
crate::effects::plugin_revision().hash(&mut h);
|
||||
}
|
||||
cms.hash(&mut h);
|
||||
(h.finish(), shown.reads)
|
||||
}
|
||||
|
||||
/// What [`hash_resources`] has found so far.
|
||||
@@ -107,6 +146,8 @@ struct Shown {
|
||||
seen: Vec<usize>,
|
||||
/// Whether type or a placed file was found.
|
||||
text: bool,
|
||||
/// Whether a placed file was found.
|
||||
placed: bool,
|
||||
/// Whether an object with a visible plug-in effect was found.
|
||||
plugins: bool,
|
||||
/// Weak references to the reads of the placed files found.
|
||||
@@ -154,6 +195,7 @@ fn hash_resources<'a>(doc: &'a Document, n: &'a Node, shown: &mut Shown, h: &mut
|
||||
read.as_ref().map(|r| Arc::as_ptr(r) as usize).hash(h);
|
||||
shown.reads.extend(read.as_ref().map(Arc::downgrade));
|
||||
shown.text = true;
|
||||
shown.placed = true;
|
||||
}
|
||||
NodeKind::Text(_) => shown.text = true,
|
||||
_ => {}
|
||||
@@ -392,17 +434,39 @@ fn spread_to_edges(px: &mut [vello_cpu::color::PremulRgba8], filled: Vec<bool>,
|
||||
impl Renderer {
|
||||
/// The [`resources_key`] of `n` in `doc`, with the frame's [`DocInputs`] ([`Found`]): `n` is a
|
||||
/// live node, or an object with effects whose art ([`Renderer::fx_art`]) can be made from
|
||||
/// evaluated live objects, type, symbol art or colors shaded through the color settings.
|
||||
pub(crate) fn live_found(&mut self, doc: &Document, n: &Node) -> Found {
|
||||
/// evaluated live objects, type, symbol art or colors shaded through the color settings. The
|
||||
/// key is made from the [`Walk`] kept for `n` while `doc`'s symbols and patterns are those it
|
||||
/// read; `n` is walked again when they changed, and in every frame when the walk found a
|
||||
/// placed file.
|
||||
pub(crate) fn live_found(&mut self, doc: &Document, n: &Arc<Node>) -> Found {
|
||||
let inputs = self.doc_inputs(doc);
|
||||
let (key, reads) = resources_key(doc, inputs.cms, n);
|
||||
let at = Arc::as_ptr(n) as usize;
|
||||
if let Some((node, walked, read)) = self.live.walks.get(&at, self.stamp)
|
||||
&& std::ptr::eq(node.as_ptr(), Arc::as_ptr(n))
|
||||
&& read.same_art(&inputs)
|
||||
{
|
||||
return (walked.key(inputs.cms), inputs, vec![]);
|
||||
}
|
||||
#[cfg(test)]
|
||||
{
|
||||
self.live.walked += 1;
|
||||
}
|
||||
let (key, reads, walked) = resources_key(doc, inputs.cms, n);
|
||||
if let Some(walked) = walked {
|
||||
// The bytes count the key and the entry, and the node's allocation that the weak
|
||||
// reference keeps.
|
||||
let bytes = size_of::<(usize, Walk, Node)>();
|
||||
self.live.walks.insert(at, (Arc::downgrade(n), walked, inputs.clone()), bytes, self.stamp);
|
||||
}
|
||||
(key, inputs, reads)
|
||||
}
|
||||
|
||||
fn live_expanded(&mut self, doc: &Document, a: &Arc<Node>, cache: bool) -> Expanded {
|
||||
let key = Arc::as_ptr(a) as usize;
|
||||
let resources = self.live_found(doc, a);
|
||||
if cache
|
||||
// An evaluation the cache does not keep is made without the key, so the copy that
|
||||
// `draw_live_node` makes is not walked.
|
||||
let resources = cache.then(|| self.live_found(doc, a));
|
||||
if let Some(resources) = &resources
|
||||
&& let Some(e) = self.live.expanded.get(&key, self.stamp)
|
||||
&& Arc::ptr_eq(&e.0, a)
|
||||
&& e.2.0 == resources.0
|
||||
@@ -417,7 +481,7 @@ impl Renderer {
|
||||
Some(children) => Arc::new(children),
|
||||
None => Arc::new(crate::effects::expand_live(Some(doc), a).into_iter().map(Arc::new).collect()),
|
||||
};
|
||||
if cache {
|
||||
if let Some(resources) = resources {
|
||||
let bytes = size_of::<Expanded>() + v.iter().map(|n| lru::node_bytes(n)).sum::<usize>();
|
||||
self.live.expanded.insert(key, (a.clone(), v.clone(), resources), bytes, self.stamp);
|
||||
}
|
||||
@@ -565,7 +629,10 @@ impl Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw a live node reached without its `Arc` (thumbnails, clip fallbacks): uncached.
|
||||
/// Draw a live node that [`Self::draw_content`] reached without its kept `Arc`
|
||||
/// ([`Self::live_root`]): the node of a thumbnail ([`Self::render_node_thumbnail_with`]), symbol
|
||||
/// art placed again in every frame, color glyph art, and brush art that the brush cache did not
|
||||
/// keep. It evaluates a copy of the node and does not use the live cache.
|
||||
pub(crate) fn draw_live_node(&mut self, ctx: &mut RenderContext, f: &Frame, n: &Node) {
|
||||
let a = Arc::new(n.clone());
|
||||
self.draw_live_body(ctx, f, &a, false);
|
||||
|
||||
@@ -25,6 +25,9 @@ use crate::PtrHasher;
|
||||
|
||||
/// Glyph outlines per text object (`Renderer::text_geom_of`).
|
||||
pub(crate) const TEXT_BUDGET: usize = 128 << 20;
|
||||
/// Expanded character strokes per run of the glyph outlines kept in `texts`
|
||||
/// (`Renderer::cached_stroke`).
|
||||
pub(crate) const CHAR_STROKE_BUDGET: usize = 128 << 20;
|
||||
/// Clip regions per clipping path (`Renderer::clip_of`), and separately what clipping paths
|
||||
/// paint (`Renderer::clip_paint_of`).
|
||||
pub(crate) const CLIP_BUDGET: usize = 32 << 20;
|
||||
@@ -36,6 +39,8 @@ pub(crate) const PLACED_ART_BUDGET: usize = 64 << 20;
|
||||
pub(crate) const BRUSH_BUDGET: usize = 64 << 20;
|
||||
/// Evaluated blends, envelopes and repeats (`Renderer::live_expanded`).
|
||||
pub(crate) const LIVE_BUDGET: usize = 64 << 20;
|
||||
/// What the walks of live objects and effect art found (`Renderer::live_found`).
|
||||
pub(crate) const WALK_BUDGET: usize = 16 << 20;
|
||||
/// Tessellated gradient meshes (`Renderer::mesh_quads`).
|
||||
pub(crate) const MESH_BUDGET: usize = 32 << 20;
|
||||
/// Pattern tile rasters, per thread and ink plane (`pattern::set_pattern_paint`): a tile is at
|
||||
@@ -176,6 +181,12 @@ impl<K: Hash + Eq + Clone, V, S: BuildHasher + Default> FrameCache<K, V, S> {
|
||||
self.map.len()
|
||||
}
|
||||
|
||||
/// The values of the entries frame `stamp` made or used.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn used_in(&self, stamp: u64) -> impl Iterator<Item = &V> {
|
||||
self.map.values().filter(move |s| s.stamp == stamp).map(|s| &s.value)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
self.map.is_empty()
|
||||
|
||||
@@ -102,7 +102,11 @@ pub(crate) fn decode_within_allowance(bytes: &[u8]) -> image::ImageResult<image:
|
||||
Ok(r)
|
||||
};
|
||||
let (w, h) = reader()?.into_dimensions()?;
|
||||
if u64::from(w) * u64::from(h) > MAX_DECODE_ALLOC / 4 {
|
||||
let bytes = (u64::from(w) * u64::from(h)).saturating_mul(4);
|
||||
// The images paints hold can't be evicted from the cache, so a document of many images held
|
||||
// them all at once: a new one is decoded only while those and it fit twice the allowance.
|
||||
let pinned = crate::images::store().pinned_bytes() as u64;
|
||||
if bytes > MAX_DECODE_ALLOC || bytes.saturating_add(pinned) > 2 * MAX_DECODE_ALLOC {
|
||||
return Err(image::ImageError::Limits(image::error::LimitError::from_kind(image::error::LimitErrorKind::InsufficientMemory)));
|
||||
}
|
||||
reader()?.decode()
|
||||
|
||||
@@ -579,6 +579,57 @@ fn outline_view_draws_paths_from_kept_geometry() {
|
||||
}
|
||||
}
|
||||
|
||||
/// An Image Trace object listed in `trace_source` draws its source image on screen whatever its
|
||||
/// View, also inside a group whose raster effect a renderer keeps; without the list, and in
|
||||
/// exports, it draws its result. A group that is not an Image Trace object draws its members.
|
||||
#[test]
|
||||
fn trace_source_draws_the_source_image_of_the_listed_objects() {
|
||||
use vectorcraft_doc::{ImageBlob, ImageObject};
|
||||
let img = image::RgbaImage::from_pixel(1, 1, image::Rgba([255, 0, 0, 255]));
|
||||
let mut png = vec![];
|
||||
img.write_to(&mut std::io::Cursor::new(&mut png), image::ImageFormat::Png).unwrap();
|
||||
let mut d = Document::new(100.0, 100.0);
|
||||
d.images.insert("red".into(), ImageBlob::new("image/png", png));
|
||||
// A group at `x`: the hidden red source image, then a blue traced square over it.
|
||||
let group = |d: &mut Document, x: f64, traced: bool| {
|
||||
let xf = Affine::translate((x, 10.0)) * Affine::scale(20.0);
|
||||
let im = ImageObject { key: "red".into(), width: 1, height: 1, xf, link: None, placement: Default::default(), pixels: None };
|
||||
let mut source = Node::new(d.alloc_id(), NodeKind::Image(Box::new(im)));
|
||||
source.visible = false;
|
||||
let shape = rect_node(d, Rect::new(x, 10.0, x + 20.0, 30.0), Paint::solid(Color::rgb(0.0, 0.0, 1.0)), Paint::None, 0.0);
|
||||
let mut g = Node::group(d.alloc_id(), vec![Arc::new(source), Arc::new(shape)]);
|
||||
if traced {
|
||||
g.extras_mut().trace = Some(Box::new(serde_json::json!({ "view": "tracingResult" })));
|
||||
}
|
||||
g
|
||||
};
|
||||
let plain = group(&mut d, 10.0, true);
|
||||
let blurred = group(&mut d, 40.0, true);
|
||||
let other = group(&mut d, 70.0, false);
|
||||
let ids = Arc::new(vec![plain.id, blurred.id, other.id]);
|
||||
let mut holder = Node::group(d.alloc_id(), vec![Arc::new(blurred)]);
|
||||
holder.appearance.effects.push(vectorcraft_doc::Effect { id: "blur.gaussian".into(), params: serde_json::json!({ "radius": 1 }), visible: true });
|
||||
let l = d.layers[0].id;
|
||||
for n in [plain, holder, other] {
|
||||
d.insert(Some(l), usize::MAX, n).unwrap();
|
||||
}
|
||||
let screen = RenderOptions { trace_views: true, background: Some([255; 4]), ..Default::default() };
|
||||
let held = RenderOptions { trace_source: Some(ids.clone()), ..screen.clone() };
|
||||
let export = RenderOptions { trace_source: Some(ids), background: Some([255; 4]), ..Default::default() };
|
||||
let red = |p: [u8; 4]| p[0] > 200 && p[2] < 60;
|
||||
let blue = |p: [u8; 4]| p[2] > 200 && p[0] < 60;
|
||||
let mut kept = Renderer::new();
|
||||
for (opts, source) in [(&screen, false), (&held, true), (&screen, false), (&export, false)] {
|
||||
for r in [kept.render(&d, 100, 100, Affine::IDENTITY, opts), Renderer::new().render(&d, 100, 100, Affine::IDENTITY, opts)] {
|
||||
for (x, what) in [(20, "the Image Trace object"), (50, "the one in the blurred group")] {
|
||||
let p = r.pixel(x, 20);
|
||||
assert!(if source { red(p) } else { blue(p) }, "{what} with trace_source {source}: {p:?}");
|
||||
}
|
||||
assert!(blue(r.pixel(80, 20)), "the plain group draws its square: {:?}", r.pixel(80, 20));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn artboards_white_on_pasteboard() {
|
||||
let d = Document::new(50.0, 50.0);
|
||||
|
||||
@@ -80,6 +80,8 @@ fn glyphs(t: &vectorcraft_doc::text::TextObject) -> Vec<(usize, usize, u32)> {
|
||||
/// required shaping, not alternates, so ordinary Arabic text shows no pink.
|
||||
#[test]
|
||||
fn arabic_joining_forms_are_not_alternates() {
|
||||
// Looking up an installed font loads it, which changes the fonts.
|
||||
let _adding = crate::tests_fontchange::adding_fonts();
|
||||
let Some(style) = arabic_style("arabic_joining_forms_are_not_alternates") else { return };
|
||||
let t = text("خلطة مبتكرة من اللومي الحساوي", style);
|
||||
// The words are shaped: most glyphs are not their letter's cmap glyph.
|
||||
@@ -90,6 +92,8 @@ fn arabic_joining_forms_are_not_alternates() {
|
||||
/// #394: the lam-alef ligature is required (`rlig`), so it isn't highlighted either.
|
||||
#[test]
|
||||
fn lam_alef_is_not_an_alternate() {
|
||||
// Looking up an installed font loads it, which changes the fonts.
|
||||
let _adding = crate::tests_fontchange::adding_fonts();
|
||||
let Some(style) = arabic_style("lam_alef_is_not_an_alternate") else { return };
|
||||
for s in ["لا", "سلام", "الاسم"] {
|
||||
assert_eq!(alternates(&text(s, style.clone())), 0, "{s}");
|
||||
@@ -100,6 +104,8 @@ fn lam_alef_is_not_an_alternate() {
|
||||
/// discretionary alternate…) is highlighted on the glyphs it changes, and only on those.
|
||||
#[test]
|
||||
fn optional_features_on_arabic_flag_only_the_glyphs_they_change() {
|
||||
// Looking up an installed font loads it, which changes the fonts.
|
||||
let _adding = crate::tests_fontchange::adding_fonts();
|
||||
let db = vectorcraft_text::FontDb::global();
|
||||
let s = "خلطة مبتكرة من اللومي الحساوي";
|
||||
// Arabic fonts that may have optional features; the first installed one with a feature that
|
||||
|
||||
@@ -7,6 +7,7 @@ use vectorcraft_doc::{AppearanceItem, Dash, LineJoin, Node, NodeKind};
|
||||
use vectorcraft_geom::Point;
|
||||
|
||||
use super::*;
|
||||
use crate::tests_fontchange::fonts_steady;
|
||||
|
||||
const SIZE: u32 = 200;
|
||||
|
||||
@@ -103,3 +104,86 @@ fn aligned_character_strokes_keep_to_their_side_of_the_glyphs() {
|
||||
assert!(!dark(&outside, mid.0, mid.1), "an outside stroke leaves the glyph itself unpainted");
|
||||
assert!(dark(&inside, mid.0, mid.1), "an inside stroke paints into the glyph");
|
||||
}
|
||||
|
||||
/// A document with 60 pt `text` without a fill and with a 1 pt character stroke, and the type's id.
|
||||
fn stroked_text_doc(text: &str) -> (Document, NodeId) {
|
||||
let mut d = Document::new(SIZE as f64, SIZE as f64);
|
||||
let style = CharStyle { size: 60.0, fill: Paint::None, stroke: Paint::solid(Color::BLACK), stroke_width: 1.0, ..Default::default() };
|
||||
let mut n = Node::new(NodeId(0), NodeKind::Text(Box::new(TextObject::point(Point::new(20.0, 120.0), text, style))));
|
||||
n.id = d.alloc_id();
|
||||
let id = n.id;
|
||||
let l = d.layers[0].id;
|
||||
d.insert(Some(l), 0, n).unwrap();
|
||||
(d, id)
|
||||
}
|
||||
|
||||
/// The character stroke outlines that `r` keeps and that its last frame made or used.
|
||||
fn character_outlines(r: &Renderer) -> Vec<Arc<BezPath>> {
|
||||
r.char_strokes.used_in(r.stamp).map(|(_, outline)| outline.clone()).collect()
|
||||
}
|
||||
|
||||
/// The outlines of type that changes in every frame (an animation) go within a few frames: the
|
||||
/// renderer keeps no more than the last few frames' strokes, however long it runs.
|
||||
#[test]
|
||||
fn the_character_strokes_of_type_that_changes_in_every_frame_go() {
|
||||
let _fonts = fonts_steady();
|
||||
let (mut d, id) = stroked_text_doc("Type");
|
||||
let opts = RenderOptions::default();
|
||||
let mut r = Renderer::new();
|
||||
for i in 0..40 {
|
||||
if let Some(Node { kind: NodeKind::Text(t), .. }) = d.node_mut(id) {
|
||||
t.xf = Affine::translate((f64::from(i), 0.0));
|
||||
}
|
||||
r.render(&d, SIZE, SIZE, Affine::IDENTITY, &opts);
|
||||
}
|
||||
assert!(r.char_strokes.len() <= 4, "{} outlines kept", r.char_strokes.len());
|
||||
}
|
||||
|
||||
/// A character stroke is expanded once: the next frame of the same view draws the outline the
|
||||
/// first made. A change of the zoom level or of the text expands it again.
|
||||
#[test]
|
||||
fn character_stroke_outlines_are_kept_between_frames() {
|
||||
let _fonts = fonts_steady();
|
||||
let (mut d, id) = stroked_text_doc("Type");
|
||||
let opts = RenderOptions::default();
|
||||
let mut r = Renderer::new();
|
||||
r.render(&d, SIZE, SIZE, Affine::IDENTITY, &opts);
|
||||
let first = character_outlines(&r);
|
||||
assert_eq!(first.len(), 1, "the outline of the one run's stroke");
|
||||
r.render(&d, SIZE, SIZE, Affine::IDENTITY, &opts);
|
||||
let again = character_outlines(&r);
|
||||
assert!(again.len() == 1 && Arc::ptr_eq(&again[0], &first[0]), "the second frame draws the outline the first made");
|
||||
r.render(&d, SIZE, SIZE, Affine::translate((-40.0, -300.0)) * Affine::scale(4.0), &opts);
|
||||
let zoomed = character_outlines(&r);
|
||||
assert!(zoomed.len() == 1 && !Arc::ptr_eq(&zoomed[0], &first[0]), "zoomed in 4×, it is expanded again");
|
||||
if let Some(Node { kind: NodeKind::Text(t), .. }) = d.node_mut(id) {
|
||||
t.runs[0].text = "Typo".into();
|
||||
}
|
||||
r.render(&d, SIZE, SIZE, Affine::IDENTITY, &opts);
|
||||
let changed = character_outlines(&r);
|
||||
assert!(changed.len() == 1 && !Arc::ptr_eq(&changed[0], &first[0]), "the changed text is expanded again");
|
||||
}
|
||||
|
||||
/// Frames that draw character strokes from the cache draw the same pixels, and what a renderer
|
||||
/// draws whose glyph cache has no room, so that it expands them in every frame: exactly at 100%,
|
||||
/// where both take a tolerance of 1/4 device pixel, and within antialiasing at 105% and 150%,
|
||||
/// where the cache takes 1/8 device pixel and the frames without it about 1/4 and 1/6.
|
||||
#[test]
|
||||
fn cached_character_strokes_draw_what_uncached_ones_draw() {
|
||||
let _fonts = fonts_steady();
|
||||
let (d, _) = stroked_text_doc("Type");
|
||||
let opts = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() };
|
||||
for (zoom, most) in [(1.0, 0), (1.05, 24), (1.5, 24)] {
|
||||
let view = Affine::scale(zoom);
|
||||
let mut r = Renderer::new();
|
||||
let first = r.render(&d, SIZE, SIZE, view, &opts).pixels;
|
||||
assert!(r.render(&d, SIZE, SIZE, view, &opts).pixels == first, "{zoom}×: the cached frames match");
|
||||
let mut uncached = Renderer::new();
|
||||
uncached.texts = FrameCache::new(0, 0);
|
||||
let plain = uncached.render(&d, SIZE, SIZE, view, &opts).pixels;
|
||||
assert!(character_outlines(&uncached).is_empty());
|
||||
let diff = first.iter().zip(&plain).map(|(a, b)| a.abs_diff(*b)).max().unwrap_or(0);
|
||||
assert!(diff <= most, "{zoom}×: cached and uncached frames differ by {diff}");
|
||||
assert!(plain.iter().any(|&c| c < 128), "{zoom}×: the strokes show");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@ use vectorcraft_geom::Point;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Taken to add fonts. Renderers lay type out again when the fonts change, so tests of what they
|
||||
/// keep between frames hold it shared ([`fonts_steady`]) and the tests here hold it alone.
|
||||
/// Taken to add fonts, or to look up an installed one by name (`FontDb::face` loads it, which
|
||||
/// changes the fonts too). Renderers lay type out again when the fonts change, so tests of what
|
||||
/// they keep between frames hold it shared ([`fonts_steady`]) and the tests that change the fonts
|
||||
/// hold it alone ([`adding_fonts`]).
|
||||
static FONTS: RwLock<()> = RwLock::new(());
|
||||
|
||||
/// No fonts are added by these tests until the guard is dropped.
|
||||
|
||||
@@ -576,12 +576,13 @@ fn art_evaluated_again_in_every_frame_keeps_one_outline_per_stroke() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The instances of a symbol and the copies of a repeat replace each other's brush art, so their
|
||||
/// brush art is made again in every frame. A brushed path gets new brush art each time its brush
|
||||
/// changes. The renderer keeps no outline or gradient slices for the squares' strokes, and each
|
||||
/// frame draws what a new renderer draws.
|
||||
/// The instances of a symbol, the copies of a repeat and a path of the document keep their own
|
||||
/// brush art, and a brushed path gets new brush art each time its brush changes. A frame of the
|
||||
/// unchanged document draws the stroke outlines and gradient slices that the frame before it made
|
||||
/// for the squares' strokes, and each frame draws what a new renderer draws, with or without room
|
||||
/// in the brush cache.
|
||||
#[test]
|
||||
fn strokes_of_brush_art_made_again_draw_as_a_new_renderer_does() {
|
||||
fn strokes_of_brush_art_draw_as_a_new_renderer_does() {
|
||||
let _fonts = fonts_steady();
|
||||
use vectorcraft_brush::{Brush, BrushKind, Scatter};
|
||||
use vectorcraft_doc::{Appearance, StrokeGradientMode};
|
||||
@@ -629,13 +630,216 @@ fn strokes_of_brush_art_made_again_draw_as_a_new_renderer_does() {
|
||||
d.insert(Some(l), usize::MAX, Node::new(id, NodeKind::Repeat(mirror))).unwrap();
|
||||
let opts = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() };
|
||||
let mut r = Renderer::new();
|
||||
let mut full = Renderer::new();
|
||||
full.brushes.entries = FrameCache::new(0, 0);
|
||||
let mut before = (vec![], vec![]);
|
||||
// Six frames of the same document, then a frame after each change of the brush's spacing.
|
||||
for (frame, spacing) in [150.0, 150.0, 150.0, 150.0, 150.0, 150.0, 120.0, 150.0, 90.0, 150.0, 120.0, 135.0].into_iter().enumerate() {
|
||||
squares(&mut d, spacing);
|
||||
let want = Renderer::new().render(&d, 200, 140, Affine::IDENTITY, &opts).pixels;
|
||||
assert!(r.render(&d, 200, 140, Affine::IDENTITY, &opts).pixels == want, "frame {frame}");
|
||||
assert!(full.render(&d, 200, 140, Affine::IDENTITY, &opts).pixels == want, "no room, frame {frame}");
|
||||
if frame == 4 {
|
||||
before = stroke_outlines(&r);
|
||||
assert!(!before.0.is_empty() && !before.1.is_empty(), "the squares' strokes keep outlines and slices");
|
||||
} else if frame == 5 {
|
||||
assert_eq!(used_again(&r, &before), (before.0.len(), before.1.len()), "the sixth frame draws those the fifth used");
|
||||
}
|
||||
}
|
||||
assert_eq!((r.strokes.len(), r.stroke_slices.len()), (0, 0), "no outline or slices kept for the strokes of brush art");
|
||||
}
|
||||
|
||||
/// A line 24 × 12 pt around the origin, stroked 1 pt in black with the 10 pt. Oval brush.
|
||||
fn brushed_line(d: &mut Document) -> Node {
|
||||
let mut ap = vectorcraft_doc::Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0);
|
||||
if let Some(s) = ap.stroke_mut() {
|
||||
s.brush = Some("10 pt. Oval".into());
|
||||
}
|
||||
Node::path(d.alloc_id(), vectorcraft_geom::shapes::line((-12.0, -6.0).into(), (12.0, 6.0).into()), ap)
|
||||
}
|
||||
|
||||
/// Copies of [`brushed_line`] that share an id: three instances of symbol `Line` (the line), two
|
||||
/// of symbol `Held` (a group holding the line), type showing `Line` as two inline graphics, and a
|
||||
/// Grid Repeat of the line (nine copies).
|
||||
fn brushed_copies_doc() -> Document {
|
||||
use vectorcraft_doc::text::{CharStyle, InlineArt, TextObject, TextRun};
|
||||
let mut d = Document::new(200.0, 100.0);
|
||||
let line = brushed_line(&mut d);
|
||||
d.symbols.push(vectorcraft_doc::Symbol { name: "Line".into(), art: Arc::new(line) });
|
||||
let line = brushed_line(&mut d);
|
||||
let held = Node::group(d.alloc_id(), vec![Arc::new(line)]);
|
||||
d.symbols.push(vectorcraft_doc::Symbol { name: "Held".into(), art: Arc::new(held) });
|
||||
let l = d.layers[0].id;
|
||||
for (symbol, at) in [("Line", (20.0, 15.0)), ("Line", (60.0, 15.0)), ("Line", (100.0, 15.0)), ("Held", (20.0, 45.0)), ("Held", (60.0, 45.0))] {
|
||||
let id = d.alloc_id();
|
||||
d.insert(Some(l), usize::MAX, Node::new(id, NodeKind::SymbolInstance { symbol: symbol.into(), xf: Affine::translate(at) })).unwrap();
|
||||
}
|
||||
let style = CharStyle { size: 24.0, ..Default::default() };
|
||||
let mut t = TextObject::point(vectorcraft_geom::Point::new(10.0, 85.0), "A", style.clone());
|
||||
t.runs.push(TextRun::inline(InlineArt::new("Line"), style.clone()));
|
||||
t.runs.push(TextRun::new("B", style.clone()));
|
||||
t.runs.push(TextRun::inline(InlineArt::new("Line"), style));
|
||||
let id = d.alloc_id();
|
||||
d.insert(Some(l), usize::MAX, Node::new(id, NodeKind::Text(Box::new(t)))).unwrap();
|
||||
let mut source = brushed_line(&mut d);
|
||||
source.transform(Affine::translate((140.0, 20.0)), true);
|
||||
let grid = vectorcraft_doc::pattern::RepeatSpec::grid(vec![Arc::new(source)], 4.0, 4.0);
|
||||
let id = d.alloc_id();
|
||||
d.insert(Some(l), usize::MAX, Node::new(id, NodeKind::Repeat(grid))).unwrap();
|
||||
d
|
||||
}
|
||||
|
||||
/// The copies of [`brushed_copies_doc`] keep their own brush art: the second frame makes none,
|
||||
/// and draws what the first drew and what a new renderer draws. With no room in the brush cache,
|
||||
/// every frame makes the brush art of each copy again and draws the same.
|
||||
#[test]
|
||||
fn brushed_copies_keep_their_own_brush_art_between_frames() {
|
||||
let _fonts = fonts_steady();
|
||||
let d = brushed_copies_doc();
|
||||
let opts = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() };
|
||||
let mut r = Renderer::new();
|
||||
let first = r.render(&d, 200, 100, Affine::IDENTITY, &opts).pixels;
|
||||
let made = r.brushes.made;
|
||||
assert_eq!(made, 16, "the first frame makes brush art for each of the 16 copies");
|
||||
let second = r.render(&d, 200, 100, Affine::IDENTITY, &opts).pixels;
|
||||
assert_eq!(r.brushes.made, made, "the second frame makes none");
|
||||
assert!(second == first, "the second frame draws the same");
|
||||
assert!(second == Renderer::new().render(&d, 200, 100, Affine::IDENTITY, &opts).pixels, "a new renderer draws the same");
|
||||
let mut full = Renderer::new();
|
||||
full.brushes.entries = FrameCache::new(0, 0);
|
||||
for n in 1..=2 {
|
||||
assert!(full.render(&d, 200, 100, Affine::IDENTITY, &opts).pixels == first, "no room, frame {n}: the same pixels");
|
||||
assert_eq!(full.brushes.made, 16 * n, "no room, frame {n}: the brush art of each copy is made again");
|
||||
}
|
||||
}
|
||||
|
||||
/// After a frame of [`brushed_copies_doc`], the next frame draws an edit of `Line`'s art (the line
|
||||
/// turns), of the brush (its nib grows to 20 pt) and of the stroke of `Held`'s line (red instead
|
||||
/// of black) as a new renderer draws it.
|
||||
#[test]
|
||||
fn brush_art_of_copies_draws_symbol_brush_and_stroke_edits() {
|
||||
let _fonts = fonts_steady();
|
||||
edit_draws_as_new(brushed_copies_doc(), |d| {
|
||||
let mut line = brushed_line(d);
|
||||
if let NodeKind::Path { path, .. } = &mut line.kind {
|
||||
*path = vectorcraft_geom::shapes::line((-12.0, 6.0).into(), (12.0, -6.0).into());
|
||||
}
|
||||
d.symbols[0].art = Arc::new(line);
|
||||
});
|
||||
edit_draws_as_new(brushed_copies_doc(), |d| {
|
||||
let mut lib = vectorcraft_brush::library(d);
|
||||
if let Some(vectorcraft_brush::BrushKind::Calligraphic(c)) = lib.iter_mut().find(|b| b.name == "10 pt. Oval").map(|b| &mut b.kind) {
|
||||
c.size = 20.0;
|
||||
}
|
||||
vectorcraft_brush::store(d, &lib);
|
||||
});
|
||||
edit_draws_as_new(brushed_copies_doc(), |d| {
|
||||
let mut held = (*d.symbols[1].art).clone();
|
||||
if let Some([line]) = held.children_mut().map(Vec::as_mut_slice)
|
||||
&& let Some(st) = Arc::make_mut(line).appearance.stroke_mut()
|
||||
{
|
||||
st.paint = Paint::solid(Color::rgb(1.0, 0.0, 0.0));
|
||||
}
|
||||
d.symbols[1].art = Arc::new(held);
|
||||
});
|
||||
}
|
||||
|
||||
/// A path stroked with scatter brush `Dots`, whose art is an instance of symbol `Dot` (a blue
|
||||
/// square) and a square painted with pattern `Fill` (a green square). After a frame, the next one
|
||||
/// draws as a new renderer does when the art of `Dot` or `Fill` starts or stops drawing a brushed
|
||||
/// stroke, which decides whether the brush art shows that instance or that pattern.
|
||||
#[test]
|
||||
fn brush_art_draws_edits_of_the_symbols_and_patterns_it_shows() {
|
||||
let _fonts = fonts_steady();
|
||||
use vectorcraft_brush::{Brush, BrushKind, Scatter};
|
||||
use vectorcraft_doc::pattern::{PatternDef, pattern_paint};
|
||||
use vectorcraft_geom::shapes::{line, rectangle};
|
||||
let square = |d: &mut Document, paint: Paint| filled(d, rectangle(Rect::new(-4.0, -4.0, 4.0, 4.0)), paint, vec![]);
|
||||
// A square painted `paint`, with a brushed line beside it when `brushed`.
|
||||
let art = |d: &mut Document, paint: Paint, brushed: bool| {
|
||||
let mut members = vec![Arc::new(square(d, paint))];
|
||||
if brushed {
|
||||
members.push(Arc::new(brushed_line(d)));
|
||||
}
|
||||
Node::group(d.alloc_id(), members)
|
||||
};
|
||||
let doc = |dot_brushed: bool, fill_brushed: bool| {
|
||||
let mut d = Document::new(200.0, 100.0);
|
||||
let dot = art(&mut d, Paint::solid(Color::rgb(0.0, 0.0, 1.0)), dot_brushed);
|
||||
d.symbols.push(vectorcraft_doc::Symbol { name: "Dot".into(), art: Arc::new(dot) });
|
||||
let fill = art(&mut d, Paint::solid(Color::rgb(0.0, 0.6, 0.0)), fill_brushed);
|
||||
let mut def = PatternDef::new("Fill", vec![Arc::new(fill)]);
|
||||
def.tile = Rect::new(-6.0, -6.0, 6.0, 6.0);
|
||||
d.patterns.push(def);
|
||||
let id = d.alloc_id();
|
||||
let instance = Node::new(id, NodeKind::SymbolInstance { symbol: "Dot".into(), xf: Affine::translate((0.0, -8.0)) });
|
||||
let mut painted = square(&mut d, pattern_paint("Fill"));
|
||||
painted.transform(Affine::translate((0.0, 8.0)), true);
|
||||
let scatter = Node::group(d.alloc_id(), vec![Arc::new(instance), Arc::new(painted)]);
|
||||
let mut lib = vectorcraft_brush::library(&d);
|
||||
lib.push(Brush { name: "Dots".into(), kind: BrushKind::Scatter(Scatter { art: scatter, spacing: (150.0, 150.0), ..Default::default() }) });
|
||||
vectorcraft_brush::store(&mut d, &lib);
|
||||
let mut ap = vectorcraft_doc::Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0);
|
||||
if let Some(s) = ap.stroke_mut() {
|
||||
s.brush = Some("Dots".into());
|
||||
}
|
||||
let path = Node::path(d.alloc_id(), line((20.0, 50.0).into(), (180.0, 50.0).into()), ap);
|
||||
let l = d.layers[0].id;
|
||||
d.insert(Some(l), usize::MAX, path).unwrap();
|
||||
d
|
||||
};
|
||||
for brushed in [false, true] {
|
||||
edit_draws_as_new(doc(brushed, false), |d| {
|
||||
let dot = art(d, Paint::solid(Color::rgb(0.0, 0.0, 1.0)), !brushed);
|
||||
d.symbols[0].art = Arc::new(dot);
|
||||
});
|
||||
edit_draws_as_new(doc(false, brushed), |d| {
|
||||
let fill = art(d, Paint::solid(Color::rgb(0.0, 0.6, 0.0)), !brushed);
|
||||
if let Some(def) = d.pattern_mut("Fill") {
|
||||
def.art = vec![Arc::new(fill)];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// A path of the document and an instance of symbol `Wave` (a group holding another path) are
|
||||
/// stroked with scatter brush `Bent`, whose art is an arc envelope around a green band: the second
|
||||
/// frame evaluates none of the envelopes in their brush art again, and draws what the first drew
|
||||
/// and what a new renderer draws.
|
||||
#[test]
|
||||
fn live_objects_in_brush_art_keep_their_evaluations_between_frames() {
|
||||
let _fonts = fonts_steady();
|
||||
use vectorcraft_brush::{Brush, BrushKind, Scatter};
|
||||
use vectorcraft_geom::shapes::{line, rectangle};
|
||||
let mut d = Document::new(200.0, 100.0);
|
||||
let band = filled(&mut d, rectangle(Rect::new(-4.0, -3.0, 4.0, 3.0)), Paint::solid(Color::rgb(0.0, 0.5, 0.0)), vec![]);
|
||||
let art = arc_envelope(&mut d, vec![band], false);
|
||||
let mut lib = vectorcraft_brush::library(&d);
|
||||
lib.push(Brush { name: "Bent".into(), kind: BrushKind::Scatter(Scatter { art, spacing: (150.0, 150.0), ..Default::default() }) });
|
||||
vectorcraft_brush::store(&mut d, &lib);
|
||||
let bent = |d: &mut Document, from: (f64, f64), to: (f64, f64)| {
|
||||
let mut ap = vectorcraft_doc::Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0);
|
||||
if let Some(s) = ap.stroke_mut() {
|
||||
s.brush = Some("Bent".into());
|
||||
}
|
||||
Node::path(d.alloc_id(), line(from.into(), to.into()), ap)
|
||||
};
|
||||
let held = bent(&mut d, (-60.0, 0.0), (60.0, 0.0));
|
||||
let held = Node::group(d.alloc_id(), vec![Arc::new(held)]);
|
||||
d.symbols.push(vectorcraft_doc::Symbol { name: "Wave".into(), art: Arc::new(held) });
|
||||
let path = bent(&mut d, (20.0, 25.0), (180.0, 25.0));
|
||||
let l = d.layers[0].id;
|
||||
d.insert(Some(l), usize::MAX, path).unwrap();
|
||||
let id = d.alloc_id();
|
||||
d.insert(Some(l), usize::MAX, Node::new(id, NodeKind::SymbolInstance { symbol: "Wave".into(), xf: Affine::translate((100.0, 70.0)) })).unwrap();
|
||||
let opts = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() };
|
||||
let mut r = Renderer::new();
|
||||
let first = r.render(&d, 200, 100, Affine::IDENTITY, &opts).pixels;
|
||||
let evaluated = r.live.evaluated;
|
||||
assert!(evaluated >= 2, "the first frame evaluates the envelopes of both paths' brush art: {evaluated}");
|
||||
let second = r.render(&d, 200, 100, Affine::IDENTITY, &opts).pixels;
|
||||
assert_eq!(r.live.evaluated, evaluated, "the second frame evaluates none of them again");
|
||||
assert!(second == first, "the second frame draws the same");
|
||||
assert!(second == Renderer::new().render(&d, 200, 100, Affine::IDENTITY, &opts).pixels, "a new renderer draws the same");
|
||||
}
|
||||
|
||||
/// Moving an instance places its art again, and editing a symbol's art places the art of its
|
||||
@@ -1092,6 +1296,95 @@ fn live_objects_draw_symbol_and_pattern_art_edits() {
|
||||
edit_draws_as_new(with_art(d, vec![envelope]), red_bar);
|
||||
}
|
||||
|
||||
/// Symbol `S` ([`symbol_art`]) at twice its size: bent by an envelope on the page at (50, 50), as
|
||||
/// the opacity mask of a black square at (350, 50) and in a clip group at (450, 50); not bent, in a
|
||||
/// group with a drop shadow at (150, 50); and an instance at (250, 50), at twice its size, of
|
||||
/// symbol `Bent`, whose art is an envelope bending a copy of `S`'s art.
|
||||
fn symbol_in_live_and_effect_art() -> Document {
|
||||
use vectorcraft_geom::shapes::rectangle;
|
||||
let mut d = Document::new(500.0, 100.0);
|
||||
let art = symbol_art(&mut d);
|
||||
d.symbols.push(vectorcraft_doc::Symbol { name: "S".into(), art: Arc::new(art) });
|
||||
let bent = |d: &mut Document, x: f64| {
|
||||
let xf = Affine::translate((x, 50.0)) * Affine::scale(2.0);
|
||||
let s = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: "S".into(), xf });
|
||||
arc_envelope(d, vec![s], false)
|
||||
};
|
||||
let envelope = bent(&mut d, 50.0);
|
||||
let xf = Affine::translate((150.0, 50.0)) * Affine::scale(2.0);
|
||||
let shadowed = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: "S".into(), xf });
|
||||
let mut group = Node::group(d.alloc_id(), vec![Arc::new(shadowed)]);
|
||||
group.appearance.effects.push(drop_shadow());
|
||||
let copy = symbol_art(&mut d);
|
||||
let art = arc_envelope(&mut d, vec![copy], false);
|
||||
d.symbols.push(vectorcraft_doc::Symbol { name: "Bent".into(), art: Arc::new(art) });
|
||||
let xf = Affine::translate((250.0, 50.0)) * Affine::scale(2.0);
|
||||
let symbol = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: "Bent".into(), xf });
|
||||
let mask = bent(&mut d, 350.0);
|
||||
let mut masked = filled(&mut d, rectangle(Rect::new(310.0, 10.0, 390.0, 90.0)), Paint::solid(Color::BLACK), vec![]);
|
||||
masked.extras_mut().mask = Some(Box::new(vectorcraft_doc::OpacityMask::new(mask, true)));
|
||||
let clip = filled(&mut d, rectangle(Rect::new(410.0, 10.0, 490.0, 90.0)), Paint::None, vec![]);
|
||||
let member = bent(&mut d, 450.0);
|
||||
let clipped = Node::new(d.alloc_id(), NodeKind::Group { children: vec![Arc::new(clip), Arc::new(member)], clip: true });
|
||||
with_art(d, vec![envelope, group, symbol, masked, clipped])
|
||||
}
|
||||
|
||||
/// A renderer draws [`symbol_in_live_and_effect_art`] a second time, in Preview and in Outline
|
||||
/// view, from what it kept, without walking any of its envelopes or its group with a drop shadow
|
||||
/// again.
|
||||
#[test]
|
||||
fn unchanged_live_objects_and_effect_art_are_not_walked_again() {
|
||||
let _fonts = fonts_steady();
|
||||
let d = symbol_in_live_and_effect_art();
|
||||
let preview = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() };
|
||||
let outline = RenderOptions { outline: true, ..preview.clone() };
|
||||
for (view, opts) in [("Preview", &preview), ("Outline", &outline)] {
|
||||
let mut r = Renderer::new();
|
||||
let first = r.render(&d, 500, 100, Affine::IDENTITY, opts).pixels;
|
||||
let walked = r.live.walked;
|
||||
assert!(walked >= 3, "{view}: the first frame walks the envelopes: {walked}");
|
||||
let second = r.render(&d, 500, 100, Affine::IDENTITY, opts).pixels;
|
||||
assert_eq!(r.live.walked, walked, "{view}: the second frame walks nothing again");
|
||||
assert!(second == first, "{view}: the second frame draws the same");
|
||||
}
|
||||
}
|
||||
|
||||
/// A thumbnail of an envelope around a symbol instance evaluates a copy of the envelope that the
|
||||
/// live cache does not keep, without walking it for the symbols it shows.
|
||||
#[test]
|
||||
fn live_objects_evaluated_without_the_cache_are_not_walked() {
|
||||
let _fonts = fonts_steady();
|
||||
let d = symbol_in_live_and_effect_art();
|
||||
let envelope = d.layers[0].children().unwrap()[0].clone();
|
||||
let mut r = Renderer::new();
|
||||
r.render_node_thumbnail(&d, &envelope, 32, None).unwrap();
|
||||
assert!(r.live.evaluated >= 1, "the thumbnail evaluates the envelope");
|
||||
assert_eq!(r.live.walked, 0, "the thumbnail walks nothing");
|
||||
}
|
||||
|
||||
/// After two frames of [`symbol_in_live_and_effect_art`], the second drawn from what the renderer
|
||||
/// kept, an edit of `S`'s art draws in Preview and in Outline view as a new renderer draws it.
|
||||
#[test]
|
||||
fn live_objects_and_effect_art_kept_without_a_walk_draw_symbol_edits() {
|
||||
let _fonts = fonts_steady();
|
||||
let preview = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() };
|
||||
let outline = RenderOptions { outline: true, ..preview.clone() };
|
||||
for (view, opts) in [("Preview", &preview), ("Outline", &outline)] {
|
||||
let mut d = symbol_in_live_and_effect_art();
|
||||
let mut r = Renderer::new();
|
||||
r.render(&d, 500, 100, Affine::IDENTITY, opts);
|
||||
let before = r.render(&d, 500, 100, Affine::IDENTITY, opts).pixels;
|
||||
// `S` becomes a wide red bar.
|
||||
let bar = vectorcraft_geom::shapes::rectangle(Rect::new(-20.0, -4.0, 20.0, 4.0));
|
||||
let red = vectorcraft_doc::Appearance::basic(Paint::solid(Color::rgb(1.0, 0.0, 0.0)), Paint::None, 0.0);
|
||||
d.symbols[0].art = Arc::new(Node::path(d.alloc_id(), bar, red));
|
||||
let after = r.render(&d, 500, 100, Affine::IDENTITY, opts).pixels;
|
||||
assert!(after != before, "{view}: the edit changes the frame");
|
||||
let fresh = Renderer::new().render(&d, 500, 100, Affine::IDENTITY, opts).pixels;
|
||||
assert!(after == fresh, "{view}: a new renderer draws the same");
|
||||
}
|
||||
}
|
||||
|
||||
/// Installs live-effect plug-in `id`, replacing one with the same id: its effect draws `shape` in
|
||||
/// place of the geometry it is given.
|
||||
fn install_shape(id: &str, shape: &vectorcraft_geom::PathData) {
|
||||
|
||||
Reference in New Issue
Block a user