Pathfinder: Outline strokes a compound shape's area in the shape's own fill

A live Outline effect on a compound shape stroked its area's segments
with no paint, and with removeUnpainted on it left them all out: the
area has no paint of its own, so the shape's fill was never read. The
area now takes the shape's top visible fill that paints, for Remove
Unpainted Artwork and for Outline's strokes. Divide's pieces stay
unpainted, so the shape's fill is not drawn twice.
This commit is contained in:
dotCooCoo
2026-11-15 10:48:06 -08:00
parent b3a7bf05a9
commit 54e2309973
3 changed files with 67 additions and 16 deletions
+25 -6
View File
@@ -66,7 +66,7 @@ pub const PATHFINDER_EFFECT_PRECISION: std::ops::RangeInclusive<f64> = 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<Ou
out.extend(source.iter().skip(art).cloned());
return Some(out);
}
// The group's own fill paints its members' geometry, a compound shape's area included
// ([`evaluate_container`]), so with one Remove Unpainted Artwork leaves out no Divide piece.
// Outline's pieces are open segments, which still go by their own fill.
// When the group has a visible fill of its own, that fill paints its members' geometry, a
// compound shape's area included ([`evaluate_container`]), so Remove Unpainted Artwork keeps
// every Divide piece. Outline's open segments still go by their source's fill.
let own_fill = has_visible_fill(group);
// A compound shape's area has no paint of its own: the shape's own appearance paints it. The
// shape's top painting fill is the area's fill for Remove Unpainted Artwork and for Outline's
// strokes, while Divide pieces stay unpainted so that the fill is not drawn twice.
let area_style = group.is_compound_shape().then(|| {
let items = group.appearance.items.iter().filter(|i| paints(i)).cloned().collect();
Node::path(group.id, PathData::default(), Appearance { items, ..Default::default() })
});
let style_of = |s: &Node| -> Option<Node> {
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<Arc<Node>> = 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<Ou
PathfinderOp::Outline => true,
_ => false,
};
let fill_sources: Vec<Option<Node>> = 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()
};
}
+37 -6
View File
@@ -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:#?}");
}
}
}
}
}
+5 -4
View File
@@ -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