Paths: painted boxes leave out lone anchors a fill does not paint

PathData::bounds now counts a subpath of one anchor, so three places
that measure what a path paints measured a point nothing paints:

- .ai import: the box arrowheads are placed against measured a visible
  fill by the path's geometric box. A filled path with a head and one
  stray anchor no longer fit the drawn look, so its style was not read.
  The fill now measures PathData::drawn_bounds(false).
- Type copies a Transform effect moves: the ink box of the glyph
  outlines now counts a contour of one anchor only where a round or
  projecting character stroke cap draws it as a dot.
- .ai envelopes: a piece of type outlines made only of contours of zero
  length kept them and counted their point. It now counts nothing, as
  the rule for such contours says.

Tests: a filled line with a head and a stray anchor still fits a look
of the line and its head; a dot-only piece beside a stroked square adds
nothing to the square's box. Both fail without the change.
This commit is contained in:
dotCooCoo committed 2026-11-27 16:44:42 -08:00
1 parent 9d54c7ccec
commit 5c709a1a64
3 files changed
+59 -5

No files matched your search

+6 -1
View File
@@ -619,7 +619,12 @@ fn moved_type(n: &Node, moves: &[serde_json::Value]) -> Option<Vec<Node>> {
}
let (_, all) = glyph_outlines(t);
let outline = PathData::from_bezpath(&all).transformed(t.xf);
let ink = outline.bounds()?;
// A contour of one anchor paints only as the dot of a round or projecting character stroke cap.
let dots = t
.runs
.iter()
.any(|r| r.style.appearance().painted_strokes().any(|s| matches!(s.cap, vectorcraft_doc::LineCap::Round | vectorcraft_doc::LineCap::Square)));
let ink = outline.drawn_bounds(dots)?;
let offsets = transform_offsets(moves, &outline)?;
if offsets.len() > MAX_TYPE_COPIES {
return None;
+27 -3
View File
@@ -234,12 +234,12 @@ fn painted_outlines(outlines: &Node) -> Option<Rect> {
}
/// `n` with its paths, and the paths in its groups and compound paths, without their subpaths of
/// one anchor (contours of zero length, which have no segment); a path with nothing else keeps
/// them. `None` when nothing changes.
/// one anchor (contours of zero length, which have no segment); a path with nothing else is left
/// empty, with no bounds. `None` when nothing changes.
fn without_zero_length_contours(n: &Node) -> Option<Node> {
if let Some(path) = n.path_data() {
let lone = |s: &vectorcraft_geom::SubPath| s.segment_count() == 0;
if !path.subpaths.iter().any(lone) || path.subpaths.iter().all(lone) {
if !path.subpaths.iter().any(lone) {
return None;
}
let mut kept = n.clone();
@@ -1405,6 +1405,30 @@ mod tests {
assert_eq!(painted_outlines(&outlines), Some(Rect::new(9.0, 9.0, 21.0, 21.0)));
}
/// A piece of type outlines that is only contours of zero length paints nothing either: a dot
/// piece with a round 2 point stroke beside a stroked square adds nothing to the square's box.
#[test]
fn a_piece_of_only_zero_length_contours_paints_nothing() {
let mut stroke = StrokeLayer::new(Paint::solid(Color::BLACK), 2.0);
(stroke.join, stroke.cap) = (LineJoin::Round, LineCap::Round);
let mut appearance = Appearance::default();
appearance.items.push(AppearanceItem::Fill(vectorcraft_doc::FillLayer::new(Paint::solid(Color::BLACK))));
appearance.items.push(AppearanceItem::Stroke(stroke));
let mut square = BezPath::new();
square.move_to((10.0, 10.0));
square.line_to((20.0, 10.0));
square.line_to((20.0, 20.0));
square.line_to((10.0, 20.0));
square.close_path();
let mut dot = BezPath::new();
dot.move_to((50.0, 50.0));
dot.line_to((50.0, 50.0));
dot.close_path();
let pieces = [(1, square), (2, dot)].map(|(id, bp)| Arc::new(Node::path(NodeId(id), PathData::from_bezpath(&bp), appearance.clone())));
let outlines = Node::group(NodeId(3), pieces.to_vec());
assert_eq!(painted_outlines(&outlines), Some(Rect::new(9.0, 9.0, 21.0, 21.0)));
}
/// Type that draws nothing adds no box next to other content in the boxes the import tries an
/// envelope with Distort Appearance mapped from, loose and in a group, as it adds none to the
/// contents' geometric box: a rectangle with a round 4 point stroke beside type of only spaces
+26 -1
View File
@@ -1488,7 +1488,7 @@ fn painted_bounds(object: &Node, appearance: &Appearance) -> Option<Rect> {
let mut out = None;
for item in &appearance.items {
let painted = match item {
AppearanceItem::Fill(f) if f.visible && !f.paint.is_none() => path.bounds(),
AppearanceItem::Fill(f) if f.visible && !f.paint.is_none() => path.drawn_bounds(false),
AppearanceItem::Stroke(s) if s.visible && !s.paint.is_none() => vectorcraft_effects::stroke::outline_region(&path, rule, s).bounds(),
_ => None,
};
@@ -1984,6 +1984,31 @@ mod tests {
Arc::new(Node::path(NodeId(id), shapes::rectangle(Rect::new(0.0, 0.0, 10.0, 10.0)), Appearance::basic(fill, Paint::None, 0.0)))
}
/// A lone anchor, which a fill does not paint, does not move what the fill paints when the
/// arrowheads are placed against the drawn look: a filled line with a head and a stray anchor
/// well outside it still fits a look of the line and its head alone.
#[test]
fn a_lone_anchor_does_not_move_the_painted_box_heads_are_placed_by() {
use vectorcraft_doc::{ArrowAlign, Arrowhead, CustomArrowhead, FillLayer, StrokeLayer};
use vectorcraft_geom::{Point, SubPath};
let wedge = PathData::single(SubPath::polyline(&[Point::new(0.0, 0.0), Point::new(3.0, 2.0), Point::new(3.0, -1.0)], true));
let mut stroke = StrokeLayer::new(Paint::solid(vectorcraft_doc::color::Color::BLACK), 2.0);
stroke.end_arrow = Some(Arrowhead::Custom(Arc::new(CustomArrowhead::new("Wedge".into(), wedge))));
stroke.arrow_align = ArrowAlign::Tip;
let mut appearance = Appearance::default();
appearance.items.push(AppearanceItem::Fill(FillLayer::new(Paint::solid(vectorcraft_doc::color::Color::BLACK))));
appearance.items.push(AppearanceItem::Stroke(stroke));
let line = SubPath::polyline(&[Point::new(0.0, 50.0), Point::new(100.0, 50.0)], false);
let plain = Node::path(NodeId(1), PathData::single(line.clone()), appearance.clone());
let want = painted_bounds(&plain, &appearance).unwrap();
let look =
Node::path(NodeId(2), shapes::rectangle(want), Appearance::basic(Paint::solid(vectorcraft_doc::color::Color::BLACK), Paint::None, 0.0));
let stray = SubPath::new(vec![vectorcraft_geom::Anchor::corner(Point::new(50.0, 200.0))], false);
let object = Node::path(NodeId(3), PathData::new(vec![line, stray]), appearance.clone());
let placed = heads_placed(&object, &look, appearance, Affine::IDENTITY).expect("the heads fit the look");
assert!(placed.items.iter().any(|i| matches!(i, AppearanceItem::Stroke(s) if s.arrow_align == ArrowAlign::Tip)));
}
/// The outline check works from one budget for the object: a look of the outline drawn twice
/// (a fill and a stroke) matches, one drawn thousands of times gives up and keeps the drawn
/// look instead of comparing every copy.