diff --git a/crates/effects/src/group.rs b/crates/effects/src/group.rs index 70e010c8e3..e517f7e658 100644 --- a/crates/effects/src/group.rs +++ b/crates/effects/src/group.rs @@ -66,7 +66,7 @@ pub const PATHFINDER_EFFECT_PRECISION: std::ops::RangeInclusive = 0.001..=1 /// The documentation of [`PATHFINDER_OPTION_KEYS`], as a literal for `concat!`. macro_rules! options_doc { () => { - "precision?: pt 0.001..10 (effect.apply: Pathfinder Options › Precision; 0.01 when missing; results are refit to within it and pieces thinner than it are dropped), removeRedundantPoints?: bool (effect.apply: Pathfinder Options › Remove Redundant Points; false when missing; results lose the anchors that don't change their shape to within precision), removeUnpainted?: bool (effect.apply: Pathfinder Options › Divide and Outline Will Remove Unpainted Artwork; false when missing; Divide and Outline leave out the pieces of members with no visible fill, except that Divide keeps every piece when the group or compound shape has a visible fill of its own; the other operations ignore it)" + "precision?: pt 0.001..10 (effect.apply: Pathfinder Options › Precision; 0.01 when missing; results are refit to within it and pieces thinner than it are dropped), removeRedundantPoints?: bool (effect.apply: Pathfinder Options › Remove Redundant Points; false when missing; results lose the anchors that don't change their shape to within precision), removeUnpainted?: bool (effect.apply: Pathfinder Options › Divide and Outline Will Remove Unpainted Artwork; false when missing; Divide and Outline leave out the pieces of members with no visible fill, a compound shape's area going by the shape's own fill, except that Divide keeps every piece when the group or compound shape has a visible fill of its own; the other operations ignore it)" }; } @@ -555,10 +555,23 @@ pub fn pathfinder_children(doc: Option<&Document>, group: &Node, hook: Option Option { + let a = area_style.as_ref().filter(|_| s.id == group.id && s.appearance.items.is_empty())?; + let mut a = a.clone(); + (a.opacity, a.blend) = (s.opacity, s.blend); + Some(a) + }; let mut stack: Vec> = if group.is_compound_shape() { // The group's own appearance paints the area ([`evaluate_container`]), so the art has none. match compound_shape_area(doc, group, hook) { @@ -654,10 +667,16 @@ pub fn pathfinder_children(doc: Option<&Document>, group: &Node, hook: Option true, _ => false, }; + let fill_sources: Vec> = sources.iter().map(style_of).collect(); + let fill_source = |k: u64| fill_sources[k as usize].as_ref().unwrap_or(&sources[k as usize]); po::pathfinder_with(op, &shapes, options.precision) .into_iter() - .filter(|r| !r.path.is_empty() && !(unpainted && !has_visible_fill(&sources[r.key as usize]))) - .map(|r| Arc::new(styled(&sources[r.key as usize], tidy(r.path), op == PathfinderOp::Outline))) + .filter(|r| !r.path.is_empty() && !(unpainted && !has_visible_fill(fill_source(r.key)))) + .map(|r| { + let outline = op == PathfinderOp::Outline; + let src = if outline { fill_source(r.key) } else { &sources[r.key as usize] }; + Arc::new(styled(src, tidy(r.path), outline)) + }) .collect() }; } diff --git a/crates/effects/src/group/tests.rs b/crates/effects/src/group/tests.rs index 2d1e34111b..8f9fef3902 100644 --- a/crates/effects/src/group/tests.rs +++ b/crates/effects/src/group/tests.rs @@ -1,6 +1,6 @@ use super::*; use vectorcraft_color::{BlendMode, Color, Paint}; -use vectorcraft_doc::{CharStyle, Effect, NodeId, TextObject}; +use vectorcraft_doc::{CharStyle, Effect, FillLayer, NodeId, TextObject}; use vectorcraft_geom::{Point, Rect, shapes}; /// Type tests need glyph outlines, which only the optional craft-fonts build input provides. @@ -120,9 +120,8 @@ fn divide_and_outline_draw_nothing_for_unpainted_members() { } } -/// With Remove Unpainted Artwork, Divide keeps the area of a compound shape whose own appearance -/// has a visible fill and leaves out the area of one without. Outline's open segments of the area -/// go either way. +/// With Remove Unpainted Artwork, Divide and Outline keep the area of a compound shape whose own +/// appearance has a visible fill and leave out the area of one without. #[test] fn remove_unpainted_keeps_a_filled_compound_shapes_area() { for effect in ["pathfinder.divide", "pathfinder.outline"] { @@ -133,8 +132,40 @@ fn remove_unpainted_keeps_a_filled_compound_shapes_area() { } g.appearance.effects.push(Effect { id: effect.into(), params: serde_json::json!({"removeUnpainted": true}), visible: true }); let out = pathfinder_children(None, &g, None).unwrap(); - let kept = filled && effect == "pathfinder.divide"; - assert_eq!(!out.is_empty(), kept, "{effect}, filled {filled}: {out:#?}"); + assert_eq!(!out.is_empty(), filled, "{effect}, filled {filled}: {out:#?}"); + } + } +} + +/// Outline strokes a compound shape's area in the shape's own fill (its top visible one that +/// paints), with Remove Unpainted Artwork on or off, and Divide leaves the area's pieces +/// unpainted for the shape's fill to paint. +#[test] +fn outline_strokes_a_compound_shapes_area_in_its_fill() { + let green = Paint::solid(Color::rgb(0.0, 1.0, 0.0)); + for (remove, covered) in [(false, false), (true, false), (false, true), (true, true)] { + for effect in ["pathfinder.divide", "pathfinder.outline"] { + let mut g = compound_shape(ShapeMode::Add); + if covered { + // A hidden fill and an unpainted fill above the green one. + let mut hidden = FillLayer::new(Paint::solid(Color::rgb(1.0, 0.0, 0.0))); + hidden.visible = false; + let mut a = (*g.appearance).clone(); + a.insert_item(a.items.len(), AppearanceItem::Fill(hidden)); + a.insert_item(a.items.len(), AppearanceItem::Fill(FillLayer::new(Paint::None))); + g.appearance = a.into(); + } + g.appearance.effects.push(Effect { id: effect.into(), params: serde_json::json!({"removeUnpainted": remove}), visible: true }); + let out = pathfinder_children(None, &g, None).unwrap(); + assert!(!out.is_empty(), "{effect}, remove {remove}"); + for n in &out { + if effect == "pathfinder.outline" { + assert_eq!(n.appearance.stroke_paint(), green, "{effect}, remove {remove}: {n:#?}"); + assert!(n.appearance.fill_paint().is_none(), "{effect}, remove {remove}: {n:#?}"); + } else { + assert!(n.appearance.items.is_empty(), "{effect}, remove {remove}: {n:#?}"); + } + } } } } diff --git a/docs/mcp.md b/docs/mcp.md index 05899cee14..f1d8c4df4e 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -4891,10 +4891,11 @@ whatever the options are then. Each Effect › Pathfinder effect (`pathfinder.add` … `pathfinder.softMix`, not Trap) keeps Pathfinder Options of its own in its params: `precision` (a number, 0.001–10 pt), `removeRedundantPoints` and `removeUnpainted` (true or false), which -mean what they mean for the panel's operations; the other operations ignore `removeUnpainted`, and Divide keeps every -piece when the group or compound shape has a visible fill of its own. `effect.apply` fills the ones `params` leave out -from the current Pathfinder Options, and the values join its journal entry. An effect saved -without them evaluates with precision 0.01 and both switches off, as before effects kept them. `effect.setParams +mean what they mean for the panel's operations; the other operations ignore `removeUnpainted`. With `removeUnpainted` +on, a compound shape's area counts as filled when the shape has a visible fill of its own, and Divide keeps every piece +when the group or compound shape has one. Outline strokes a compound shape's area in the shape's own fill. `effect.apply` +fills the ones `params` leave out from the current Pathfinder Options, and the values join its journal entry. An effect +saved without them evaluates with precision 0.01 and both switches off, as before effects kept them. `effect.setParams {index, params: {precision?, removeRedundantPoints?, removeUnpainted?}}` edits them as one undo step; values the effect already evaluates with record no undo step and return `{ids: []}`. A precision out of range, or a switch that isn't true or false, is refused with an error and nothing changes. In the app, a Pathfinder effect's name or a