From c1be491962e5f63ccce8274b76c182e46c527649 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 11:11:16 -0800 Subject: [PATCH] Export: nested symbol art baked and dropped still counts against the limit A nested reshaped instance whose baked art passes SYMBOL_ART_MAX_NODES stays an instance, and the art baked for it now counts against the instances after it (NESTED_DROPPED, as DROPPED_NODES does for placed art). Before, the count went back to its value before the instance, so many sibling instances could each bake up to the limit and be refused. --- crates/effects/src/bake.rs | 17 ++++++++--- crates/effects/src/bake/tests.rs | 52 ++++++++++++++++++++++++-------- docs/target-app-parity.md | 2 +- 3 files changed, 53 insertions(+), 18 deletions(-) diff --git a/crates/effects/src/bake.rs b/crates/effects/src/bake.rs index b008f41faf..67388c0d72 100644 --- a/crates/effects/src/bake.rs +++ b/crates/effects/src/bake.rs @@ -117,6 +117,11 @@ thread_local! { /// The objects of symbol art that [`bake_document`] has baked for instances inside the art of /// other instances, counted against [`crate::SYMBOL_ART_MAX_NODES`]. static NESTED_NODES: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// The objects in the baked art of the instances inside the art of other instances that + /// [`bake_node`] baked for one export and then left as they are, counted with + /// [`NESTED_NODES`] against [`crate::SYMBOL_ART_MAX_NODES`] before more art is baked. Never + /// given back. + static NESTED_DROPPED: std::cell::Cell = const { std::cell::Cell::new(0) }; /// While [`bake_document_placing_symbols`] bakes: the symbols whose instances become their /// placed art ([`placed_symbol_art`]). static PLACING: std::cell::RefCell>> = const { std::cell::RefCell::new(None) }; @@ -371,15 +376,17 @@ fn bake_object(d: &mut Document, n: &Node) -> Option { // passes the objects one export bakes that way: an instance of a symbol whose art holds // instances of itself is kept as it is there. The symbol's art is held in the count while // it bakes, so the instances inside it bake only within what is left; the art it bakes to, - // with what its effects add, then takes its place in the count, or the instance stays as it - // is and gives its objects back when that art does not fit. + // with what its effects add, then takes its place in the count. When that art does not + // fit, the instance stays as it is, and the art baked for it, with the art dropped for the + // instances inside it, still counts against the instances after it. let instance = matches!(n.kind, NodeKind::SymbolInstance { .. }); let nested = instance && INSTANCE_DEPTH.with(|c| c.get()) > 0; let before = NESTED_NODES.with(|c| c.get()); if nested { let count = symbol.as_ref().map_or(0, |a| a.count() as u64); let spent = before.saturating_add(count); - if INSTANCE_DEPTH.with(|c| c.get()) >= vectorcraft_doc::depth::MAX_DEPTH || spent > crate::SYMBOL_ART_MAX_NODES { + let dropped = NESTED_DROPPED.with(|c| c.get()); + if INSTANCE_DEPTH.with(|c| c.get()) >= vectorcraft_doc::depth::MAX_DEPTH || spent.saturating_add(dropped) > crate::SYMBOL_ART_MAX_NODES { return None; } NESTED_NODES.with(|c| c.set(spent)); @@ -400,8 +407,9 @@ fn bake_object(d: &mut Document, n: &Node) -> Option { let baked = baked.unwrap_or(m); if nested { let spent = before.saturating_add(baked.count() as u64); - if spent > crate::SYMBOL_ART_MAX_NODES { + if spent.saturating_add(NESTED_DROPPED.with(|c| c.get())) > crate::SYMBOL_ART_MAX_NODES { NESTED_NODES.with(|c| c.set(before)); + NESTED_DROPPED.with(|c| c.set(c.get().saturating_add(baked.count() as u64))); return None; } NESTED_NODES.with(|c| c.set(spent)); @@ -1087,6 +1095,7 @@ fn bake(doc: &Document, placing: Option<(bool, u64, WrittenLayers)>) -> Option Node { } /// `n` baked as an instance inside another instance's art, with `spent` objects of nested symbol -/// art already baked: the baked object, and the objects counted after it. +/// art already baked: the baked object, and the objects counted after it, art baked and dropped +/// included. fn bake_nested(d: &mut Document, n: &Node, spent: u64) -> (Option, u64) { INSTANCE_DEPTH.with(|c| c.set(1)); NESTED_NODES.with(|c| c.set(spent)); + NESTED_DROPPED.with(|c| c.set(0)); let out = bake_node(d, n); INSTANCE_DEPTH.with(|c| c.set(0)); - (out, NESTED_NODES.with(|c| c.replace(0))) + (out, NESTED_NODES.with(|c| c.replace(0)).saturating_add(NESTED_DROPPED.with(|c| c.replace(0)))) } /// The object with id `id` in `n`'s subtree. @@ -1558,7 +1560,7 @@ fn baked(n: Option<&Node>) -> bool { /// An instance baked inside another instance's art counts the art it bakes to, the copies its /// symbol's effects make included: art that fits exactly takes the last of the budget, and art -/// whose symbol fits but whose baked art does not leaves the instance as it is. +/// whose symbol fits but whose baked art does not leaves the instance as it is and still counts. #[test] fn nested_reshape_counts_baked_art() { let mut d = Document::new(400.0, 400.0); @@ -1575,13 +1577,13 @@ fn nested_reshape_counts_baked_art() { assert_eq!(spent, max); let (short, spent) = bake_nested(&mut d, &n, max - baked + 1); assert!(short.is_none(), "the symbol's {source} objects fit, the {baked} baked ones do not"); - assert_eq!(spent, max - baked + 1, "the instance left as it is counts nothing"); + assert_eq!(spent, max + 1, "the art baked for the instance left as it is still counts"); } -/// An instance left as it is because its baked art does not fit gives back what its art held -/// while it baked: an instance after it whose baked art fits in what is left is baked. +/// An instance left as it is because its baked art does not fit still counts the art baked for +/// it: an instance after it is left as it is too, before its art bakes. #[test] -fn nested_reshape_refusal_restores_budget() { +fn nested_reshape_refusal_keeps_its_work_counted() { let mut d = Document::new(400.0, 400.0); add_symbol(&mut d, "Big", gradient_copies(800)); add_symbol(&mut d, "Small", moved_square(810)); @@ -1592,14 +1594,37 @@ fn nested_reshape_refusal_restores_budget() { let first = crate::SYMBOL_ART_MAX_NODES - b + 1; let (refused, spent) = bake_nested(&mut d, &big, first); assert!(refused.is_none(), "the big art passes the budget"); - assert_eq!(spent, first); - let (later, spent) = bake_nested(&mut d, &small, spent); - assert!(later.is_some(), "the small art fits in what the big art gave back"); - assert_eq!(spent, first + s); + assert_eq!(spent, first + b, "the big art baked and dropped counts"); + let (later, after) = bake_nested(&mut d, &small, spent); + assert!(later.is_none(), "the small art does not fit after the dropped art"); + assert_eq!(after, spent, "the small instance is refused before it bakes"); +} + +/// Sibling instances inside other instances' art whose baked art each passes what is left: the +/// first is baked and dropped, and its art counts, so the others are left as they are before +/// their art bakes. With room for all of them, every one is baked. +#[test] +fn nested_reshape_refused_siblings_bake_once() { + let mut d = Document::new(400.0, 400.0); + add_symbol(&mut d, "Big", gradient_copies(800)); + let one = offset_instance(900, "Big"); + let b = bake_nested(&mut d, &one, 0).0.map_or(0, |m| m.count() as u64); + let siblings: Vec> = (0..16).map(|i| Arc::new(offset_instance(1000 + i, "Big"))).collect(); + let group = Node::group(NodeId(999), siblings); + let first = crate::SYMBOL_ART_MAX_NODES - b + 1; + let (refused, spent) = bake_nested(&mut d, &group, first); + let refused = refused.unwrap_or_else(|| group.clone()); + assert!((0..16).all(|i| !baked(find(&refused, 1000 + i))), "no sibling fits: {refused:?}"); + assert_eq!(spent, first + b, "only the first sibling's art is baked and counted: {spent}"); + let (room, spent) = bake_nested(&mut d, &group, 0); + let room = room.unwrap_or_else(|| panic!("the siblings are baked")); + assert!((0..16).all(|i| baked(find(&room, 1000 + i))), "every sibling is baked"); + assert_eq!(spent, 16 * b); } /// An instance inside another instance's art whose own art holds a reshaped instance counts that -/// instance's baked art once: a budget of exactly the outer art's baked objects bakes both. +/// instance's baked art once: a budget of exactly the outer art's baked objects bakes both, and +/// with one object less the art baked and dropped still counts. #[test] fn nested_reshape_counts_successful_descendants_once() { let mut d = Document::new(400.0, 400.0); @@ -1619,5 +1644,6 @@ fn nested_reshape_counts_successful_descendants_once() { assert_eq!(spent, max); let (short, spent) = bake_nested(&mut d, &outer, max - total + 1); assert!(short.as_ref().is_none_or(|m| !baked(find(m, 802))), "with one object less, not both are baked"); - assert!(spent <= max); + assert!(spent > max, "the art baked and dropped counts: {spent}"); + assert!(spent <= max - total + 1 + 2 * total, "at most the outer and the inner art are dropped: {spent}"); } diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 9517e19143..54fe627ae9 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1698,7 +1698,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur A geometry effect on one of type's own fills or strokes reshapes the whole outline that the fill or stroke paints, on the canvas and in exports; PDF, SVG, EPS and the other vector exports write such type as paths. On type that holds inline graphics, those effects are drawn and exported only when the type has a geometry effect or perspective of its own. A geometry effect on a symbol instance's fill reshapes the filled shapes of the symbol's art and leaves their strokes as they are; one on the instance's stroke reshapes the stroked shapes and leaves their fills as they are. The shapes keep their colors. Only the instance's topmost fill and topmost stroke count, and only while they are visible with an opacity above 0. The canvas and Object › Expand Appearance use the same art, SVG and PDF export bake the same shapes, and Expand Appearance turns the instance into an editable group in one undo step. A group's own fills and strokes in the art take the effects too. An instance inside the art passes the effects on to its own art, and a dynamic symbol's instance reshapes the fills and strokes it paints on the art. How the effects map onto the symbol's art is VectorCraft's own rule. The help page describes effects on one fill or stroke, and the help page describes Expand Appearance (engine `expand::a_symbol_instance_fill_effect_reshapes_its_filled_art_and_expands`, `a_symbol_instance_stroke_effect_reshapes_its_stroked_art_and_expands`, `a_stroke_effect_reshapes_a_stroke_a_dynamic_instance_adds`, `a_fill_effect_reshapes_the_fill_of_a_group_in_the_art`, `only_the_topmost_visible_instance_fill_reshapes_the_art`, `a_nested_symbol_instance_takes_the_outer_fill_effect`, `export_bakes_a_symbol_instance_fill_effect`, `a_fill_effect_on_an_instance_of_a_symbol_that_holds_itself_ends`). Existing documents with a geometry effect on a symbol instance's fill or stroke draw differently: before, the effect drew nothing. Live effects inside a symbol's art (geometry effects, color adjustments and the rest that export bakes) are written where each instance places the art in PDF, print, EPS and DXF, as the canvas draws them: the art is placed first and its effects are applied after, so an instance that scales its art does not scale the distance a Transform effect moves it. Symbols nested in the art, a dynamic symbol instance's own paint changes and the stain an instance's fill gives its art are kept, and the art is stained before its effects apply. A linked instance's PDF link covers its art where the effects draw it. A symbol whose art holds itself stops at the nesting limit, and the symbols' own art keeps its effects. An instance stays an instance in these exports when the objects its art makes once baked (the copies a Transform effect makes included) would take the export's placed symbol art past 16,000,000 objects, or when its baked art would draw deeper than the 128 levels a document may draw; these are VectorCraft's own limits. Art baked for an instance that then stays an instance still counts toward that limit, and while an instance's art bakes, the art's own objects are held in the limit for the instances nested in it. Instances the export leaves out (hidden ones, those in hidden groups, on template layers, and on hidden layers or layers that do not print when the export leaves those out) are not placed and do not count toward that limit. Before, these exports wrote the art without its effects (effects `bake::placing_symbols_bakes_their_art_where_each_instance_places_it`, `placing_symbols_reaches_the_art_of_nested_instances`, `placing_a_symbol_that_holds_itself_stops`, `placing_symbols_keeps_dynamic_instances_changes`, `placing_symbols_keeps_the_instances_stain`, `placing_symbols_counts_the_baked_art`, `placing_symbols_counts_nested_art_once`, `placing_symbols_holds_the_outer_art_while_it_bakes`, `placing_symbols_counts_the_art_it_drops`, `placing_symbols_counts_art_dropped_for_depth_against_later_baked_art`, `placing_symbols_keeps_the_baked_art_within_the_drawn_depth`, `placing_symbols_skips_instances_the_export_leaves_out`; doc `depth::tests::drawn_heights_measure_objects_outside_the_layers`; PDF, print, EPS and DXF `symbol_art_effects_are_written_where_they_draw`, `symbol_art_effects_print_where_they_draw`; PDF `a_stained_instance_keeps_its_stain_when_its_art_has_effects`, `a_linked_instance_keeps_its_link_when_its_art_has_effects`). - When an export bakes a symbol instance with geometry effects inside the art of another such instance, it counts the art the inner instance bakes to, the copies its symbol's effects make included, against the 262,144 objects of symbol art one export bakes that way; it counted only the symbol's art before its effects. An instance whose baked art would pass that count stays an instance with its effects, and the objects its art held while it baked do not count against the instances after it. These are VectorCraft's own limits (effects `bake::nested_reshape_counts_baked_art`, `nested_reshape_refusal_restores_budget`, `nested_reshape_counts_successful_descendants_once`). + When an export bakes a symbol instance with geometry effects inside the art of another such instance, it counts the art the inner instance bakes to, the copies its symbol's effects make included, against the 262,144 objects of symbol art one export bakes that way; it counted only the symbol's art before its effects. An instance whose baked art would pass that count stays an instance with its effects, and the art baked for it still counts against the instances after it. These are VectorCraft's own limits (effects `bake::nested_reshape_counts_baked_art`, `nested_reshape_refusal_keeps_its_work_counted`, `nested_reshape_refused_siblings_bake_once`, `nested_reshape_counts_successful_descendants_once`). A raster effect (Drop Shadow, Outer Glow, Gaussian Blur and the other effects that paint pixels) on a symbol instance's topmost fill draws on each filled shape of the symbol's art, and one on its topmost stroke draws on each stroked shape, after any geometry effects listed before it, under the same rules as geometry effects: only a visible fill or stroke with an opacity above 0 counts, a group's own fills and strokes in the art take the effect, and an instance inside the art passes it on. Each shape gets its own shadow or glow, which is VectorCraft's own rule. The canvas, Use Preview Bounds and the drawn bounds, SVG and PDF export draw it, and Object › Expand Appearance is enabled for such an instance and makes the effect an image at the document's raster effects resolution, in one undo step (engine `expand::a_symbol_instance_fill_shadow_shadows_its_filled_art`, `a_symbol_instance_stroke_shadow_shadows_only_its_stroked_art`, `a_symbol_instance_fill_shadow_follows_the_fill_offset_before_it`, `a_nested_symbol_instance_takes_the_outer_fill_shadow`, `export_draws_a_symbol_instance_fill_shadow`). Existing documents with a raster effect on a symbol instance's fill or stroke draw differently: before, the effect drew nothing. The Appearance panel's inline effect editor labels each parameter as the effect dialogs' generic fields do, without the colon ("Max. Radius", "Channel 1", "Create New Fields by"). Roughen's and Zig Zag's Points, Offset Path's Joins, Inner Glow's Source and the menus of Radial Blur, Smart Blur, Sprayed Strokes, Glass, Mezzotint, Halftone Pattern, Grain, Texturizer and De-Interlace are dropdowns with the dialog's labels that send the dialog's values, and a plug-in's choice is a dropdown of the plug-in's values. Revolve's edge, Extrude & Bevel's bevel, every Warp style's orientation, Rasterize's Color Model, Background and Anti-aliasing and the channel of Levels and Curves are dropdowns too, with the labels their own dialogs show. `effect.apply` and `effect.setParams` refuse a Levels or Curves `channel` other than `rgb`, `red`, `green` or `blue` (or `r`, `g` and `b`, in any letter case).