diff --git a/crates/engine/src/tests/prefs.rs b/crates/engine/src/tests/prefs.rs index 4b5848bcf9..a8617bf822 100644 --- a/crates/engine/src/tests/prefs.rs +++ b/crates/engine/src/tests/prefs.rs @@ -1936,6 +1936,315 @@ fn real_time_drawing_off_draws_the_bounds_of_a_selection_too_big_to_outline() { assert!(moved.0 > 1.0 && moved.1 > 1.0 && moved.2.abs() < 1e-6 && moved.3.abs() < 1e-6, "the bounds moved with the drag: {moved:?}"); } +/// The bounding boxes (left, top, width) of the Real-time Drawing off feedback after a drag by (30, 40) +/// from (x, y), left to right. +fn dragged_feedback_boxes(s: &mut Session, x: f64, y: f64) -> Vec<(f64, f64, f64)> { + use vectorcraft_tools::Overlay; + use vectorcraft_tools::draw2::FEEDBACK; + let v = ViewInfo::default(); + s.select_tool("selection", v).unwrap(); + set_pref(s, "realTimeDrawing", json!(false)); + s.pointer(&PointerEvent::new(PointerKind::Down, x, y), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, x + 30.0, y + 40.0), v).unwrap(); + let mut boxes: Vec<_> = s + .overlays(v) + .into_iter() + .filter_map(|o| match o { + Overlay::Path { path, color, .. } if color == FEEDBACK => Some(kurbo::Shape::bounding_box(&path)), + _ => None, + }) + .map(|b| ((b.x0 * 1e3).round() / 1e3, (b.y0 * 1e3).round() / 1e3, (b.width() * 1e3).round() / 1e3)) + .collect(); + boxes.sort_by(|p, q| p.0.total_cmp(&q.0)); + boxes +} + +/// The number of subpaths in each path of the Real-time Drawing off feedback the session shows now. +fn feedback_subpaths(s: &mut Session) -> Vec { + use vectorcraft_tools::Overlay; + use vectorcraft_tools::draw2::FEEDBACK; + s.overlays(ViewInfo::default()) + .into_iter() + .filter_map(|o| match o { + Overlay::Path { path, color, .. } if color == FEEDBACK => { + Some(path.elements().iter().filter(|el| matches!(el, kurbo::PathEl::MoveTo(_))).count()) + } + _ => None, + }) + .collect() +} + +/// With Real-time Drawing off, a dragged group draws the outline of each member, nested groups' +/// members included, at the dragged position instead of one union of them all. +#[test] +fn real_time_drawing_off_outlines_a_dragged_group_member_by_member() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let rect = |s: &mut Session, x: f64| s.execute("shape.rectangle", &json!({"x": x, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + let (a, b, c) = (rect(&mut s, 100.0), rect(&mut s, 150.0), rect(&mut s, 200.0)); + s.execute("select.set", &json!({"ids": [b, c]})).unwrap(); + let inner = s.execute("object.group", &json!({})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [a, inner]})).unwrap(); + s.execute("object.group", &json!({})).unwrap(); + let boxes = dragged_feedback_boxes(&mut s, 120.0, 120.0); + assert_eq!(boxes, [(130.0, 140.0, 100.0), (180.0, 140.0, 100.0), (230.0, 140.0, 100.0)], "one moved outline per member"); +} + +/// With Real-time Drawing off, a hidden member of a dragged group draws no outline. +#[test] +fn real_time_drawing_off_skips_a_hidden_member_of_a_dragged_group() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let rect = |s: &mut Session, x: f64| s.execute("shape.rectangle", &json!({"x": x, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + let (a, b, c) = (rect(&mut s, 100.0), rect(&mut s, 150.0), rect(&mut s, 200.0)); + s.execute("select.set", &json!({"ids": [b]})).unwrap(); + s.execute("object.hide", &json!({})).unwrap(); + s.execute("select.set", &json!({"ids": [a, b, c]})).unwrap(); + s.execute("object.group", &json!({})).unwrap(); + let boxes = dragged_feedback_boxes(&mut s, 120.0, 120.0); + assert_eq!(boxes, [(130.0, 140.0, 100.0), (230.0, 140.0, 100.0)]); +} + +/// With Real-time Drawing off, a dragged blend draws the outline of each of its objects and steps. +#[test] +fn real_time_drawing_off_outlines_a_dragged_blend_step_by_step() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let a = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + let b = s.execute("shape.rectangle", &json!({"x": 300, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [a, b]})).unwrap(); + s.execute("object.blend.make", &json!({"steps": 3})).unwrap(); + let lefts: Vec = dragged_feedback_boxes(&mut s, 120.0, 120.0).iter().map(|b| b.0).collect(); + assert_eq!(lefts, [130.0, 180.0, 230.0, 280.0, 330.0], "one moved outline per blended object and step"); +} + +/// With Real-time Drawing off, a dragged compound shape draws the outline of the area it makes. +#[test] +fn real_time_drawing_off_outlines_a_dragged_compound_shape_by_its_area() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let a = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + let b = s.execute("shape.rectangle", &json!({"x": 150, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [a, b]})).unwrap(); + let shape = s.execute("object.compoundShape.make", &json!({"mode": "intersect"})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [shape]})).unwrap(); + assert_eq!(dragged_feedback_boxes(&mut s, 170.0, 120.0), [(180.0, 140.0, 50.0)]); +} + +/// With Real-time Drawing off, a dragged group with a Pathfinder effect draws the outline of the area +/// the effect makes. +#[test] +fn real_time_drawing_off_outlines_a_dragged_pathfinder_group_by_its_area() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let a = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + let b = s.execute("shape.rectangle", &json!({"x": 150, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [a, b]})).unwrap(); + s.execute("object.group", &json!({})).unwrap(); + s.execute("effect.apply", &json!({"effect": "pathfinder.intersect"})).unwrap(); + assert_eq!(dragged_feedback_boxes(&mut s, 170.0, 120.0), [(180.0, 140.0, 50.0)]); +} + +/// With Real-time Drawing off, a dragged group with a Drop Shadow draws the outline of each member +/// instead of one union of them. +#[test] +fn real_time_drawing_off_outlines_a_dragged_group_with_an_effect_member_by_member() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let a = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + let b = s.execute("shape.rectangle", &json!({"x": 150, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [a, b]})).unwrap(); + s.execute("object.group", &json!({})).unwrap(); + s.execute("effect.apply", &json!({"effect": "stylize.dropShadow", "item": null})).unwrap(); + assert_eq!(dragged_feedback_boxes(&mut s, 120.0, 120.0), [(130.0, 140.0, 100.0), (180.0, 140.0, 100.0)]); +} + +/// With Real-time Drawing off, a dragged clip group draws only its clipping path, as its selection +/// highlight does. +#[test] +fn real_time_drawing_off_outlines_a_dragged_clip_group_by_its_clipping_path() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let art = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 200, "height": 100})).unwrap()["id"].clone(); + let clip = s.execute("shape.rectangle", &json!({"x": 120, "y": 110, "width": 50, "height": 50})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [art, clip]})).unwrap(); + s.execute("object.clippingMask.make", &json!({})).unwrap(); + assert_eq!(dragged_feedback_boxes(&mut s, 140.0, 130.0), [(150.0, 150.0, 50.0)]); +} + +/// With Real-time Drawing off, a dragged envelope draws the outline of each object it evaluates to: each +/// rectangle's fill and its outlined stroke. +#[test] +fn real_time_drawing_off_outlines_a_dragged_envelope_object_by_object() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let a = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + let b = s.execute("shape.rectangle", &json!({"x": 150, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [a, b]})).unwrap(); + s.execute("object.envelope.makeWithMesh", &json!({"rows": 1, "cols": 1})).unwrap(); + let boxes = dragged_feedback_boxes(&mut s, 120.0, 120.0); + assert_eq!(boxes, [(129.5, 139.5, 101.0), (130.0, 140.0, 100.0), (179.5, 139.5, 101.0), (180.0, 140.0, 100.0)]); +} + +/// With Real-time Drawing off, a dragged Shaper group draws the outline of its result and not of the +/// source art it keeps. +#[test] +fn real_time_drawing_off_skips_the_source_art_of_a_dragged_shaper_group() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap(); + s.execute("shape.rectangle", &json!({"x": 150, "y": 100, "width": 100, "height": 100})).unwrap(); + let points = [[125.0, 120.0], [175.0, 135.0], [130.0, 150.0], [225.0, 165.0], [175.0, 180.0], [225.0, 185.0]]; + let shaper = s.execute("shaper.scribble", &json!({"points": points})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [shaper]})).unwrap(); + let boxes = dragged_feedback_boxes(&mut s, 120.0, 120.0); + assert_eq!(boxes, [(130.0, 140.0, 150.0), (130.0, 140.0, 150.0)], "the merged result's fill and stroke"); +} + +/// With Real-time Drawing off, a dragged symbol instance draws the bounds its selection highlight +/// shows, alone and as a member of a group. +#[test] +fn real_time_drawing_off_outlines_a_dragged_symbol_instance_by_its_bounds() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let a = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [a]})).unwrap(); + s.execute("symbol.new", &json!({"name": "Box"})).unwrap(); + assert_eq!(dragged_feedback_boxes(&mut s, 120.0, 120.0), [(130.0, 140.0, 100.0)]); + s.pointer(&PointerEvent::new(PointerKind::Up, 150.0, 160.0), ViewInfo::default()).unwrap(); + s.execute("shape.rectangle", &json!({"x": 400, "y": 100, "width": 50, "height": 50})).unwrap(); + s.execute("select.all", &json!({})).unwrap(); + s.execute("object.group", &json!({})).unwrap(); + assert_eq!(dragged_feedback_boxes(&mut s, 150.0, 160.0), [(160.0, 180.0, 100.0), (430.0, 140.0, 50.0)]); +} + +/// With Real-time Drawing off, a handle resize of a group draws each member's outline at its new size. +#[test] +fn real_time_drawing_off_outlines_a_resized_group_member_by_member() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let a = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + let b = s.execute("shape.rectangle", &json!({"x": 300, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [a, b]})).unwrap(); + s.execute("object.group", &json!({})).unwrap(); + // The Right handle, dragged 30 pt out: the group goes from 300 pt wide to 330. + assert_eq!(dragged_feedback_boxes(&mut s, 400.0, 125.0), [(100.0, 100.0, 110.0), (320.0, 100.0, 110.0)]); +} + +/// With Real-time Drawing off, each copy of a gradient mesh in a dragged repeat draws its mesh lines +/// once, without the pieces the mesh is drawn with. +#[test] +fn real_time_drawing_off_outlines_each_mesh_of_a_dragged_repeat_once() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let a = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [a]})).unwrap(); + s.execute("object.mesh.create", &json!({"rows": 2, "cols": 2})).unwrap(); + s.execute("object.repeat.grid", &json!({"rows": 1, "cols": 2})).unwrap(); + let boxes = dragged_feedback_boxes(&mut s, 120.0, 120.0); + assert_eq!(boxes.len(), 2, "one outline per copy: {boxes:?}"); + assert_eq!(boxes[0], (130.0, 140.0, 100.0), "the first copy's mesh lines, moved"); + let subpaths = feedback_subpaths(&mut s); + assert!(subpaths.len() == 2 && subpaths.iter().all(|&n| n > 1), "each copy's mesh lines, not one boundary: {subpaths:?}"); +} + +/// With Real-time Drawing off, a dragged gradient mesh with a Drop Shadow draws its mesh lines as one +/// outline, without the pieces the mesh is drawn with. +#[test] +fn real_time_drawing_off_outlines_a_dragged_mesh_with_an_effect_by_its_lines() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let a = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [a]})).unwrap(); + s.execute("object.mesh.create", &json!({"rows": 2, "cols": 2})).unwrap(); + s.execute("effect.apply", &json!({"effect": "stylize.dropShadow", "item": null})).unwrap(); + assert_eq!(dragged_feedback_boxes(&mut s, 120.0, 120.0), [(130.0, 140.0, 100.0)]); + let subpaths = feedback_subpaths(&mut s); + assert!(matches!(subpaths.as_slice(), [n] if *n > 1), "the mesh's lines, not one boundary: {subpaths:?}"); +} + +/// With Real-time Drawing off, a dragged group with a Vector Halftone keeps its own fill, which is what +/// the effect samples, so an unpainted member still gives an outline. +#[test] +fn real_time_drawing_off_outlines_a_dragged_halftone_group_with_its_own_fill() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let a = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap()["id"].clone(); + s.execute("paint.setFill", &json!({"ids": [a], "none": true})).unwrap(); + s.execute("paint.setStroke", &json!({"ids": [a], "none": true})).unwrap(); + s.execute("select.set", &json!({"ids": [a]})).unwrap(); + let group = s.execute("object.group", &json!({})).unwrap()["id"].clone(); + s.execute("paint.setFill", &json!({"color": "#000000", "ids": []})).unwrap(); + s.execute("select.set", &json!({"ids": [group]})).unwrap(); + s.execute("appearance.addFill", &json!({})).unwrap(); + let fill = s.doc().unwrap().doc.node(vectorcraft_doc::NodeId(group.as_u64().unwrap())).unwrap().appearance.fill_paint().label(); + assert_eq!(fill, "#000000", "the group's own fill"); + s.execute("effect.apply", &json!({"effect": "addon.color.halftone", "item": null})).unwrap(); + // The Right handle: the unpainted member gives nothing to press on. + assert!(!dragged_feedback_boxes(&mut s, 200.0, 150.0).is_empty(), "the halftone's dots are outlined"); +} + +/// With Real-time Drawing off, a dragged object with Crop Marks draws the object's outline without its +/// marks. +#[test] +fn real_time_drawing_off_outlines_a_dragged_object_without_its_crop_marks() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let a = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [a]})).unwrap(); + s.execute("effect.apply", &json!({"effect": "cropMarks", "item": null})).unwrap(); + assert_eq!(dragged_feedback_boxes(&mut s, 120.0, 120.0), [(130.0, 140.0, 100.0)]); +} + +/// With Real-time Drawing off, the objects a dragged repeat evaluates to count toward the limit with +/// the points of their outlines: 18,000 rectangles have 90,000 points, and with the objects they come +/// to 108,000. +#[test] +fn real_time_drawing_off_draws_the_bounds_of_a_repeat_with_too_many_objects() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let a = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 10, "height": 10})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [a]})).unwrap(); + s.execute("object.repeat.grid", &json!({"rows": 120, "cols": 150})).unwrap(); + let boxes = dragged_feedback_boxes(&mut s, 105.0, 105.0); + assert_eq!(boxes.len(), 1, "one bounds rectangle: {} boxes", boxes.len()); +} + +/// With Real-time Drawing off, a dragged intertwine draws the outline of each member, without the +/// area one of them is arranged over the other in. +#[test] +fn real_time_drawing_off_outlines_a_dragged_intertwine_member_by_member() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let a = s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + let b = s.execute("shape.rectangle", &json!({"x": 150, "y": 100, "width": 100, "height": 50})).unwrap()["id"].clone(); + s.execute("select.set", &json!({"ids": [a, b]})).unwrap(); + s.execute("object.intertwine.make", &json!({})).unwrap(); + s.execute("object.intertwine.arrange", &json!({"at": [175, 125], "order": "back"})).unwrap(); + let boxes = dragged_feedback_boxes(&mut s, 120.0, 120.0); + assert_eq!(boxes, [(130.0, 140.0, 100.0), (180.0, 140.0, 100.0)]); +} + +/// With Real-time Drawing off, a dragged group whose members have more than 100,000 points between +/// them shows its moved bounds, as a single path of that size does. +#[test] +fn real_time_drawing_off_draws_the_bounds_of_a_group_too_big_to_outline() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap(); + let path = |s: &mut Session, y: f64| { + let anchors: Vec = + (0..60_000).map(|i| json!({"x": 100.0 + f64::from(i) * 0.003, "y": if i % 2 == 0 { y } else { y + 50.0 }})).collect(); + s.execute("path.create", &json!({"anchors": anchors, "closed": false})).unwrap()["id"].clone() + }; + let (a, b) = (path(&mut s, 100.0), path(&mut s, 200.0)); + s.execute("select.set", &json!({"ids": [a, b]})).unwrap(); + s.execute("object.group", &json!({})).unwrap(); + let at_rest = s.doc().unwrap().doc.bounds_of(&s.doc().unwrap().selection.objects, true).unwrap(); + let boxes = dragged_feedback_boxes(&mut s, 200.0, 100.0); + let [(x, y, width)] = boxes.as_slice() else { panic!("one bounds rectangle, got {boxes:?}") }; + assert!((x - at_rest.x0 - 30.0).abs() < 1e-2 && (y - at_rest.y0 - 40.0).abs() < 1e-2 && (width - at_rest.width()).abs() < 1e-2, "{boxes:?}"); +} + /// A deferred commit that fails its preview cancels the interaction instead of leaving it open. #[test] fn deferred_commit_preview_failure_cancels_interaction() { diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index 2d85d620fe..7db1688326 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -1041,23 +1041,13 @@ impl Session { /// `crates/ui-egui/src/canvas/outline.rs`). Past it the selection's bounds are drawn instead. const FEEDBACK_MAX_POINTS: usize = 100_000; -/// The outline of every selected object, or the selection's bounds when the outlines have more than -/// [`FEEDBACK_MAX_POINTS`] points. +/// The outlines of every selected object, a group's members each with their own, or the selection's +/// bounds when the outlines' points and the objects evaluated to make them come to more than +/// [`FEEDBACK_MAX_POINTS`]. fn outlines_for_selection(doc: &vectorcraft_doc::Document, selection: &Selection) -> Vec { - let mut left = FEEDBACK_MAX_POINTS; - let mut outlines = vec![]; - for &id in &selection.objects { - let Some((path, _)) = doc.node(id).and_then(|n| vectorcraft_render::drawn_outline(doc, n)) else { continue }; - let points = path.elements().iter().filter(|el| !matches!(el, kurbo::PathEl::ClosePath)).count(); - let Some(l) = left.checked_sub(points) else { - return doc - .bounds_of(&selection.objects, true) - .map(|b| Overlay::Path { path: vectorcraft_geom::shapes::rectangle(b).to_bezpath(), color: FEEDBACK, width: 1.0, dashed: false }) - .into_iter() - .collect(); - }; - left = l; - outlines.push(Overlay::Path { path, color: FEEDBACK, width: 1.0, dashed: false }); - } - outlines + let nodes = selection.objects.iter().filter_map(|&id| doc.node(id)); + let outlines = vectorcraft_render::drawn_outlines(doc, nodes, FEEDBACK_MAX_POINTS).unwrap_or_else(|| { + doc.bounds_of(&selection.objects, true).map(|b| vectorcraft_geom::shapes::rectangle(b).to_bezpath()).into_iter().collect() + }); + outlines.into_iter().map(|path| Overlay::Path { path, color: FEEDBACK, width: 1.0, dashed: false }).collect() } diff --git a/crates/render/src/bounds.rs b/crates/render/src/bounds.rs index dec8db1c52..5cb622e5dc 100644 --- a/crates/render/src/bounds.rs +++ b/crates/render/src/bounds.rs @@ -34,3 +34,15 @@ pub fn drawn_bounds(doc: &Document, n: &Node) -> Option { pub fn drawn_outline(doc: &Document, n: &Node) -> Option<(BezPath, FillRule)> { fx::drawn_outline(doc, n) } + +/// The outlines a drag draws for `nodes` with Real-time Drawing off: one for each object in them, +/// without uniting a group's members. `None` when the outlines' points and the objects evaluated to +/// make them come to more than `max_points`. +pub fn drawn_outlines<'a>(doc: &Document, nodes: impl IntoIterator, max_points: usize) -> Option> { + let symbols = doc.symbol_boxes(); + let (mut left, mut out) = (max_points, vec![]); + for n in nodes { + fx::drawn_outlines(doc, &symbols, n, &mut left, &mut out)?; + } + Some(out) +} diff --git a/crates/render/src/fx.rs b/crates/render/src/fx.rs index 305ece3982..abdf1666ce 100644 --- a/crates/render/src/fx.rs +++ b/crates/render/src/fx.rs @@ -70,7 +70,7 @@ mod renderer; #[cfg(test)] pub(crate) use bounds::visual_bounds; -pub(crate) use bounds::{cull_bounds, drawn_outline, painted_reach, path_cull_bounds}; +pub(crate) use bounds::{cull_bounds, drawn_outline, drawn_outlines, painted_reach, path_cull_bounds}; #[cfg(test)] pub(crate) use entries::Drawn; pub(crate) use entries::{DocInputs, FxGeom, Reads, ShadowEntry}; diff --git a/crates/render/src/fx/bounds.rs b/crates/render/src/fx/bounds.rs index 8bccf2c36c..3e26921794 100644 --- a/crates/render/src/fx/bounds.rs +++ b/crates/render/src/fx/bounds.rs @@ -1,7 +1,8 @@ -use super::predicates::{has_fx, has_object_fx}; +use super::predicates::{has_fx, has_object_fx, is_container}; use super::raster::doc_raster_ppi; use super::{ - Affine, AppearanceItem, Arc, BezPath, Document, Effect, FillRule, GeomContext, Node, NodeKind, Rect, Renderer, Shape, SymbolBoxes, effects, + Affine, AppearanceItem, Arc, BezPath, Document, Effect, FillRule, GeomContext, Node, NodeKind, PathEl, Rect, Renderer, Shape, SymbolBoxes, + effects, }; fn node_bezpath(n: &Node) -> Option { @@ -232,6 +233,78 @@ pub(crate) fn drawn_outline(doc: &Document, n: &Node) -> Option<(BezPath, FillRu } } +/// Adds the outlines of `n` to `out`, one per object and without uniting them: the visible members of +/// a group, layer or intertwine (a Shaper group's without its source art) and the evaluated art of a +/// blend, envelope, repeat, Pathfinder result or object with object effects. A gradient mesh adds its +/// mesh lines and a symbol instance its bounds, as the selection highlight shows them; any other +/// object, a clip group included, adds [`drawn_outline`]. Each outline's points and each evaluated +/// object are taken from `left`; `None` when they do not fit in it. +pub(crate) fn drawn_outlines(doc: &Document, symbols: &SymbolBoxes, n: &Node, left: &mut usize, out: &mut Vec) -> Option<()> { + if let Some(art) = effects::crop_marks_art(n) { + return match art.children().and_then(|c| c.first()) { + Some(object) => drawn_outlines(doc, symbols, object, left, out), + None => Some(()), + }; + } + if has_object_fx(n) { + let makes_art = effects::has_revolve(n) || effects::has_solid(n) || effects::addons::halftone::has_halftone(n); + // Effects that leave a mesh's shape alone evaluate it to its many colored pieces. + if let NodeKind::Mesh(m) = &n.kind + && !makes_art + && !effects::has_geometry(&n.appearance.effects) + { + return push_outline(Some(m.lines().to_bezpath()), left, out); + } + let mut object = n.clone(); + // A group's own fills and strokes repeat its members' geometry as more art. + if is_container(n) && !makes_art && !effects::has_item_geometry(n) { + object.appearance.items.clear(); + } + let art = Renderer::new().fx_art(doc, &Arc::new(object), false); + if art.children().is_some() && !has_object_fx(&art) { + return evaluated_outlines(doc, symbols, &art, left, out); + } + return push_outline(effects::clip_outline(&art).map(|(path, _)| path), left, out); + } + if effects::has_pathfinder(n) + && let Some(art) = effects::evaluate_container(Some(doc), n).filter(|art| !effects::has_pathfinder(art)) + { + return evaluated_outlines(doc, symbols, &art, left, out); + } + match &n.kind { + NodeKind::Group { children, clip: false } | NodeKind::Layer { children, clip: false, .. } | NodeKind::Intertwine { children } => { + for c in children.iter().skip(usize::from(n.extras().shaper.is_some())).filter(|c| c.visible) { + drawn_outlines(doc, symbols, c, left, out)?; + } + Some(()) + } + NodeKind::Blend { .. } | NodeKind::Envelope { .. } | NodeKind::Repeat(_) => { + evaluated_outlines(doc, symbols, &effects::expanded_live_group(Some(doc), n), left, out) + } + NodeKind::Mesh(m) => push_outline(Some(m.lines().to_bezpath()), left, out), + NodeKind::SymbolInstance { .. } => { + push_outline(n.geometric_bounds_with(symbols).map(|b| vectorcraft_geom::shapes::rectangle(b).to_bezpath()), left, out) + } + _ => push_outline(drawn_outline(doc, n).map(|(path, _)| path), left, out), + } +} + +/// [`drawn_outlines`] of `art`, the evaluated form of a live object or an object with effects, with +/// each of its objects taken from `left`. +fn evaluated_outlines(doc: &Document, symbols: &SymbolBoxes, art: &Node, left: &mut usize, out: &mut Vec) -> Option<()> { + *left = left.checked_sub(art.children().map_or(0, Vec::len))?; + drawn_outlines(doc, symbols, art, left, out) +} + +/// Adds `path` to `out` with its points taken from `left`; `None` when they do not fit in it. +fn push_outline(path: Option, left: &mut usize, out: &mut Vec) -> Option<()> { + if let Some(path) = path { + *left = left.checked_sub(path.elements().iter().filter(|el| !matches!(el, PathEl::ClosePath)).count())?; + out.push(path); + } + Some(()) +} + /// How far raster effects `fx` paint beyond `b`, each spreading what the ones before it paint /// ([`spread`]). fn outset(symbols: &SymbolBoxes, fx: &[Effect], b: Rect) -> f64 { diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index 46a0ca64a2..68020dcfa0 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -224,7 +224,7 @@ mod renderer; mod text_geom; mod threads; -pub use bounds::{drawn_bounds, drawn_outline, effect_bounds, painted_bounds}; +pub use bounds::{drawn_bounds, drawn_outline, drawn_outlines, effect_bounds, painted_bounds}; pub use frame::FrameStats; use frame::{ClipEntry, ClipPaintEntry, Frame, FxArtEntry, GeomEntry, PlacedEntry, PlacedKey, PtrHasher, PtrMap, SliceEntry, StrokeEntry, StrokeKey}; #[cfg(test)] diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 7f0efd5064..4c65ec5f84 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -729,7 +729,8 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Preferences audit (2026-10-30, #394): every Preferences dialog option is read by shipped code, by its field or its key, except User Interface › Open Documents As Tabs, Units › East Asian Type, Hyphenation › Default Language, Plug-ins & Scratch Disks › Primary and Secondary, and Clipboard Handling › Legacy vector clipboard and its mode, which are stored only; [gaps.md G12](gaps.md#g12-preferences-and-panels-that-dont-act-yet) says what each waits on. - With Performance › Real-time Drawing and Editing off, the bounding box moves with a Selection-tool move drag and the object moves when the button is released ([help](https://web.archive.org/web/20220324053041id_/https://helpx.adobe.com/illustrator/using/real-time-editing.html); `real_time_drawing_off_moves_the_bounding_box_with_a_move_drag`). - Performance › Real-time Drawing and Editing off defers a drag's edits to its release, but a ruler guide dragged out of a ruler or moved still shows as it is dragged, where only its position label showed (#4646; `a_guide_dragged_out_of_a_ruler_shows_while_dragged`, `real_time_drawing_off_still_shows_a_dragged_guide`). - - With Real-time Drawing and Editing off, a dragged selection whose outlines have more than 100,000 points shows its moved bounds instead, as the selection at rest does (#525, #2460; `real_time_drawing_off_draws_the_bounds_of_a_selection_too_big_to_outline`). + - With Real-time Drawing and Editing off, a dragged selection whose outline points and evaluated objects come to more than 100,000 shows its moved bounds instead, as the selection at rest does (#525, #2460; `real_time_drawing_off_draws_the_bounds_of_a_selection_too_big_to_outline`, `real_time_drawing_off_draws_the_bounds_of_a_group_too_big_to_outline`, `real_time_drawing_off_draws_the_bounds_of_a_repeat_with_too_many_objects`). + - With Real-time Drawing and Editing off, a move or handle drag of a group, blend, envelope, repeat or intertwine draws the outline of each of its objects instead of one union of them, as VectorCraft's own rule (`real_time_drawing_off_outlines_a_dragged_group_member_by_member`, `real_time_drawing_off_outlines_a_resized_group_member_by_member`, `real_time_drawing_off_outlines_a_dragged_blend_step_by_step`, `real_time_drawing_off_outlines_a_dragged_envelope_object_by_object`). A group with a Pathfinder effect draws the area the effect makes, a gradient mesh draws its mesh lines, and a symbol instance draws its bounds (`real_time_drawing_off_outlines_a_dragged_pathfinder_group_by_its_area`, `real_time_drawing_off_outlines_each_mesh_of_a_dragged_repeat_once`, `real_time_drawing_off_outlines_a_dragged_symbol_instance_by_its_bounds`). - Dialogs move by dragging their heading (the band down from the top edge, as a title bar), stay on screen and keep where they were moved for the session; the form dialogs' choices are dropdowns (Offset Path's Joins, Average's and Shear's and Reflect's axis), and Offset Path lists Offset, Joins, Miter Limit and previews (#423). - Dialogs open with their first field focused and its value selected: type a value and press Enter (Move, Rotate, Scale…). A dialog opened from a menu takes the keyboard focus every time it opens, not only the first (#1367), and one whose first field starts greyed out (Blend Options on Smooth Color, Layers Panel Options) gives the focus to that field once it is enabled (#1395). Number fields in panels, the Control bar and dialogs (preferences too) step with Up/Down, or with the mouse wheel over the focused field (#485: a notch a step; the panel under it then stays put, and an unfocused field leaves the wheel to scrolling) (Shift: ten, Ctrl/Cmd: a tenth of their unit), applied at once. - While Alt (Option on macOS) is held, the Flare Tool Options' Cancel button reads Reset, which puts every option back to the Flare tool's default and leaves the dialog open (`ui.dialogReset`).