From 57946bfbd72e7ae05d6e74cecea5586bf9e39e28 Mon Sep 17 00:00:00 2001 From: Don Omondi <282319807+mockydevs@users.noreply.github.com> Date: Sat, 7 Nov 2026 01:56:25 -0500 Subject: [PATCH 1/5] EPS/.ai editing data: Zig Zag on paths stays live where it draws the drawn look's outline Zig Zag in a path's or compound path's art style is kept live when the outline VectorCraft's Zig Zag draws lies within 0.25 pt of every outline of the object's drawn look, both ways. Otherwise the drawn look stays, as before; type keeps taking Zig Zag as it did. --- crates/eps/src/import/ai/read/ops.rs | 89 ++++++++++++++++++++++++- crates/eps/src/import/ai/style.rs | 8 ++- crates/eps/src/import/ai/style/tests.rs | 3 +- crates/eps/src/import/ai/tests.rs | 47 +++++++++++++ docs/file-format-parity.md | 3 +- 5 files changed, 144 insertions(+), 6 deletions(-) diff --git a/crates/eps/src/import/ai/read/ops.rs b/crates/eps/src/import/ai/read/ops.rs index 9535aa062f..99ad5d23ff 100644 --- a/crates/eps/src/import/ai/read/ops.rs +++ b/crates/eps/src/import/ai/read/ops.rs @@ -1094,7 +1094,94 @@ fn styled(object: &Node, look: &Node, st: &crate::import::ai::style::ArtStyle, p } else { object.appearance.contents_index }; - Some(Appearance { items, effects: st.effects.clone(), contents_index }) + let appearance = Appearance { items, effects: st.effects.clone(), contents_index }; + // Zig Zag's ridges are placed by VectorCraft's own rule: on objects other than type it is kept + // only where they draw the outline the drawn look has. + if !slot && st.effects.iter().any(|e| e.id == "distort.zigZag") && !draws_look_outline(object, &appearance, look) { + return None; + } + Some(appearance) +} + +/// How far, in points, an outline drawn with a reshaping effect may lie from its drawn look's +/// ([`draws_look_outline`]): the look's coordinates are written to a few decimals. +const OUTLINE_TOLERANCE: f64 = 0.25; + +/// Most points compared, one outline's flattened points times the other's segments. +const MAX_OUTLINE_PAIRS: usize = 4_000_000; + +/// Does path or compound path `object` with `appearance`'s effects draw every outline of its drawn look +/// `look`, as `look` draws its own (each within [`OUTLINE_TOLERANCE`] of the other)? `false` for +/// anything else: a look holding other than paths, outlines too detailed to compare. +fn draws_look_outline(object: &Node, appearance: &Appearance, look: &Node) -> bool { + fn leaves(n: &Node, out: &mut Vec, depth: usize) -> bool { + match &n.kind { + NodeKind::Path { path, .. } => { + out.push(path.clone()); + true + } + NodeKind::Compound { children, .. } => { + out.push(vectorcraft_geom::PathData::new( + children.iter().filter_map(|c| c.path_data()).flat_map(|p| p.subpaths.iter().cloned()).collect(), + )); + true + } + NodeKind::Group { clip: false, .. } if depth < MAX_DEPTH => n.children().into_iter().flatten().all(|c| leaves(c, out, depth + 1)), + _ => false, + } + } + /// The segments of `paths` flattened, at most `max` of them. + fn segments(paths: &[vectorcraft_geom::PathData], max: usize) -> Option> { + let mut out = vec![]; + let (mut start, mut last) = (None, None); + let mut over = false; + for p in paths { + vectorcraft_geom::flatten(p.to_bezpath(), OUTLINE_TOLERANCE / 10.0, |el| { + let mut add = |a: kurbo::Point, b: kurbo::Point| { + if out.len() < max { + out.push(kurbo::Line::new(a, b)); + } else { + over = true; + } + }; + match el { + kurbo::PathEl::MoveTo(q) => (start, last) = (Some(q), Some(q)), + kurbo::PathEl::LineTo(q) => { + if let Some(l) = last { + add(l, q); + } + last = Some(q); + } + kurbo::PathEl::ClosePath => { + if let (Some(l), Some(s)) = (last, start) { + add(l, s); + } + last = start; + } + _ => {} + } + }); + } + (!over && !out.is_empty()).then_some(out) + } + /// Does every end of segments `a` lie within the tolerance of segments `b`? + fn near(a: &[kurbo::Line], b: &[kurbo::Line]) -> bool { + use kurbo::ParamCurveNearest; + a.iter().all(|s| b.iter().any(|t| t.nearest(s.p0, 1e-6).distance_sq <= OUTLINE_TOLERANCE * OUTLINE_TOLERANCE)) + } + let (mut ours, mut theirs) = (vec![], vec![]); + if !matches!(object.kind, NodeKind::Path { .. } | NodeKind::Compound { .. }) || !leaves(object, &mut ours, 0) || !leaves(look, &mut theirs, 0) { + return false; + } + // The object's outline reshaped as it is drawn: its effects from its own bounds. + for path in &mut ours { + let bounds = kurbo::Shape::bounding_box(&path.to_bezpath()); + *path = vectorcraft_effects::apply_geometry(&appearance.effects, path, bounds); + } + let max = MAX_OUTLINE_PAIRS.isqrt(); + let Some(ours) = segments(&ours, max) else { return false }; + // Each of the look's outlines (a fill and a stroke draw the same one) is the object's. + theirs.iter().all(|t| segments(std::slice::from_ref(t), max).is_some_and(|t| near(&t, &ours) && near(&ours, &t))) } /// A graphic style's appearance from art style `st`, on no object: `None` when the style isn't one diff --git a/crates/eps/src/import/ai/style.rs b/crates/eps/src/import/ai/style.rs index 9699e3ac6a..fa43984a04 100644 --- a/crates/eps/src/import/ai/style.rs +++ b/crates/eps/src/import/ai/style.rs @@ -1361,8 +1361,9 @@ impl Builder<'_> { /// Is `e`, on the whole object, an effect any object is read with? Of the Distort & Transform /// effects: Transform without copies (Random is never read), Twist, a Tweak that moves nothing, -/// Pucker & Bloat at 0, and Free Distort when its corners make a parallelogram (an affine map). -/// Zig Zag is left to type. Which objects Transform, Twist and Free Distort are read on is +/// Pucker & Bloat at 0, Free Distort when its corners make a parallelogram (an affine map), and Zig +/// Zag (on objects other than type only where it draws its drawn look's outline: `read::ops`' +/// `styled`). Which objects Transform, Twist and Free Distort are read on is /// `read::ops`' `moves_with`. fn any_object_takes(e: &Effect) -> bool { match e.id.as_str() { @@ -1379,7 +1380,8 @@ fn any_object_takes(e: &Effect) -> bool { | "path.outlineObject" | "path.outlineStroke" | "distort.twist" - | "distort.tweak" => true, + | "distort.tweak" + | "distort.zigZag" => true, // Copies are drawn as one path, its fills under all its strokes, where the file paints each // copy's fill and stroke in turn. "distort.transform" => e.params["copies"].as_i64() == Some(0), diff --git a/crates/eps/src/import/ai/style/tests.rs b/crates/eps/src/import/ai/style/tests.rs index bdb9a3d6e3..fa6eca9f4c 100644 --- a/crates/eps/src/import/ai/style/tests.rs +++ b/crates/eps/src/import/ai/style/tests.rs @@ -955,7 +955,8 @@ fn any_object_takes_the_distort_effects_that_draw_as_its_drawn_look() { assert!(simple("Adobe Free Distort", &corners(src, [[0.2, 0.0], [1.2, 0.0], [0.0, -1.0], [1.0, -1.0]]))); assert!(!simple("Adobe Free Distort", &corners(src, [[0.2, 0.0], [1.2, 0.1], [0.0, -1.0], [1.0, -1.0]]))); assert!(!simple("Adobe Punk and Bloat", "-35 /Real (d_factor) ,\n")); - assert!(!simple("Adobe Zigzag", "")); + // Zig Zag: objects other than type check it against their drawn look (`read::ops`). + assert!(simple("Adobe Zigzag", "")); assert!(!simple("Adobe Transform", &format!("1 /Int (numCopies) ,\n{SWITCHES}"))); // With another effect, only type takes it. let chain = [basic("Adobe Twirl", "45 /Real (angle) ,\n"), basic("Adobe Offset Path", "4 /Real (ofst) ,\n0 /Int (jntp) ,\n4 /Real (mlim) ,\n")]; diff --git a/crates/eps/src/import/ai/tests.rs b/crates/eps/src/import/ai/tests.rs index 36a93a690d..6ed474caa2 100644 --- a/crates/eps/src/import/ai/tests.rs +++ b/crates/eps/src/import/ai/tests.rs @@ -5793,6 +5793,53 @@ fn an_object_with_a_distort_effect_drawn_another_way_keeps_its_drawn_look() { } } +#[test] +fn a_path_with_zig_zag_comes_in_as_itself_where_its_look_has_that_outline() { + // GUARDS: Zig Zag on a path came in as its drawn look even where the live effect draws the same outline. + let keys = "3 /Real (amount) ,\n1 /Real (absoluteness) ,\n2 /Real (ridges) ,\n0 /Real (roundness) ,\n"; + let zig = vectorcraft_doc::Effect { + id: "distort.zigZag".into(), + params: serde_json::json!({"size": 3.0, "relative": false, "ridges": 2, "points": "corner"}), + visible: true, + }; + // The square as the document has it (y up in the file, down in the document). + let plain = read_ok(&layer(&format!("{RED}{}f\n", rect_path(20.0, 20.0, 60.0, 50.0)))); + let square = art(&plain.doc)[0].path_data().unwrap().clone(); + let to_file = |p: Point| { + let start = square.subpaths[0].anchors[0].p; + Point::new(p.x - start.x + 20.0, start.y - p.y + 20.0) + }; + let outline = vectorcraft_effects::apply_geometry(&[zig], &square, square.bounds().unwrap()); + // The look: the outline the effect draws, as straight segments. + let ops = |shift: f64| -> String { + let mut out = String::new(); + for sp in &outline.subpaths { + for (i, a) in sp.anchors.iter().enumerate() { + let p = to_file(a.p); + out.push_str(&format!("{:.4} {:.4} {}\n", p.x + shift, p.y, if i == 0 { "m" } else { "L" })); + } + } + out + }; + let hidden_rect = rect_path(20.0, 20.0, 60.0, 50.0).replace('\n', "\n%_"); + let object = |look: &str| format!("0 Ae\nu\n0 0 0 0 0 0 1 Xa\n{look}f\nU\n%_{hidden_rect}f\n1 (Bent) XW\n"); + let r = read_ok(&format!("{}{}", distort_styles("Adobe Zigzag", keys, BLUE_FILL), layer(&object(&ops(0.0))))); + assert!(!r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings); + let a = art(&r.doc); + assert_eq!(a.len(), 1, "{a:#?}"); + assert!(matches!(a[0].kind, NodeKind::Path { .. }), "the object, not its look: {a:#?}"); + let e = &a[0].appearance.effects; + assert_eq!(e.len(), 1, "{e:?}"); + assert_eq!( + (e[0].id.as_str(), &e[0].params), + ("distort.zigZag", &serde_json::json!({"size": 3.0, "relative": false, "ridges": 2, "points": "corner"})) + ); + // A look whose ridges lie elsewhere (here 1 pt to the right) keeps the drawn look. + let r = read_ok(&format!("{}{}", distort_styles("Adobe Zigzag", keys, BLUE_FILL), layer(&object(&ops(1.0))))); + assert!(r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings); + assert!(matches!(art(&r.doc)[0].kind, NodeKind::Group { .. })); +} + /// The gradient `G`, white to black, defined for a document. const GRADIENT_G: &str = "%AI5_BeginGradient: (G)\n(G) 0 2 Bd\n[\n%_1 0 50 0 Bs\n%_0 0 50 100 Bs\nBD\n%AI5_EndGradient\n"; diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index f60d46f622..2ccd69d56e 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -1,6 +1,6 @@ # File format parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-06 · **Change:** minor (EPS and `.ai` editing data: a transparency set inside a clipping group stays after its `Q`; SVG import: filter and mask regions clip, #5876, #5875; SVG import: Gaussian blurs keep `color-interpolation-filters`, #5877; PDF and `.ai` export: objects' URLs as links, #5785; SVG import: `color-interpolation="linearRGB"` gradients, #5878; `.ai` import: paths with a Calligraphic brush open brushed, #372) · **Target:** Adobe Illustrator 2026 (30.x) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-07 · **Change:** minor (EPS and `.ai` editing data: Zig Zag on paths stays live where it draws its drawn look's outline) Every format Illustrator opens, places, saves or exports, against VectorCraft's format table (`FORMATS`, `OPEN_EXTS`, `PLACE_EXTS` in `crates/engine/src/cmd/fileio/formats.rs`). Illustrator's list comes from its public @@ -212,6 +212,7 @@ the app's own editing copy of a file (an EPS after its `%%EOF`, a `.ai`'s `AIPri | Date | Change | Summary | |---|---|---| +| 2026-11-07 | minor | EPS and `.ai` editing data: Zig Zag in a path's art style (Size, Relative or Absolute, Ridges per segment, Smooth or Corner points) stays live where VectorCraft's Zig Zag draws the outline the drawn look has, each within 0.25 pt of the other; where it doesn't, the drawn look stays, as before. Type keeps taking Zig Zag as it did. Checked on a user's Illustrator EPS (used locally, not committed): its 3 Zig Zag circles (Smooth and Corner, 10 and 13 ridges) come in live, within 0.03 pt of their drawn looks, and the render is unchanged. Scores and estimates unchanged. | | 2026-11-06 | minor | EPS and `.ai` editing data: `Q` restores the painting state but not the transparency (`Xy`), which the writer only sets when the next object's differs from the last one written. A Screen glow followed by a clipping group set back to Normal no longer leaves the type after the group in Screen: two users' Illustrator 26.5 and 30 EPS posters (used locally, not committed) now show their gold heading and crescent, and both open from their layers (2.5% and 2.7% from the page before, under the limit after). Scores and estimates unchanged. | | 2026-11-06 | minor | EPS and `.ai` editing data: a blend whose spine was never edited, written with its keys and no spine part, comes in as a live blend along the straight lines between its keys' centres (in its record's order) instead of as its drawn steps. Checked on six users' Illustrator EPS files (used locally, not committed): every blend in four of them now comes in live, their renders unchanged; two still have blends the reader can't match to their drawn steps. Scores and estimates unchanged. | | 2026-11-06 | minor | EPS and `.ai` editing data: the art styles are found before the art is read, so objects in symbols defined ahead of `%AI9_BeginArtStyles` (as Illustrator 24 writes it) come in as themselves with their style instead of their drawn look. Checked on two users' EPS files (used locally, not committed): one's Symbols panel gains live Feather and Round Corners, its drawn-look count drops from 5 to 2, and both render unchanged; own-fixture test in `import::ai::tests`; scores and hours unchanged | From bafa1868daa4f60959308420db575a568e41891d Mon Sep 17 00:00:00 2001 From: Don Omondi <282319807+mockydevs@users.noreply.github.com> Date: Sat, 7 Nov 2026 13:21:55 -0500 Subject: [PATCH 2/5] EPS/.ai editing data: a live outline's check compares both ends of each segment The check that a reshaping effect draws its look's outline compared only the start of each segment, so the last point of an open outline was never compared and a look ending elsewhere still kept the effect live. Both ends are now compared. --- crates/eps/src/import/ai/read/ops.rs | 6 ++++-- crates/eps/src/import/ai/tests.rs | 27 ++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/crates/eps/src/import/ai/read/ops.rs b/crates/eps/src/import/ai/read/ops.rs index 99ad5d23ff..b4e9142547 100644 --- a/crates/eps/src/import/ai/read/ops.rs +++ b/crates/eps/src/import/ai/read/ops.rs @@ -1164,10 +1164,12 @@ fn draws_look_outline(object: &Node, appearance: &Appearance, look: &Node) -> bo } (!over && !out.is_empty()).then_some(out) } - /// Does every end of segments `a` lie within the tolerance of segments `b`? + /// Does every end of segments `a` lie within the tolerance of segments `b`? Both ends: the last + /// point of an open outline starts no segment. fn near(a: &[kurbo::Line], b: &[kurbo::Line]) -> bool { use kurbo::ParamCurveNearest; - a.iter().all(|s| b.iter().any(|t| t.nearest(s.p0, 1e-6).distance_sq <= OUTLINE_TOLERANCE * OUTLINE_TOLERANCE)) + let close = |p: kurbo::Point| b.iter().any(|t| t.nearest(p, 1e-6).distance_sq <= OUTLINE_TOLERANCE * OUTLINE_TOLERANCE); + a.iter().all(|s| close(s.p0) && close(s.p1)) } let (mut ours, mut theirs) = (vec![], vec![]); if !matches!(object.kind, NodeKind::Path { .. } | NodeKind::Compound { .. }) || !leaves(object, &mut ours, 0) || !leaves(look, &mut theirs, 0) { diff --git a/crates/eps/src/import/ai/tests.rs b/crates/eps/src/import/ai/tests.rs index 6ed474caa2..55949bfbea 100644 --- a/crates/eps/src/import/ai/tests.rs +++ b/crates/eps/src/import/ai/tests.rs @@ -5809,7 +5809,7 @@ fn a_path_with_zig_zag_comes_in_as_itself_where_its_look_has_that_outline() { let start = square.subpaths[0].anchors[0].p; Point::new(p.x - start.x + 20.0, start.y - p.y + 20.0) }; - let outline = vectorcraft_effects::apply_geometry(&[zig], &square, square.bounds().unwrap()); + let outline = vectorcraft_effects::apply_geometry(std::slice::from_ref(&zig), &square, square.bounds().unwrap()); // The look: the outline the effect draws, as straight segments. let ops = |shift: f64| -> String { let mut out = String::new(); @@ -5838,6 +5838,31 @@ fn a_path_with_zig_zag_comes_in_as_itself_where_its_look_has_that_outline() { let r = read_ok(&format!("{}{}", distort_styles("Adobe Zigzag", keys, BLUE_FILL), layer(&object(&ops(1.0))))); assert!(r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings); assert!(matches!(art(&r.doc)[0].kind, NodeKind::Group { .. })); + // An open path (filled without closing it, `F`): its look's outline matches, and a look whose + // last point lies 3 pt away from where the effect ends it keeps the drawn look. + let open_path = "20 20 m\n60 20 L\n60 50 L\n"; + let plain = read_ok(&layer(&format!("{RED}{open_path}F\n"))); + let open = art(&plain.doc)[0].path_data().unwrap().clone(); + assert!(!open.subpaths[0].closed); + let start = open.subpaths[0].anchors[0].p; + let outline = vectorcraft_effects::apply_geometry(std::slice::from_ref(&zig), &open, open.bounds().unwrap()); + let ops = |last_shift: f64| -> String { + let mut out = String::new(); + for sp in &outline.subpaths { + for (i, a) in sp.anchors.iter().enumerate() { + let shift = if i + 1 == sp.anchors.len() { last_shift } else { 0.0 }; + let p = Point::new(a.p.x - start.x + 20.0 + shift, start.y - a.p.y + 20.0); + out.push_str(&format!("{:.4} {:.4} {}\n", p.x, p.y, if i == 0 { "m" } else { "L" })); + } + } + out + }; + let hidden_open = open_path.replace('\n', "\n%_"); + let object = |look: &str| format!("0 Ae\nu\n0 0 0 0 0 0 1 Xa\n{look}F\nU\n%_{hidden_open}F\n1 (Bent) XW\n"); + let r = read_ok(&format!("{}{}", distort_styles("Adobe Zigzag", keys, BLUE_FILL), layer(&object(&ops(0.0))))); + assert!(!r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings); + let r = read_ok(&format!("{}{}", distort_styles("Adobe Zigzag", keys, BLUE_FILL), layer(&object(&ops(3.0))))); + assert!(r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings); } /// The gradient `G`, white to black, defined for a document. From 5520a254b984c6e5c98a00d5052b0efd935e2211 Mon Sep 17 00:00:00 2001 From: Don Omondi <282319807+mockydevs@users.noreply.github.com> Date: Sat, 7 Nov 2026 15:02:04 -0500 Subject: [PATCH 3/5] EPS/.ai editing data: a live outline's check samples inside each segment Two outlines can share their vertices and join them differently: ends alone matched a bowtie to the square of its look. Each segment is now checked at points at most the tolerance apart, within the same budget of points compared. --- crates/eps/src/import/ai/read/ops.rs | 20 ++++++++++++++++---- crates/eps/src/import/ai/tests.rs | 7 +++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/eps/src/import/ai/read/ops.rs b/crates/eps/src/import/ai/read/ops.rs index b4e9142547..5a73729b88 100644 --- a/crates/eps/src/import/ai/read/ops.rs +++ b/crates/eps/src/import/ai/read/ops.rs @@ -1164,12 +1164,24 @@ fn draws_look_outline(object: &Node, appearance: &Appearance, look: &Node) -> bo } (!over && !out.is_empty()).then_some(out) } - /// Does every end of segments `a` lie within the tolerance of segments `b`? Both ends: the last - /// point of an open outline starts no segment. + /// Does every point of segments `a` lie within the tolerance of segments `b`? Each segment is + /// checked at both ends (the last point of an open outline starts no segment) and at points + /// at most the tolerance apart between them (two outlines can share their vertices and join + /// them differently). `false` past [`MAX_OUTLINE_PAIRS`] points compared. fn near(a: &[kurbo::Line], b: &[kurbo::Line]) -> bool { - use kurbo::ParamCurveNearest; + use kurbo::{ParamCurve, ParamCurveArclen, ParamCurveNearest}; let close = |p: kurbo::Point| b.iter().any(|t| t.nearest(p, 1e-6).distance_sq <= OUTLINE_TOLERANCE * OUTLINE_TOLERANCE); - a.iter().all(|s| close(s.p0) && close(s.p1)) + let mut budget = MAX_OUTLINE_PAIRS; + for s in a { + let steps = (s.arclen(1e-6) / OUTLINE_TOLERANCE).ceil(); + let steps = if steps.is_finite() && steps >= 1.0 { steps as usize } else { 1 }; + let Some(left) = budget.checked_sub(steps.saturating_add(1).saturating_mul(b.len())) else { return false }; + budget = left; + if !(0..=steps).all(|k| close(s.eval(k as f64 / steps as f64))) { + return false; + } + } + true } let (mut ours, mut theirs) = (vec![], vec![]); if !matches!(object.kind, NodeKind::Path { .. } | NodeKind::Compound { .. }) || !leaves(object, &mut ours, 0) || !leaves(look, &mut theirs, 0) { diff --git a/crates/eps/src/import/ai/tests.rs b/crates/eps/src/import/ai/tests.rs index 55949bfbea..316d35c12d 100644 --- a/crates/eps/src/import/ai/tests.rs +++ b/crates/eps/src/import/ai/tests.rs @@ -5863,6 +5863,13 @@ fn a_path_with_zig_zag_comes_in_as_itself_where_its_look_has_that_outline() { assert!(!r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings); let r = read_ok(&format!("{}{}", distort_styles("Adobe Zigzag", keys, BLUE_FILL), layer(&object(&ops(3.0))))); assert!(r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings); + // A Zig Zag of no size on an open path through the corners of its look's square, joined + // across it: the vertices match, the segments between them don't, so the drawn look stays. + let flat = "0 /Real (amount) ,\n1 /Real (absoluteness) ,\n0 /Real (ridges) ,\n0 /Real (roundness) ,\n"; + let bowtie = "%_20 20 m\n%_60 50 L\n%_60 20 L\n%_20 50 L\n%_F\n"; + let crossed = format!("0 Ae\nu\n0 0 0 0 0 0 1 Xa\n{}f\nU\n{bowtie}1 (Bent) XW\n", rect_path(20.0, 20.0, 60.0, 50.0)); + let r = read_ok(&format!("{}{}", distort_styles("Adobe Zigzag", flat, BLUE_FILL), layer(&crossed))); + assert!(r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings); } /// The gradient `G`, white to black, defined for a document. From 79dba05dc6b4313ba4ad9f4336aa5ced8c096f1a Mon Sep 17 00:00:00 2001 From: Don Omondi <282319807+mockydevs@users.noreply.github.com> Date: Sun, 8 Nov 2026 05:16:01 -0500 Subject: [PATCH 4/5] EPS/.ai editing data: Zig Zag's outline check works from one budget per object The point-to-segment distances for all of a look's outlines now come from one budget for the object, so a look with many outlines can't multiply the work, and boxes further apart than the tolerance are turned down before any points are compared. Tests: a look drawn thousands of times gives up, and a look worked out by hand (not by the effect) matches while its mirror doesn't. --- crates/eps/src/import/ai/read/ops.rs | 51 ++++++++++++++++++++++++---- crates/eps/src/import/ai/tests.rs | 11 ++++++ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/crates/eps/src/import/ai/read/ops.rs b/crates/eps/src/import/ai/read/ops.rs index 5a73729b88..f052b16114 100644 --- a/crates/eps/src/import/ai/read/ops.rs +++ b/crates/eps/src/import/ai/read/ops.rs @@ -1107,7 +1107,7 @@ fn styled(object: &Node, look: &Node, st: &crate::import::ai::style::ArtStyle, p /// ([`draws_look_outline`]): the look's coordinates are written to a few decimals. const OUTLINE_TOLERANCE: f64 = 0.25; -/// Most points compared, one outline's flattened points times the other's segments. +/// Most point-to-segment distances worked out for one object, over all its look's outlines. const MAX_OUTLINE_PAIRS: usize = 4_000_000; /// Does path or compound path `object` with `appearance`'s effects draw every outline of its drawn look @@ -1167,22 +1167,27 @@ fn draws_look_outline(object: &Node, appearance: &Appearance, look: &Node) -> bo /// Does every point of segments `a` lie within the tolerance of segments `b`? Each segment is /// checked at both ends (the last point of an open outline starts no segment) and at points /// at most the tolerance apart between them (two outlines can share their vertices and join - /// them differently). `false` past [`MAX_OUTLINE_PAIRS`] points compared. - fn near(a: &[kurbo::Line], b: &[kurbo::Line]) -> bool { + /// them differently). Each point's distance to each segment of `b` (a projection onto it) is + /// taken from `budget`: `false` once that runs out. + fn near(a: &[kurbo::Line], b: &[kurbo::Line], budget: &mut usize) -> bool { use kurbo::{ParamCurve, ParamCurveArclen, ParamCurveNearest}; let close = |p: kurbo::Point| b.iter().any(|t| t.nearest(p, 1e-6).distance_sq <= OUTLINE_TOLERANCE * OUTLINE_TOLERANCE); - let mut budget = MAX_OUTLINE_PAIRS; for s in a { let steps = (s.arclen(1e-6) / OUTLINE_TOLERANCE).ceil(); let steps = if steps.is_finite() && steps >= 1.0 { steps as usize } else { 1 }; let Some(left) = budget.checked_sub(steps.saturating_add(1).saturating_mul(b.len())) else { return false }; - budget = left; + *budget = left; if !(0..=steps).all(|k| close(s.eval(k as f64 / steps as f64))) { return false; } } true } + /// The box round segments `lines` (`None` without any). + fn bounds(lines: &[kurbo::Line]) -> Option { + let first = lines.first()?.p0; + Some(lines.iter().fold(kurbo::Rect::from_points(first, first), |r, l| r.union_pt(l.p0).union_pt(l.p1))) + } let (mut ours, mut theirs) = (vec![], vec![]); if !matches!(object.kind, NodeKind::Path { .. } | NodeKind::Compound { .. }) || !leaves(object, &mut ours, 0) || !leaves(look, &mut theirs, 0) { return false; @@ -1194,8 +1199,18 @@ fn draws_look_outline(object: &Node, appearance: &Appearance, look: &Node) -> bo } let max = MAX_OUTLINE_PAIRS.isqrt(); let Some(ours) = segments(&ours, max) else { return false }; + let Some(ours_box) = bounds(&ours) else { return false }; + // Two outlines each within the tolerance of the other have boxes as close: the boxes are + // compared first, then the points, from one budget for the object. + let boxed = |t: &[kurbo::Line]| { + let Some(r) = bounds(t) else { return false }; + [r.x0 - ours_box.x0, r.y0 - ours_box.y0, r.x1 - ours_box.x1, r.y1 - ours_box.y1].iter().all(|d| d.abs() <= OUTLINE_TOLERANCE) + }; + let mut budget = MAX_OUTLINE_PAIRS; // Each of the look's outlines (a fill and a stroke draw the same one) is the object's. - theirs.iter().all(|t| segments(std::slice::from_ref(t), max).is_some_and(|t| near(&t, &ours) && near(&ours, &t))) + theirs + .iter() + .all(|t| segments(std::slice::from_ref(t), max).is_some_and(|t| boxed(&t) && near(&t, &ours, &mut budget) && near(&ours, &t, &mut budget))) } /// A graphic style's appearance from art style `st`, on no object: `None` when the style isn't one @@ -1364,6 +1379,30 @@ 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))) } + /// 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. + #[test] + fn the_outline_check_has_one_budget_for_the_object() { + let zig = vectorcraft_doc::Effect { + id: "distort.zigZag".into(), + params: serde_json::json!({"size": 3.0, "relative": false, "ridges": 4, "points": "corner"}), + visible: true, + }; + let path = shapes::rectangle(Rect::new(0.0, 0.0, 100.0, 60.0)); + let appearance = Appearance { effects: vec![zig.clone()], ..Appearance::basic(Paint::None, Paint::None, 0.0) }; + let object = Node::path(NodeId(1), path.clone(), appearance.clone()); + let outline = vectorcraft_effects::apply_geometry(std::slice::from_ref(&zig), &path, Rect::new(0.0, 0.0, 100.0, 60.0)); + let look = |copies: u64| { + let drawn = (0..copies).map(|i| Arc::new(Node::path(NodeId(10 + i), outline.clone(), Appearance::default()))).collect(); + Node::group(NodeId(2), drawn) + }; + assert!(draws_look_outline(&object, &appearance, &look(2))); + let started = std::time::Instant::now(); + assert!(!draws_look_outline(&object, &appearance, &look(5_000))); + assert!(started.elapsed() < std::time::Duration::from_secs(5), "{:?}", started.elapsed()); + } + /// An image draws no stroke, so an image with a brush in its art style keeps its drawn look. #[test] fn an_image_with_a_brush_keeps_its_drawn_look() { diff --git a/crates/eps/src/import/ai/tests.rs b/crates/eps/src/import/ai/tests.rs index 316d35c12d..c4c2bd785e 100644 --- a/crates/eps/src/import/ai/tests.rs +++ b/crates/eps/src/import/ai/tests.rs @@ -5870,6 +5870,17 @@ fn a_path_with_zig_zag_comes_in_as_itself_where_its_look_has_that_outline() { let crossed = format!("0 Ae\nu\n0 0 0 0 0 0 1 Xa\n{}f\nU\n{bowtie}1 (Bent) XW\n", rect_path(20.0, 20.0, 60.0, 50.0)); let r = read_ok(&format!("{}{}", distort_styles("Adobe Zigzag", flat, BLUE_FILL), layer(&crossed))); assert!(r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings); + // A look worked out by hand rather than by the effect: Zig Zag of 3 pt with one ridge per + // segment and corner points, on a line from (20, 20) to (60, 20), puts the line's ends 3 pt up + // the page and its middle 3 pt down. The same look mirrored keeps the drawn look. + let one = "3 /Real (amount) ,\n1 /Real (absoluteness) ,\n1 /Real (ridges) ,\n0 /Real (roundness) ,\n"; + let line = "20 20 m\n60 20 L\n".replace('\n', "\n%_"); + let object = |look: &str| format!("0 Ae\nu\n0 0 0 0 0 0 1 Xa\n{look}F\nU\n%_{line}F\n1 (Bent) XW\n"); + let r = read_ok(&format!("{}{}", distort_styles("Adobe Zigzag", one, BLUE_FILL), layer(&object("20 23 m\n40 17 L\n60 23 L\n")))); + assert!(!r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings); + assert!(matches!(art(&r.doc)[0].kind, NodeKind::Path { .. }), "{:#?}", art(&r.doc)); + let r = read_ok(&format!("{}{}", distort_styles("Adobe Zigzag", one, BLUE_FILL), layer(&object("20 17 m\n40 23 L\n60 17 L\n")))); + assert!(r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings); } /// The gradient `G`, white to black, defined for a document. From a90779740c315abd4819113f80a2eb9cc132c18f Mon Sep 17 00:00:00 2001 From: Don Omondi <282319807+mockydevs@users.noreply.github.com> Date: Sun, 8 Nov 2026 07:21:13 -0500 Subject: [PATCH 5/5] EPS/.ai editing data: Zig Zag's outline check holds between the points it checks --- crates/eps/src/import/ai/read/ops.rs | 47 +++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/crates/eps/src/import/ai/read/ops.rs b/crates/eps/src/import/ai/read/ops.rs index f052b16114..19136ab010 100644 --- a/crates/eps/src/import/ai/read/ops.rs +++ b/crates/eps/src/import/ai/read/ops.rs @@ -1107,6 +1107,17 @@ fn styled(object: &Node, look: &Node, st: &crate::import::ai::style::ArtStyle, p /// ([`draws_look_outline`]): the look's coordinates are written to a few decimals. const OUTLINE_TOLERANCE: f64 = 0.25; +/// How far, in points, a flattened outline in [`draws_look_outline`] may lie from its curves. +const OUTLINE_FLATNESS: f64 = OUTLINE_TOLERANCE / 10.0; + +/// How far apart, in points, [`draws_look_outline`] checks points along each flattened segment. +const OUTLINE_SPACING: f64 = OUTLINE_TOLERANCE / 2.0; + +/// How close, in points, each checked point must lie to the other flattened outline: every point +/// between two checked ones is within half the spacing of one, and both outlines are within the +/// flatness of their curves, so the curves are then within [`OUTLINE_TOLERANCE`] of each other. +const OUTLINE_POINT_LIMIT: f64 = OUTLINE_TOLERANCE - 2.0 * OUTLINE_FLATNESS - OUTLINE_SPACING / 2.0; + /// Most point-to-segment distances worked out for one object, over all its look's outlines. const MAX_OUTLINE_PAIRS: usize = 4_000_000; @@ -1136,7 +1147,7 @@ fn draws_look_outline(object: &Node, appearance: &Appearance, look: &Node) -> bo let (mut start, mut last) = (None, None); let mut over = false; for p in paths { - vectorcraft_geom::flatten(p.to_bezpath(), OUTLINE_TOLERANCE / 10.0, |el| { + vectorcraft_geom::flatten(p.to_bezpath(), OUTLINE_FLATNESS, |el| { let mut add = |a: kurbo::Point, b: kurbo::Point| { if out.len() < max { out.push(kurbo::Line::new(a, b)); @@ -1164,16 +1175,16 @@ fn draws_look_outline(object: &Node, appearance: &Appearance, look: &Node) -> bo } (!over && !out.is_empty()).then_some(out) } - /// Does every point of segments `a` lie within the tolerance of segments `b`? Each segment is - /// checked at both ends (the last point of an open outline starts no segment) and at points - /// at most the tolerance apart between them (two outlines can share their vertices and join - /// them differently). Each point's distance to each segment of `b` (a projection onto it) is - /// taken from `budget`: `false` once that runs out. + /// Does every point of segments `a` lie close enough to segments `b` ([`OUTLINE_POINT_LIMIT`])? + /// Each segment is checked at both ends (the last point of an open outline starts no segment) + /// and at points at most [`OUTLINE_SPACING`] apart between them (two outlines can share their + /// vertices and join them differently). Each point's distance to each segment of `b` (a + /// projection onto it) is taken from `budget`: `false` once that runs out. fn near(a: &[kurbo::Line], b: &[kurbo::Line], budget: &mut usize) -> bool { use kurbo::{ParamCurve, ParamCurveArclen, ParamCurveNearest}; - let close = |p: kurbo::Point| b.iter().any(|t| t.nearest(p, 1e-6).distance_sq <= OUTLINE_TOLERANCE * OUTLINE_TOLERANCE); + let close = |p: kurbo::Point| b.iter().any(|t| t.nearest(p, 1e-6).distance_sq <= OUTLINE_POINT_LIMIT * OUTLINE_POINT_LIMIT); for s in a { - let steps = (s.arclen(1e-6) / OUTLINE_TOLERANCE).ceil(); + let steps = (s.arclen(1e-6) / OUTLINE_SPACING).ceil(); let steps = if steps.is_finite() && steps >= 1.0 { steps as usize } else { 1 }; let Some(left) = budget.checked_sub(steps.saturating_add(1).saturating_mul(b.len())) else { return false }; *budget = left; @@ -1403,6 +1414,26 @@ mod tests { assert!(started.elapsed() < std::time::Duration::from_secs(5), "{:?}", started.elapsed()); } + /// The outline check holds for every point of the outlines, not only the points it checks: a + /// 0.25 pt line whose look has only short pieces over its ends, 0.24 pt away, leaves the + /// line's middle about 0.27 pt from the look, so the drawn look stays. The line drawn 0.1 pt + /// away matches. + #[test] + fn the_outline_check_holds_between_the_points_it_checks() { + use kurbo::Point; + use vectorcraft_geom::{PathData, SubPath}; + let appearance = Appearance::basic(Paint::None, Paint::None, 0.0); + let line = PathData::new(vec![SubPath::polyline(&[Point::new(0.0, 0.0), Point::new(0.25, 0.0)], false)]); + let object = Node::path(NodeId(1), line, appearance.clone()); + let look = |pieces: &[[Point; 2]]| { + let drawn = PathData::new(pieces.iter().map(|p| SubPath::polyline(p, false)).collect()); + Node::group(NodeId(2), vec![Arc::new(Node::path(NodeId(3), drawn, Appearance::default()))]) + }; + let ends = [[Point::new(0.0, 0.24), Point::new(0.01, 0.24)], [Point::new(0.24, 0.24), Point::new(0.25, 0.24)]]; + assert!(!draws_look_outline(&object, &appearance, &look(&ends))); + assert!(draws_look_outline(&object, &appearance, &look(&[[Point::new(0.0, 0.1), Point::new(0.25, 0.1)]]))); + } + /// An image draws no stroke, so an image with a brush in its art style keeps its drawn look. #[test] fn an_image_with_a_brush_keeps_its_drawn_look() {