mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 16:42:52 +00:00
Merge pull request #7967 from dotCooCoo/fix/svg-artboard-export-keeps-brushed-path
SVG: an artboard's SVG keeps a brushed path whose brush art reaches it
This commit is contained in:
@@ -199,8 +199,12 @@ fn selected_part(n: &Arc<Node>, keep: &HashSet<NodeId>, holders: &HashSet<NodeId
|
||||
/// out, at any depth of layers, sublayers and groups that don't clip, unless what the renderer
|
||||
/// draws for them, their effects included ([`vectorcraft_render::effect_bounds`]), reaches it.
|
||||
/// Objects that reach it stay whole (the file's bounds clip them), as DXF's crop leaves them.
|
||||
/// Symbol instances are measured by their art, and the box of one whose art holds brushed strokes
|
||||
/// grows by as far as their brush art can paint ([`SymbolBoxes::with_brush_art`]). An object that
|
||||
/// Both boxes grow by the room brush art can paint past the brushed strokes of the object and of
|
||||
/// the objects in it ([`vectorcraft_brush::reach_within`]: a clipping group or layer by its clipping
|
||||
/// path's, a compound path by its own strokes'), so a brushed path just off `rect` stays when its
|
||||
/// brush art reaches it. Symbol instances are measured by their art, and the box of one whose art
|
||||
/// holds brushed strokes grows by as far as their brush art can paint
|
||||
/// ([`SymbolBoxes::with_brush_art`]). An object that
|
||||
/// holds a symbol instance also stays when what the canvas paints for it reaches `rect`
|
||||
/// ([`vectorcraft_render::painted_bounds`]: the effects in the symbols' art and its own effects). A
|
||||
/// clipping layer keeps every object, its clipping path among them. An artboard's file then holds
|
||||
@@ -233,7 +237,9 @@ pub(super) fn art_over(doc: &Document, rect: vectorcraft_geom::Rect, renderer: &
|
||||
let mut holds_instance = false;
|
||||
n.walk(&mut |c| holds_instance |= matches!(c.kind, NodeKind::SymbolInstance { .. }));
|
||||
let painted = || holds_instance && vectorcraft_render::painted_bounds(doc, n).is_some_and(over);
|
||||
(n.visual_bounds_with(symbols).is_none_or(over) || renderer.effect_bounds(symbols, n).is_some_and(over) || painted()).then(|| n.clone())
|
||||
let reach = vectorcraft_brush::reach_within(n);
|
||||
let brushed = |b: vectorcraft_geom::Rect| over(if reach > 0.0 { b.inflate(reach, reach) } else { b });
|
||||
(n.visual_bounds_with(symbols).is_none_or(brushed) || renderer.effect_bounds(symbols, n).is_some_and(brushed) || painted()).then(|| n.clone())
|
||||
}
|
||||
let symbols = doc.symbol_boxes().with_brush_art();
|
||||
let mut d = doc.clone();
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
//! SVG encodings, profiles and embedded fonts through the engine: the options reach the file,
|
||||
//! files in each encoding open again, and `document.serialize` reads them as text.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde_json::json;
|
||||
use vectorcraft_doc::Document;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -109,6 +112,106 @@ fn a_chosen_artboard_s_svg_keeps_an_object_whose_shadow_reaches_it() {
|
||||
assert_eq!(paths(&mut s), 1, "its shadow reaches 10 pt onto the artboard");
|
||||
}
|
||||
|
||||
/// A 100 × 100 document whose 3 pt. Round brush paints with a 20 pt nib, and the left edge of its
|
||||
/// artboard.
|
||||
fn nib_doc() -> (Document, f64) {
|
||||
let mut d = Document::new(100.0, 100.0);
|
||||
let mut lib = vectorcraft_brush::library(&d);
|
||||
let Some(vectorcraft_brush::BrushKind::Calligraphic(c)) = lib.iter_mut().find(|b| b.name == "3 pt. Round").map(|b| &mut b.kind) else {
|
||||
panic!("the 3 pt. Round brush")
|
||||
};
|
||||
c.size = 20.0;
|
||||
vectorcraft_brush::store(&mut d, &lib);
|
||||
let x0 = d.artboards[0].rect.x0;
|
||||
(d, x0)
|
||||
}
|
||||
|
||||
/// A line from (`x`, 40) to (`x`, 60) with a 1 pt stroke in `paint`, painted by the 20 pt nib of
|
||||
/// [`nib_doc`] when `brushed`: the nib paints 10 pt either side of the line.
|
||||
fn nib_line(d: &mut Document, x: f64, paint: vectorcraft_color::Paint, brushed: bool) -> vectorcraft_doc::Node {
|
||||
let mut look = vectorcraft_doc::Appearance::basic(vectorcraft_color::Paint::None, paint, 1.0);
|
||||
if brushed {
|
||||
look.stroke_mut().unwrap().brush = Some("3 pt. Round".into());
|
||||
}
|
||||
let line = vectorcraft_geom::shapes::line((x, 40.0).into(), (x, 60.0).into());
|
||||
vectorcraft_doc::Node::path(d.alloc_id(), line, look)
|
||||
}
|
||||
|
||||
fn black() -> vectorcraft_color::Paint {
|
||||
vectorcraft_color::Paint::solid(vectorcraft_color::Color::BLACK)
|
||||
}
|
||||
|
||||
/// A brushed path just left of a chosen artboard, whose brush art paints onto it, is in that
|
||||
/// artboard's SVG and SVGZ; a brushed path too far off for its brush art to reach it is not.
|
||||
#[test]
|
||||
fn a_chosen_artboard_s_svg_keeps_brush_art_reaching_in() {
|
||||
let (mut d, x0) = nib_doc();
|
||||
let layer = d.layers[0].id;
|
||||
let near = nib_line(&mut d, x0 - 5.0, black(), true);
|
||||
let far = nib_line(&mut d, x0 - 200.0, black(), true);
|
||||
let (near, far) = (d.insert(Some(layer), 0, near).unwrap(), d.insert(Some(layer), 0, far).unwrap());
|
||||
let kept = export::art_over(&d, d.artboards[0].rect, &mut vectorcraft_render::Renderer::new());
|
||||
assert!(kept.node(near).is_some(), "the nib paints 5 pt onto the artboard");
|
||||
assert!(kept.node(far).is_none(), "the nib paints 190 pt short of the artboard");
|
||||
let mut s = Session::new();
|
||||
s.add_document(d, None);
|
||||
let svg = s.execute("document.serialize", &json!({"format": "svg", "artboard": 0})).unwrap();
|
||||
let svg = svg["text"].as_str().unwrap().to_string();
|
||||
assert!(vectorcraft_testkit::svg_shapes(&svg) > 0, "{svg}");
|
||||
let svgz = s.execute("document.serialize", &json!({"format": "svgz", "artboard": 0})).unwrap();
|
||||
let svgz = vectorcraft_format::base64_decode(svgz["dataBase64"].as_str().unwrap()).unwrap();
|
||||
assert_eq!(vectorcraft_svg::text_of(&svgz).unwrap(), svg, "the SVGZ is the SVG gzipped");
|
||||
}
|
||||
|
||||
/// The room for brush art also keeps a brushed path in a plain group on a sublayer. A brushed
|
||||
/// stroke without a paint draws no brush art, a clipping group's clip keeps its members' brush art
|
||||
/// inside it, and a compound path is painted with its own appearance, not its paths': those stay
|
||||
/// out when only brush art could reach the artboard.
|
||||
#[test]
|
||||
fn a_chosen_artboard_s_svg_keeps_nested_brush_art_but_not_unpainted_or_clipped_art() {
|
||||
use vectorcraft_doc::{LayerColor, Node, NodeKind};
|
||||
let (mut d, x0) = nib_doc();
|
||||
let layer = d.layers[0].id;
|
||||
let x = x0 - 5.0;
|
||||
// A brushed line in a plain group on a sublayer.
|
||||
let line = nib_line(&mut d, x, black(), true);
|
||||
let nested = line.id;
|
||||
let group = Node::new(d.alloc_id(), NodeKind::Group { children: vec![Arc::new(line)], clip: false });
|
||||
let mut sublayer = Node::layer(d.alloc_id(), "Sublayer", LayerColor::Preset(1));
|
||||
sublayer.children_mut().unwrap().push(Arc::new(group));
|
||||
d.insert(Some(layer), 0, sublayer).unwrap();
|
||||
// A brushed stroke without a paint.
|
||||
let unpainted = nib_line(&mut d, x, vectorcraft_color::Paint::None, true);
|
||||
let unpainted = d.insert(Some(layer), 0, unpainted).unwrap();
|
||||
// A clipping group whose clip, far left of the artboard, holds a brushed line just off it.
|
||||
let mut clip = Node::path(
|
||||
d.alloc_id(),
|
||||
vectorcraft_geom::shapes::rectangle(vectorcraft_geom::Rect::new(x0 - 100.0, 40.0, x0 - 90.0, 60.0)),
|
||||
vectorcraft_doc::Appearance::basic(vectorcraft_color::Paint::None, vectorcraft_color::Paint::None, 0.0),
|
||||
);
|
||||
if let NodeKind::Path { clipping, .. } = &mut clip.kind {
|
||||
*clipping = true;
|
||||
}
|
||||
let member = nib_line(&mut d, x, black(), true);
|
||||
let clipped = Node::new(d.alloc_id(), NodeKind::Group { children: vec![Arc::new(clip), Arc::new(member)], clip: true });
|
||||
let clipped = d.insert(Some(layer), 0, clipped).unwrap();
|
||||
// Compound paths of a brushed line: plain itself, then brushed itself.
|
||||
let mut compounds = vec![];
|
||||
for own in [false, true] {
|
||||
let member = nib_line(&mut d, x, black(), true);
|
||||
let mut compound =
|
||||
Node::new(d.alloc_id(), NodeKind::Compound { children: vec![Arc::new(member)], rule: vectorcraft_geom::FillRule::NonZero });
|
||||
compound.appearance = nib_line(&mut d, x, black(), own).appearance;
|
||||
compounds.push(d.insert(Some(layer), 0, compound).unwrap());
|
||||
}
|
||||
let kept = export::art_over(&d, d.artboards[0].rect, &mut vectorcraft_render::Renderer::new());
|
||||
assert!(kept.node(nested).is_some(), "the brushed line in the group on the sublayer");
|
||||
assert!(kept.node(unpainted).is_none(), "a brushed stroke without a paint");
|
||||
assert!(kept.node(clipped).is_none(), "a clipping group whose clip misses the artboard");
|
||||
assert!(kept.node(compounds[0]).is_none(), "a compound path that is not brushed itself");
|
||||
assert!(kept.node(compounds[1]).is_some(), "a compound path that is brushed itself");
|
||||
}
|
||||
|
||||
/// #3544: an SVG of one artboard on its own (an `artboard` or `range`, Export for Screens, an asset)
|
||||
/// has the artboard's (or asset's) name as `<title>`; Save's SVG and Export for Screens' Full
|
||||
/// Document keep the document's.
|
||||
|
||||
@@ -2191,6 +2191,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **Later effects on every fill or stroke a painted effect returns (G17):** when a painted effect on a fill or stroke returns several fills or strokes, a later live-effect plug-in in that fill's or stroke's stack, and a later geometry effect on strokes, runs once on each of them in paint order, given its own paint and its own `_context.item` among them. Each run's pieces replace only that fill or stroke. A run that fails, is refused, is deferred or would pass the effects' budget leaves only its own fill or stroke as it was, and the others still run; a deferred stage is listed once, at the source fill's or stroke's place. Regressions: `crates/engine/src/tests/plugins.rs`, `crates/effects/src/tests/painted.rs`. Scores and hours unchanged.
|
||||
- **Painted pieces with brushed strokes are culled and measured by their brush art (G17):** a piece that keeps the object's brushed stroke draws the brush along the piece's own path at the piece's stroke width. Culling leaves VectorCraft's usual room for brush art (16 × the stroke width + 8 pt) past each piece, from the piece's width rather than the object's, and so does culling of a group, layer, symbol instance, blend, envelope or repeat that holds the object. A group or layer also leaves that room for each brushed path among its members, painted or not. Object › Rasterize takes the brush art drawn along each piece and leaves out the object's own brush art, which is not drawn. Pieces without a brush are culled as before. Regressions: `crates/render/src/tests/paintedbrush.rs`. Scores and hours unchanged.
|
||||
- **Brushed paths just off the page are exported and printed:** PDF and EPS export keep a path or compound path whose brush art reaches the page while the path lies just off it, alone or in a group, by leaving the canvas's room for brush art (16 × the widest stroke + 8 pt, VectorCraft's own value) past its box. Skip Blank Artboards keeps an artboard such brush art reaches, and Print with Ignore Artboards frames the page with that room around brushed paths and around instances whose art holds brushed strokes. A clip group leaves room only for its clipping path. Art without brushed strokes is written as before. Regressions: `crates/pdf/src/tests.rs`, `crates/pdf/src/tests/print.rs`, `crates/eps/src/tests.rs`. Scores and hours unchanged.
|
||||
- **Brushed paths just off an artboard are in its SVG:** the SVG or SVGZ of a chosen artboard (`artboard`, or Use Artboards with a range) keeps a path whose brush art reaches the artboard while the path lies just off it, alone, in a group or on a sublayer, with the room for brush art that PDF and EPS export leave (16 × the widest stroke + 8 pt, VectorCraft's own value). A brushed stroke without a paint gets no room, a clip group leaves room only for its clipping path, and a compound path only for its own strokes. Regressions: `crates/engine/src/cmd/fileio/tests_svgenc.rs`. Scores and hours unchanged.
|
||||
- **Live-effect plug-ins while a document opens (G17):** the live-effect plug-in runs of a document's first view on screen share a 2,000 ms budget (VectorCraft's own value). A stage left out for time, or one that times out, fails, has no plug-in or meets Safe Mode, draws its input unchanged and is deferred; the status bar says how many, `effect.deferredStatus` lists them with their object, effect and reason, and Effect › Refresh Deferred Effects (`effect.refreshDeferred`) runs them again with a fresh budget. Each document has its own budget, an edit runs the stages it changes, and exports, Expand Appearance and commands run every stage under the 5 s limit of each run. The web build times the budget and each run's limit with the page's `performance.now()`. Regressions: `crates/plugins/src/deferred.rs`, `crates/plugins/src/effect.rs`, `crates/plugins/src/host.rs`, `crates/engine/src/tests/plugins.rs`, `crates/ui-egui/src/canvas/tests.rs`. Scores and hours unchanged.
|
||||
- **Refreshing many deferred effects (G17):** Refresh Deferred Effects (`effect.refreshDeferred`) looks up the objects asked for, the stages reached, the objects drawn whole and the inputs that ran in hash sets, so its time no longer grows with the square of the number of deferred stages. The deferred records are indexed by stage and input, so asking whether a stage stays deferred, replacing a stage's records when it runs, and ending a drawing after the first view look at that stage's records only, and the records keep the order they were made in. With 40,000 deferred stages, one refresh in a release build took 38 ms, down from 1,036 ms, and asking about and running each stage once took 16 ms, down from 2,287 ms (wall-clock time on a computer busy with other builds, one run each). Regressions: `crates/plugins/src/deferred.rs`. Scores and hours unchanged.
|
||||
- **Refresh Deferred Effects by object (G17):** `effect.refreshDeferred` takes `ids`, or `id` for one, naming objects in the layers or in the art of a symbol, pattern, brush or opacity mask, the objects `effect.deferredStatus` lists; an object without a deferred stage adds nothing to the counts, and an id of no object in the document is an error. Regressions: `crates/engine/src/tests/plugins.rs`. Scores and hours unchanged.
|
||||
|
||||
Reference in New Issue
Block a user