Files
vectorcraft/crates/render/src/bounds.rs
T
dotCooCoo 00f42826ef Effects: each copy of a Transform effect listed after Rasterize carries the Rasterize image
On a path or compound path, a Transform effect with copies listed after
the object's own Rasterize effect now places the one image Rasterize
makes of the art before it on the original and on each copy: copy k
through the effect's map applied k times, with its pixel grid and its
room around the art, the last copy lowest and the original on top.
Before, the Transform effect copied the art and Rasterize made one image
of all the copies on a grid square to the page.

The image is made once for every placement, also when a shadow or glow
is listed between the Rasterize and Transform effects. The canvas, the
object's bounds, Expand Appearance and PDF export use the same
placements; Expand Appearance and PDF export make a group of images that
share the one image's pixels. Copies stop where the copied art stops,
and a copy scaled to nothing is left out.
2026-11-16 13:55:27 -08:00

87 lines
4.5 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
use std::sync::Arc;
use super::{BezPath, Document, FillRule, Node, NodeKind, Rect, SymbolBoxes, brush_fx, fx};
/// Bounds of everything `n` paints, as the renderer culls it: its members, strokes, brush art and
/// geometry effects, and the shadows and glows of it and its members. Symbol instances are
/// measured by their art in `doc` ([`Node::visual_bounds_with`]).
pub fn painted_bounds(doc: &Document, n: &Node) -> Option<Rect> {
brush_fx::cull_bounds(&doc.symbol_boxes(), n)
}
/// [`painted_bounds`] of `n` without the room it leaves for brush art past the brushed strokes of
/// `n` and of a symbol instance's art (the brush art of the objects in a blend, envelope or repeat
/// still counts). A group or layer without effects of its own is measured by its members, leaving
/// out the transparent source art of a Shaper group as [`Node::visual_bounds_with`] does. Symbol
/// instances are measured by their art in `symbols`.
pub fn effect_bounds(symbols: &SymbolBoxes, n: &Node) -> Option<Rect> {
effect_bounds_with(symbols, n, None, None)
}
impl crate::Renderer {
/// [`effect_bounds`] of `n`, its 3D art measured as this renderer draws and keeps it
/// (`Renderer::bounds_of`): a pass that measures the same objects again, over each
/// artboard of an export, builds each solid once. What it keeps is measured with the symbol
/// boxes it was first measured with, and found by the objects' addresses: give each document,
/// and each kind of `symbols`, its own renderer.
pub fn effect_bounds(&mut self, symbols: &SymbolBoxes, n: &Arc<Node>) -> Option<Rect> {
effect_bounds_with(symbols, n, Some(n), Some(self))
}
}
/// [`effect_bounds`] of `n` (`held`: `n` as held in its document, which `renderer` keeps what it
/// measures by). Through `renderer`, an object is measured once for every artboard it measures:
/// those it measures as [`effect_bounds`] does (`Renderer::bounds_of`), those whose
/// brushed strokes it leaves room for afresh.
pub(crate) fn effect_bounds_with(
symbols: &SymbolBoxes,
n: &Node,
held: Option<&Arc<Node>>,
mut renderer: Option<&mut crate::Renderer>,
) -> Option<Rect> {
match &n.kind {
NodeKind::Layer { children, clip: false, .. } | NodeKind::Group { children, clip: false } if !fx::has_object_fx(n) => children
.iter()
.skip(usize::from(n.extras().shaper.is_some()))
.fold(None, |acc, c| vectorcraft_geom::union_opt(acc, effect_bounds_with(symbols, c, Some(c), renderer.as_deref_mut()))),
_ => match (renderer, held) {
(Some(r), Some(a)) if brush_fx::pad(symbols, a) == 0.0 => r.bounds_of(symbols, a),
_ => fx::cull_bounds(symbols, n),
},
}
}
/// Bounds of what `n` draws with its own and its members' geometry effects applied and with the
/// reach of its own and its members' raster effects, measured as [`Node::visual_bounds_with`]
/// measures art without effects: what Object › Rasterize makes its image over.
pub fn drawn_bounds(doc: &Document, n: &Node) -> Option<Rect> {
fx::painted_reach(&doc.symbol_boxes(), n)
}
/// For a path or compound path whose own Rasterize effect is followed by Transform effects that
/// move or copy the art ([`crate::effects::rasterize_stage`]): `n` with those Transform effects
/// hidden, which the image is made of, and the maps they place the image by, the lowest first
/// (one per copy, the original's last). The canvas draws the image on its own pixel grid and
/// places it, and the room around the art, through each map. `None` for other objects.
pub fn rasterize_stage(doc: &Document, n: &Node) -> Option<(Node, Vec<vectorcraft_geom::Affine>)> {
fx::rasterize_stage(doc, n)
}
/// The outline, with `n`'s geometry effects applied, that the canvas clips `n`'s Rasterize with
/// Create Clipping Mask to. Object › Rasterize's clipping mask follows it.
pub fn drawn_outline(doc: &Document, n: &Node) -> Option<(BezPath, FillRule)> {
fx::drawn_outline(doc, n)
}
/// The outlines a drag draws for `nodes` with Real-time Drawing off: one for each object in them,
/// without uniting a group's members. `None` when the outlines' points and the objects evaluated to
/// make them come to more than `max_points`.
pub fn drawn_outlines<'a>(doc: &Document, nodes: impl IntoIterator<Item = &'a Node>, max_points: usize) -> Option<Vec<BezPath>> {
let symbols = doc.symbol_boxes();
let (mut left, mut out) = (max_points, vec![]);
for n in nodes {
fx::drawn_outlines(doc, &symbols, n, &mut left, &mut out)?;
}
Some(out)
}