diff --git a/crates/doc/src/text.rs b/crates/doc/src/text.rs index 440c379283..7481fc77a2 100644 --- a/crates/doc/src/text.rs +++ b/crates/doc/src/text.rs @@ -34,7 +34,7 @@ pub use tabs_lists::{ Bullet, DEFAULT_TAB_INTERVAL, LIST_HANGING_INDENT, LIST_LEVEL_INDENT, LIST_LEVELS, ListAlign, ListCounts, NumberStyle, ParaList, TabAlign, TabStop, }; -pub use wrap::{resolve_wrap, wrap_work}; +pub use wrap::{resolve_wrap, wrap_outline, wrap_work}; /// A text object. `runs` split into paragraphs at `\n`. /// diff --git a/crates/doc/src/text/wrap.rs b/crates/doc/src/text/wrap.rs index 0b5fe45dc2..81cb7d9c8f 100644 --- a/crates/doc/src/text/wrap.rs +++ b/crates/doc/src/text/wrap.rs @@ -32,6 +32,16 @@ fn outline(n: &Node, out: &mut PathData) { } } +/// The outline area type wraps around for wrap object `n`, in document coordinates, as +/// [`resolve_wrap`] makes it: a path's subpaths that are closed or have more than two anchors, those +/// of the shown members of a group or compound path, a clip group's clipping object's, and the +/// bounds of other art. Empty when `n` has none. +pub fn wrap_outline(n: &Node) -> PathData { + let mut pd = PathData::default(); + outline(n, &mut pd); + pd +} + enum Item<'a> { Wrap(&'a Node), Text(&'a Node), diff --git a/crates/eps/src/ai_editing/tests.rs b/crates/eps/src/ai_editing/tests.rs index a3b2800fd3..31e4d155a1 100644 --- a/crates/eps/src/ai_editing/tests.rs +++ b/crates/eps/src/ai_editing/tests.rs @@ -10222,3 +10222,151 @@ fn a_clipping_path_written_as_its_paint_keeps_one_text_wrap() { same_wraps(&wraps(read_back(&doc).layers[0].children().unwrap()), &[(None, 5.0, true)]); } } + +/// The wrap shapes [`vectorcraft_doc::text::resolve_wrap`] gives the area type in `doc`. +fn area_wrap(doc: &Document) -> Vec { + let mut d = doc.clone(); + vectorcraft_doc::text::resolve_wrap(None, &mut d); + let mut out = vec![]; + d.layers[0].walk(&mut |n| { + if let NodeKind::Text(t) = &n.kind + && matches!(t.kind, vectorcraft_doc::TextKind::Area { .. }) + { + out.clone_from(&t.wrap); + } + }); + out +} + +/// `got` and `want` are the same wrap shapes: the same options, offsets within `1e-6`, and the +/// same subpaths with anchors within `1e-3`. +fn same_shapes(got: &[vectorcraft_doc::WrapShape], want: &[vectorcraft_doc::WrapShape], case: &str) { + let same = got.len() == want.len() + && got.iter().zip(want).all(|(g, w)| { + g.wrap.invert == w.wrap.invert + && (g.wrap.offset - w.wrap.offset).abs() < 1e-6 + && g.path.subpaths.len() == w.path.subpaths.len() + && g.path.subpaths.iter().zip(&w.path.subpaths).all(|(a, b)| { + a.closed == b.closed + && a.anchors.len() == b.anchors.len() + && a.anchors.iter().zip(&b.anchors).all(|(p, q)| (p.p - q.p).hypot() < 1e-3) + }) + }); + assert!(same, "{case}\n{got:?}\n{want:?}"); +} + +/// A clipping object that isn't written as an object of its own (a group, an image, a symbol +/// instance, a path or compound path without paint in art cut to a clipping object) or is written +/// as its outlines or cut (type, a path the outer clipping object cuts) keeps its text wrap options on one unpainted object +/// of its wrap outline: area type below it wraps alike after a round trip, and the object stays +/// locked or hidden as it was. A clipping object without options gets no such object. +#[test] +fn a_clipping_object_not_written_whole_keeps_its_text_wrap() { + use vectorcraft_doc::{TextKind, TextObject, TextRun}; + let cases = ["group", "hidden", "locked", "image", "instance", "type", "unpainted path", "unpainted compound", "cut path", "no options"]; + for case in cases { + let mut doc = Document::new(400.0, 200.0); + let layer = doc.layers[0].id; + let st = style(10.0, Color::BLACK); + let mut area = TextObject::point(vectorcraft_geom::Point::ZERO, "", st.clone()); + area.runs = vec![TextRun::new("One two three four five six", st)]; + area.kind = TextKind::Area { frame: shapes::rectangle(Rect::new(0.0, 0.0, 400.0, 200.0)) }; + area.xf = Affine::IDENTITY; + let area = text_node(&mut doc, area); + doc.insert(Some(layer), usize::MAX, area).unwrap(); + let art = square(&mut doc, Rect::new(0.0, 0.0, 10.0, 10.0), LEAF); + doc.symbols.push(Symbol { dynamic: false, name: "Leaf".into(), art: Arc::new(art) }); + let mut cutter = match case { + "group" | "hidden" | "locked" | "no options" => { + let mut off = square(&mut doc, Rect::new(200.0, 20.0, 230.0, 60.0), Color::gray(0.5)); + off.visible = false; + let members = vec![ + square(&mut doc, Rect::new(20.0, 20.0, 50.0, 60.0), Color::gray(0.5)), + square(&mut doc, Rect::new(60.0, 30.0, 90.0, 70.0), Color::gray(0.5)), + off, + ]; + group(&mut doc, members, false) + } + "image" => image_node(&mut doc, ImageBlob::png(rgb_png()), (3, 2), Affine::new([20.0, 0.0, 0.0, 20.0, 30.0, 40.0]), None), + "instance" => instance(&mut doc, "Leaf", Affine::translate((40.0, 30.0))), + "type" => { + let label = TextObject::point(vectorcraft_geom::Point::new(30.0, 50.0), "Clip", style(24.0, Color::BLACK)); + text_node(&mut doc, label) + } + "unpainted path" => clipping(&mut doc, shapes::rectangle(Rect::new(20.0, 20.0, 80.0, 80.0))), + "unpainted compound" => { + let outer = Node::path(doc.alloc_id(), shapes::rectangle(Rect::new(20.0, 20.0, 80.0, 80.0)), Appearance::default()); + let inner = Node::path(doc.alloc_id(), shapes::rectangle(Rect::new(30.0, 30.0, 70.0, 70.0)), Appearance::default()); + Node::new(doc.alloc_id(), NodeKind::Compound { children: vec![Arc::new(outer), Arc::new(inner)], rule: FillRule::EvenOdd }) + } + _ => { + let mut c = clipping(&mut doc, shapes::rectangle(Rect::new(50.0, 20.0, 150.0, 80.0))); + c.appearance = Appearance::basic(solid(Color::gray(0.5)), Paint::None, 0.0).into(); + c + } + }; + cutter.visible = case != "hidden"; + cutter.locked = case == "locked"; + let cutter = if case == "no options" { cutter } else { wrapped(cutter, -4.5, true) }; + let member = square(&mut doc, Rect::new(30.0, 30.0, 70.0, 50.0), Color::rgb(1.0, 0.0, 0.0)); + let mut top = group(&mut doc, vec![cutter, member], true); + if matches!(case, "unpainted path" | "unpainted compound" | "cut path") { + let frame = square(&mut doc, Rect::new(0.0, 0.0, 100.0, 100.0), Color::gray(0.9)); + let frame = group(&mut doc, vec![frame], false); + top = group(&mut doc, vec![frame, top], true); + } + doc.insert(Some(layer), usize::MAX, top).unwrap(); + let text = program(&doc); + let back = read_back(&doc); + if case == "no options" { + assert!(!text.contains("(AI11TextWrapOffset)"), "{text}"); + assert!(wraps(back.layers[0].children().unwrap()).is_empty()); + continue; + } + assert_eq!(text.matches("(AI11TextWrapOffset)").count(), 1, "{case}\n{text}"); + same_wraps(&wraps(back.layers[0].children().unwrap()), &[(None, -4.5, true)]); + let mut carrier = None; + back.layers[0].walk(&mut |n| { + if n.extras().wrap.is_some() { + carrier = Some((n.locked, n.visible)); + } + }); + assert_eq!(carrier, Some((case == "locked", case != "hidden")), "{case}"); + let want = area_wrap(&doc); + assert_eq!(want.is_empty(), case == "hidden", "{case}"); + same_shapes(&area_wrap(&back), &want, case); + } +} + +/// With too little room for the unpainted object that carries a clipping object's text wrap +/// options, the options are left out, never written on another object, and the data stays readable. +#[test] +fn a_clipping_objects_text_wrap_is_left_out_without_room() { + let mut doc = Document::new(200.0, 100.0); + let layer = doc.layers[0].id; + let members = vec![ + square(&mut doc, Rect::new(20.0, 20.0, 50.0, 60.0), Color::gray(0.5)), + square(&mut doc, Rect::new(60.0, 30.0, 90.0, 70.0), Color::gray(0.5)), + ]; + let cutter = wrapped(group(&mut doc, members, false), 2.0, false); + let member = square(&mut doc, Rect::new(30.0, 30.0, 70.0, 50.0), Color::rgb(1.0, 0.0, 0.0)); + let top = group(&mut doc, vec![cutter, member], true); + doc.insert(Some(layer), usize::MAX, top).unwrap(); + let all = crate::import::objects_read(&export_ai_editing(&doc, &opts()).unwrap().program).unwrap(); + for room in 0..=all { + let out = export_within(&doc, &opts(), room).unwrap(); + assert!(crate::import::objects_read(&out.program).unwrap() <= room); + let text = String::from_utf8_lossy(&out.program).replace("\r\n", "\n"); + // The group, then the compound path of the two squares (three objects): with room for all four + // the options are written, on that compound path. + assert_eq!(text.matches("(AI11TextWrapOffset)").count(), usize::from(room >= 4), "{room}\n{text}"); + let (back, _) = crate::ai_alone(&out.program).unwrap(); + let mut carriers = vec![]; + back.layers[0].walk(&mut |n| { + if n.extras().wrap.is_some() { + carriers.push(matches!(n.kind, NodeKind::Compound { .. }) && n.appearance.items.is_empty()); + } + }); + assert_eq!(carriers, if room >= 4 { vec![true] } else { vec![] }, "{room}\n{text}"); + } +} diff --git a/crates/eps/src/ai_editing/writer.rs b/crates/eps/src/ai_editing/writer.rs index 765856753c..c77d9d354d 100644 --- a/crates/eps/src/ai_editing/writer.rs +++ b/crates/eps/src/ai_editing/writer.rs @@ -1041,16 +1041,15 @@ impl<'a> Writer<'a> { /// A container's members, the first one's outline cutting the others: its fills painted /// behind them (cut to the region outside too), its strokes over them, not cut by it. Its text - /// wrap options are written once: with its fills, or without fills with its strokes. + /// wrap options are written once, under them all ([`Self::wrap_carrier`]). fn clip_contents(&mut self, children: &[Arc]) { let Some((first, rest)) = children.split_first() else { return }; + self.wrap_carrier(first); // Nothing to clip by hides the clipped art. let Some((outline, rule)) = vectorcraft_effects::clip_outline(first) else { return }; let mut paint = first.clip_paint(); - if let (Some(_), Some(stroke)) = (&paint.fill, &mut paint.stroke) - && stroke.extras().wrap.is_some() - { - stroke.extras_mut().wrap = None; + for part in [&mut paint.fill, &mut paint.stroke].into_iter().flatten() { + part.extras_mut().wrap = None; } let outer = self.clip.clone(); let region = self.cut(&PathData::from_bezpath(&outline), rule); @@ -1067,6 +1066,28 @@ impl<'a> Writer<'a> { } } + /// The text wrap options of clipping object `first`, when it has them, on an unpainted path + /// (a compound path for several subpaths) of the outline area type wraps around + /// ([`vectorcraft_doc::text::wrap_outline`]), uncut, locked and hidden as `first` is. Nothing is + /// written for an empty outline or without room for the path ([`Self::take_objects`]). + fn wrap_carrier(&mut self, first: &Node) { + let Some(wrap) = first.extras().wrap.filter(|_| self.drawn == 0 && !self.in_look) else { return }; + let outline = vectorcraft_doc::text::wrap_outline(first); + if outline.is_empty() { + return; + } + self.state(first.locked, !first.visible); + let start = self.body.len(); + self.plain_object(&outline, FillRule::NonZero, None, None, Xy::of(first).object()); + if self.body.len() == start { + return; + } + self.block_end = usize::MAX; + self.body.push_str("%_/ArtDictionary :\n"); + self.text_wrap(wrap); + self.body.push_str("%_;\n%_\n"); + } + /// `path` (filled by `rule`) cut to the region the art is cut to, as a non-zero path. fn cut(&self, path: &PathData, rule: FillRule) -> PathData { match &self.clip { diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 7e36c7f318..b7a72fca0a 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1671,6 +1671,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur A PDF-compatible `.ai` saved with Include Editing Data for Other Apps writes point type, area type and type on a path as type in its editing copy, and objects next to it keep their own transparency (`crates/eps/src/ai_editing/tests.rs`, `cmd::fileio::tests_pdfedit::type_comes_back_from_the_editing_copy`; [file-format-parity.md](file-format-parity.md) lists what is written as outlines). A PDF-compatible `.ai` saved with Include Editing Data for Other Apps keeps the document's variables, data sets and the bindings of objects to variables in its editing copy, in the form the variable library reader above reads, so they come back when the file is opened. Bindings to layers, to type written as outlines, to graphs and to linked images written as other objects, data set values of graphs, and variables, data sets, bindings and values past the writer's limits are left out with a warning (#6024; `crates/eps/src/ai_editing/tests.rs` `variables_data_sets_and_bindings_are_read_back`; `crates/eps/src/ai_editing/writer/variables.rs` lists what is left out). A PDF-compatible `.ai` saved with Include Editing Data for Other Apps keeps each wrap object's Text Wrap Options in its editing copy: the Offset, positive or negative, and Invert Wrap ([the help page](https://helpx.adobe.com/illustrator/desktop/design-with-text/add-manage-text/wrap-or-unwrap-text-around-objects.html)), in the form the `.ai` reader reads them (`text_wrap` in `crates/eps/src/import/ai/read/document.rs`), so they come back when the file is opened. An offset past the -1000 to 1000 pt the reader keeps is written as the nearer end of that range. On a large canvas the offset is written at the art's scale and comes back at its size. Art the writer draws for an object, such as a blend's steps or a symbol instance written as its art, has only that object's options, and a clipping path written as its fills and its strokes has its options once (`crates/eps/src/ai_editing/tests.rs` `text_wrap_options_are_written_and_read_back`, `drawn_art_keeps_only_its_objects_text_wrap`, `text_wrap_offsets_on_a_large_canvas_come_back_at_their_size`, `text_wrap_options_of_type_and_envelopes_are_read_back`, `a_clipping_path_written_as_its_paint_keeps_one_text_wrap`). + A clipping object whose clipped art is written cut to it (a group, an image, a symbol instance, type, or a path or compound path inside art cut to another clipping object) keeps its Text Wrap Options in the editing copy on an unpainted path, or compound path, of the outline area type wraps around, under the art it clips and locked or hidden as the object is. The `.ai` reader reads an unpainted path (`paint` in `crates/eps/src/import/ai/read/art.rs`) and gives it the options of the dictionary after it (`text_wrap` in `crates/eps/src/import/ai/read/document.rs`), so area type below the object wraps the same way when the file is opened. Without room for that path under the object limit, the options are left out (`crates/eps/src/ai_editing/tests.rs` `a_clipping_object_not_written_whole_keeps_its_text_wrap`, `a_clipping_objects_text_wrap_is_left_out_without_room`). In a `.ai` or EPS opened from its editing data, type has its text object's opacity, blend mode and knockout shape flag, whether it is made from the file's text document or taken from the page, and type made from the text document takes its text object's lock. Where such type has transparency and comes in with other art (the rest of its look, or page type and strokes that go with it), a group of them has it. Where the page draws its type, or the strokes around it, with transparency that is neither its text object's nor its text object's combined with that of the objects around it, the page's type and strokes keep their own instead (`crates/eps/src/import/tests_native.rs`). Where the page draws type of no text object over text objects made from the text document, with their words in any case, that type is theirs as the page draws it and is left out; the page's other type of no text object goes only to text objects whose type the text document can't make, or else is left out with a warning. `.ai` editing-data import restores the document's listed graphic styles in panel order and links objects that use a listed style; unsupported appearances keep their drawn look (`crates/eps/src/import/ai/tests.rs`). A `.ai` or EPS graphic style library, whose editing data holds the styles and their list but no layers, opens with those styles in list order. Other Library… loads another document's graphic styles ([Apply graphic styles](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/apply-graphic-styles/apply-graphic-styles.html)) and lists such a library's styles in a library panel. A `.ai` or EPS read as its PDF part or page because its layers can't be used also gets the styles of its list in place of the default ones (`crates/eps/src/import/tests_native.rs`, `cmd::fileio::tests_aiimport::a_graphic_style_library_in_a_ai_file_without_layers_loads_its_styles`).