From 46745dbf8547680f9b4a5ceaeca9e5d089073330 Mon Sep 17 00:00:00 2001 From: jmverges Date: Mon, 16 Nov 2026 14:57:01 +0000 Subject: [PATCH] .ai import: an envelope of type that paints nothing, as its drawn art, opens live An envelope of type whose type has no fill and no stroke, its drawn art unpainted too, inks no pixel either way. The drawn-art check took that as a difference and kept the drawn art, with its type hidden. `alike_within` now first asks whether either side has any paint at all (`paints`). When neither has any, they draw alike (nothing) and add nothing to the page check's share. Art that paints, however faintly, is compared as before. The shapes aren't compared when nothing paints: the first way tried (the envelope as saved) is taken. Co-Authored-By: Claude Opus 5.5 --- crates/eps/src/import/ai/envelope.rs | 70 +++++++++++++++++++++++++-- crates/eps/src/import/tests_native.rs | 26 ++++++++++ 2 files changed, 92 insertions(+), 4 deletions(-) diff --git a/crates/eps/src/import/ai/envelope.rs b/crates/eps/src/import/ai/envelope.rs index 501b9f4b00..264471eb15 100644 --- a/crates/eps/src/import/ai/envelope.rs +++ b/crates/eps/src/import/ai/envelope.rs @@ -980,10 +980,11 @@ pub(super) fn warps(appearance: &Appearance) -> bool { appearance.effects.iter().any(warp) || appearance.items.iter().any(|i| i.visible() && i.effects().iter().any(warp)) } -/// Do `live` and `drawn` draw alike: few of the pixels either inks differ, and fewer still where a -/// whole patch differs; and, on `page` (when the file has one), do they differ little enough that -/// with the differences in `spent` the page check still takes the layers' art (it is added to -/// `spent` when they do)? Both are drawn on `layer`, a layer id no other node has. +/// Do `live` and `drawn` draw alike? Either neither has any paint ([`paints`]), or few of the +/// pixels either inks differ and fewer still where a whole patch differs, and, on `page` (when the +/// file has one), they differ little enough that with the differences in `spent` the page check +/// still takes the layers' art (it is added to `spent` when they do). Both are drawn on `layer`, a +/// layer id no other node has. pub(super) fn drawn_alike(live: &Node, drawn: &Node, layer: NodeId, shared: &Shared<'_>, page: Option, spent: &mut Spent) -> bool { alike_within(live, drawn, live.visual_bounds(), layer, shared, page, spent) } @@ -997,6 +998,12 @@ pub(super) fn warped_alike(live: &Node, drawn: &Node, layer: NodeId, shared: &Sh /// [`drawn_alike`], with `live` measured as `reach`. fn alike_within(live: &Node, drawn: &Node, reach: Option, layer: NodeId, shared: &Shared<'_>, page: Option, spent: &mut Spent) -> bool { + // Neither has any paint (type with no fill and no stroke, its drawn art the outlines unpainted): + // both draw nothing, so they draw alike and add nothing to what the page check sees. Their + // shapes aren't compared. Art that paints, however faintly, is compared as before. + if !paints(live, 0) && !paints(drawn, 0) { + return true; + } let (Some(a), Some(b)) = (reach, drawn.visual_bounds()) else { return false }; let region = a.union(b).inflate(2.0, 2.0); if !(region.is_finite() && region.width() > 0.0 && region.height() > 0.0) || region.width().max(region.height()) > 1e6 { @@ -1029,6 +1036,26 @@ fn alike_within(live: &Node, drawn: &Node, reach: Option, layer: NodeId, s true } +/// Does `n`, shown, paint anything: a fill or stroke of its own or of its type with a paint, an +/// effect, or an object of another kind than a path, type or container (an image, a mesh, a symbol +/// instance…)? Hidden objects paint nothing. Past `depth` 64 it is taken to paint. +fn paints(n: &Node, depth: usize) -> bool { + if depth > 64 { + return true; + } + if !n.visible { + return false; + } + if n.appearance.items.iter().any(|i| i.visible() && !i.paint().is_none()) || n.appearance.effects.iter().any(|e| e.visible) { + return true; + } + match &n.kind { + NodeKind::Path { .. } => false, + NodeKind::Text(t) => t.runs.iter().any(|r| !r.style.fill.is_none() || !r.style.stroke.is_none()), + _ => n.children().is_none_or(|c| c.iter().any(|c| paints(c, depth + 1))), + } +} + #[cfg(test)] mod tests { use super::*; @@ -1056,6 +1083,41 @@ mod tests { } } + /// A 40 × 40 square at (10, 10) filled black at `opacity`, or with no fill when `None`. + fn square_node(id: u64, opacity: Option) -> Node { + let mut bp = BezPath::new(); + bp.move_to((10.0, 10.0)); + bp.line_to((50.0, 10.0)); + bp.line_to((50.0, 50.0)); + bp.line_to((10.0, 50.0)); + bp.close_path(); + let mut n = Node::new( + NodeId(id), + NodeKind::Path { path: PathData::from_bezpath(&bp), rule: Default::default(), live: None, clipping: false, guide: false }, + ); + let mut appearance = (*n.appearance).clone(); + appearance.items.clear(); + if let Some(o) = opacity { + appearance.items.push(AppearanceItem::Fill(vectorcraft_doc::FillLayer::new(Paint::solid(Color::BLACK)))); + n.opacity = o; + } + n.appearance = appearance.into(); + n + } + + /// Two objects with no paint draw alike; two that paint too faintly to ink a pixel (an alpha of + /// 8 or less) aren't taken as alike, nor is one with paint against one without. + #[test] + fn art_with_no_paint_draws_alike_and_faint_art_is_still_compared() { + let shared = Shared { patterns: &[], images: &BTreeMap::new() }; + let alike = |a: &Node, b: &Node| drawn_alike(a, b, NodeId(999), &shared, None, &mut Spent::default()); + let (none, other_none) = (square_node(1, None), square_node(2, None)); + assert!(alike(&none, &other_none)); + let (faint, other_faint) = (square_node(1, Some(0.02)), square_node(2, Some(0.02))); + assert!(!alike(&faint, &other_faint)); + assert!(!alike(&none, &square_node(2, Some(1.0)))); + } + /// "AVA" at 40 points, at (10, 60). fn type_node(id: u64, style: CharStyle) -> Node { Node::new(NodeId(id), NodeKind::Text(Box::new(TextObject::point(Point::new(10.0, 60.0), "AVA", CharStyle { size: 40.0, ..style })))) diff --git a/crates/eps/src/import/tests_native.rs b/crates/eps/src/import/tests_native.rs index dbac845dad..999bacf2f4 100644 --- a/crates/eps/src/import/tests_native.rs +++ b/crates/eps/src/import/tests_native.rs @@ -5998,6 +5998,32 @@ fn an_envelope_of_type_that_draws_as_its_drawn_art_opens_live() { assert!(super::tests::program_warnings(&r.warnings).is_empty(), "{:?}", r.warnings); } +/// An envelope of type with no fill and no stroke, its drawn art the bent outlines unpainted, opens +/// live: neither draws a pixel, so they draw alike, and the type stays editable. +#[test] +fn an_envelope_of_unpainted_type_whose_drawn_art_paints_nothing_opens_live() { + let Some(family) = installed_family() else { return }; + // The outlines come from the type filled; the file's type has its fill turned off (`/56 false`). + let filled = type_envelope_text(&family, None); + let mut doc = text_document(&[("FLUX\r", 0, (8170.0, 8180.0), (0.0, 0.0), 0.0)]) + .replace("(Helvetica)", &format!("({family})")) + .replace("/53 <<", "/56 false /53 <<"); + while ascii85(doc.as_bytes()).len() % 60 == 1 { + doc.push('\n'); + } + assert_eq!(text_fill(&made_envelope_type(&doc)), None); + let (drawn, _) = drawn_envelope(&arc_envelope(&made_envelope_type(&filled), 30.0)); + assert!(drawn.contains("f\n"), "{drawn}"); + let unpainted = drawn.replace("f\n", "n\n"); + let art = native_with_text(&layer("Art", true, &format!("{}\n{}", square(10, 10), type_envelope(&arc_keys(0.3), &unpainted))), &doc); + let r = import(&eps(&page_square(10, 10), &art)).unwrap(); + assert_eq!(names(&r.document), ["Art"], "{:?}", r.warnings); + let (envelopes, loose) = envelopes_and_type(&r.document); + assert_eq!(envelopes, [vec!["FLUX".to_string()]], "{:?}", r.warnings); + assert!(loose.is_empty(), "{loose:?}"); + assert!(super::tests::program_warnings(&r.warnings).is_empty(), "{:?}", r.warnings); +} + /// An envelope of type whose live envelope draws apart from its drawn art (the file's art bends the /// other way) keeps its drawn art and its type, hidden, with a note. #[test]