From 746d6e33df4d61cbe7dcfbbd84408d4f71157cd8 Mon Sep 17 00:00:00 2001 From: Hamza Naveed <45464935+Hamza0101@users.noreply.github.com> Date: Tue, 17 Nov 2026 07:30:24 +0500 Subject: [PATCH] craft-drawingml: elbow connector handles take the spec's whole adjust range (#1892) --- crates/drawingml/src/preset/build.rs | 17 +++++++++++------ crates/drawingml/src/preset/tests.rs | 11 +++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/crates/drawingml/src/preset/build.rs b/crates/drawingml/src/preset/build.rs index f8996a93c..30019804f 100644 --- a/crates/drawingml/src/preset/build.rs +++ b/crates/drawingml/src/preset/build.rs @@ -1115,6 +1115,9 @@ fn flowchart_and_star_shapes(c: &Ctx) -> Option { Some(g) } +/// The range presetShapeDefinitions gives the elbows' handles (`minX` / `maxX`, `minY` / `maxY`). +const ADJ_LIMIT: f64 = 2_147_483_647.0; + fn callout_wave_and_connector_shapes(c: &Ctx) -> Option { let name = c.name; let w = c.w; @@ -1197,28 +1200,30 @@ fn callout_wave_and_connector_shapes(c: &Ctx) -> Option { } // The elbows of ECMA-376's presetShapeDefinitions: 3 has one middle leg, 4 adds a // horizontal one at `adj2`, 5 a third vertical one at `adj3`. 4 and 5 were drawn as 3. + // Their handles take the spec's whole range (its `ahXY` min and max), so dragging one + // never clamps a value an imported route uses. "bentConnector3" => { let x1 = w * a(0) / 1e5; let l = Pb::new().m(0.0, 0.0).l(x1, 0.0).l(x1, h).l(w, h).take(); let mut g = Geometry { paths: vec![stroke_only(l)], text_rect: full, handles: vec![], sites: vec![Point::ZERO, Point::new(w, h)] }; - g.handles.push(Handle::new(0, Point::new(0.0, h / 2.0), Vec2::new(w / 1e5, 0.0), a(0), -1e6, 1e6)); + g.handles.push(Handle::new(0, Point::new(0.0, h / 2.0), Vec2::new(w / 1e5, 0.0), a(0), -ADJ_LIMIT, ADJ_LIMIT)); g } "bentConnector4" => { let (x1, y2) = (w * a(0) / 1e5, h * a(1) / 1e5); let l = Pb::new().m(0.0, 0.0).l(x1, 0.0).l(x1, y2).l(w, y2).l(w, h).take(); let mut g = Geometry { paths: vec![stroke_only(l)], text_rect: full, handles: vec![], sites: vec![Point::ZERO, Point::new(w, h)] }; - g.handles.push(Handle::new(0, Point::new(0.0, y2 / 2.0), Vec2::new(w / 1e5, 0.0), a(0), -1e6, 1e6)); - g.handles.push(Handle::new(1, Point::new((x1 + w) / 2.0, 0.0), Vec2::new(0.0, h / 1e5), a(1), -1e6, 1e6)); + g.handles.push(Handle::new(0, Point::new(0.0, y2 / 2.0), Vec2::new(w / 1e5, 0.0), a(0), -ADJ_LIMIT, ADJ_LIMIT)); + g.handles.push(Handle::new(1, Point::new((x1 + w) / 2.0, 0.0), Vec2::new(0.0, h / 1e5), a(1), -ADJ_LIMIT, ADJ_LIMIT)); g } "bentConnector5" => { let (x1, y2, x3) = (w * a(0) / 1e5, h * a(1) / 1e5, w * a(2) / 1e5); let l = Pb::new().m(0.0, 0.0).l(x1, 0.0).l(x1, y2).l(x3, y2).l(x3, h).l(w, h).take(); let mut g = Geometry { paths: vec![stroke_only(l)], text_rect: full, handles: vec![], sites: vec![Point::ZERO, Point::new(w, h)] }; - g.handles.push(Handle::new(0, Point::new(0.0, y2 / 2.0), Vec2::new(w / 1e5, 0.0), a(0), -1e6, 1e6)); - g.handles.push(Handle::new(1, Point::new((x1 + x3) / 2.0, 0.0), Vec2::new(0.0, h / 1e5), a(1), -1e6, 1e6)); - g.handles.push(Handle::new(2, Point::new(0.0, (y2 + h) / 2.0), Vec2::new(w / 1e5, 0.0), a(2), -1e6, 1e6)); + g.handles.push(Handle::new(0, Point::new(0.0, y2 / 2.0), Vec2::new(w / 1e5, 0.0), a(0), -ADJ_LIMIT, ADJ_LIMIT)); + g.handles.push(Handle::new(1, Point::new((x1 + x3) / 2.0, 0.0), Vec2::new(0.0, h / 1e5), a(1), -ADJ_LIMIT, ADJ_LIMIT)); + g.handles.push(Handle::new(2, Point::new(0.0, (y2 + h) / 2.0), Vec2::new(w / 1e5, 0.0), a(2), -ADJ_LIMIT, ADJ_LIMIT)); g } // The curved connectors follow the same legs with cubic Béziers. diff --git a/crates/drawingml/src/preset/tests.rs b/crates/drawingml/src/preset/tests.rs index 0427d1a3e..deddd5fb8 100644 --- a/crates/drawingml/src/preset/tests.rs +++ b/crates/drawingml/src/preset/tests.rs @@ -452,6 +452,17 @@ fn the_three_and_four_bend_elbows_follow_their_adjust_values() { let g = build("bentConnector5", 200.0, 100.0, &[25000.0, 75000.0, 60000.0]).unwrap(); let pos: Vec<(f64, f64)> = g.handles.iter().map(|h| (h.pos.x, h.pos.y)).collect(); assert_eq!(pos, [(50.0, 37.5), (85.0, 75.0), (120.0, 87.5)]); + // A handle dragged far out keeps the value: the spec's range is ±2147483647, and PowerPoint's + // routing gives a thin connector box values well beyond ±1000000 (a leg 50 pt beside a 1 pt + // wide box is 5000000). + for name in ["bentConnector3", "bentConnector4", "bentConnector5"] { + let g = build(name, 200.0, 100.0, &[]).unwrap(); + for h in &g.handles { + for v in [5_000_000.0, -5_000_000.0] { + assert_eq!(h.value_at(h.origin + h.dir * v), v, "{name} handle {}", h.index); + } + } + } } // curvedConnector2 is one cubic (l,t)…(r,b) through (wd2,t) and (r,hd2); 4 and 5 bend at the same