From f9bc097b4ef92e6b39725ea94716a5787e6565fc Mon Sep 17 00:00:00 2001 From: Hamza Naveed <45464935+Hamza0101@users.noreply.github.com> Date: Mon, 16 Nov 2026 19:39:49 +0500 Subject: [PATCH] Shapes: the 3- and 4-bend elbow and curved connectors follow presetShapeDefinitions (#1851) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Shapes: the 3- and 4-bend elbow and curved connectors follow presetShapeDefinitions PowerPoint routes connectors around shapes with bentConnector4 and 5 and their curved counterparts. They were drawn as bentConnector3 and curvedConnector3, using adj1 alone, and curvedConnector2 as a two-cubic S where the spec has one cubic. Each now draws the spec's path, and the elbows get a handle per adjust value where the spec puts it. None of these is in the gallery, so their adjust values had no defaults: a file giving none, or only adj2, drew them at 0. adjust_defaults() adds the spec's 50000s for presets outside the gallery, and the reader, writer, Adjust command and handle drag use it. * Shapes: elbow handles take the spec's whole adjust range The handles clamped a dragged value to ±1000000, so dragging one on an imported route with a value beyond that moved the route. They now take presetShapeDefinitions' ±2147483647 (noted in review). --- crates/engine/src/cmd/shape/appearance.rs | 2 +- crates/engine/src/tools/drag.rs | 2 +- crates/pptx/src/read/shapes.rs | 24 ++++++++++++++++++++++- crates/pptx/src/write/shapes.rs | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/shape/appearance.rs b/crates/engine/src/cmd/shape/appearance.rs index 4dd406ea3..c9a318abc 100644 --- a/crates/engine/src/cmd/shape/appearance.rs +++ b/crates/engine/src/cmd/shape/appearance.rs @@ -9,7 +9,7 @@ pub(super) fn adjust(s: &mut Session, p: &Value) -> Result { let v = f64_param(p, "value").ok_or_else(|| bad("shape.adjust", "missing `value`"))?; edit_geometry(s, p, "shape.adjust", |sh| { if let Geom::Preset { name, adj } = &mut sh.geom { - let defaults = deckcraft_geom::preset::info(name).map(|x| x.defaults).unwrap_or(&[]); + let defaults = deckcraft_geom::preset::adjust_defaults(name); while adj.len() <= i { let k = adj.len(); adj.push(defaults.get(k).copied().unwrap_or(0.0)); diff --git a/crates/engine/src/tools/drag.rs b/crates/engine/src/tools/drag.rs index 41ade3266..7e8b93a74 100644 --- a/crates/engine/src/tools/drag.rs +++ b/crates/engine/src/tools/drag.rs @@ -293,7 +293,7 @@ impl Session { if let Some(sh) = deckcraft_model::find_shape_mut(list, id) && let deckcraft_model::Geom::Preset { name, adj } = &mut sh.geom { - let defaults = deckcraft_geom::preset::info(name).map(|x| x.defaults).unwrap_or(&[]); + let defaults = deckcraft_geom::preset::adjust_defaults(name); for (i, v) in &vals { while adj.len() <= *i { let k = adj.len(); diff --git a/crates/pptx/src/read/shapes.rs b/crates/pptx/src/read/shapes.rs index b6b1c882b..bcef9f8c5 100644 --- a/crates/pptx/src/read/shapes.rs +++ b/crates/pptx/src/read/shapes.rs @@ -177,7 +177,7 @@ fn base(imp: &mut Imp, part: &Part, ctx: &mut IdCtx, nv: Option<&El>) -> Shape { fn preset_geom(pg: &El) -> Geom { let name = pg.attr("prst").unwrap_or("rect").to_string(); - let defaults: Vec = preset::info(&name).map(|i| i.defaults.to_vec()).unwrap_or_default(); + let defaults: Vec = preset::adjust_defaults(&name).to_vec(); let mut adj = defaults; let mut any = false; if let Some(av) = pg.child("avLst") { @@ -897,3 +897,25 @@ fn cell(imp: &mut Imp, part: &Part, tc: &El) -> Cell { } c } + +#[cfg(test)] +mod preset_geom_tests { + use super::*; + + fn geom(xml: &str) -> Geom { + let doc = crate::xml::parse(xml.as_bytes()).unwrap(); + preset_geom(&doc.root) + } + + // A file may give some adjust values and rely on the defaults for the rest. A preset outside the + // gallery had no defaults, so a missing value read as 0: a bentConnector4 with only adj2 lost + // its middle leg. + #[test] + fn a_missing_adjust_value_takes_the_spec_default() { + let a = r#"xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main""#; + let g = geom(&format!(r#""#)); + assert!(matches!(&g, Geom::Preset { name, adj } if name == "bentConnector4" && adj == &[50000.0, 25000.0]), "{g:?}"); + let g = geom(&format!(r#""#)); + assert!(matches!(&g, Geom::Preset { adj, .. } if adj == &[50000.0, 50000.0, 10000.0]), "{g:?}"); + } +} diff --git a/crates/pptx/src/write/shapes.rs b/crates/pptx/src/write/shapes.rs index 4b32264ff..df7a226df 100644 --- a/crates/pptx/src/write/shapes.rs +++ b/crates/pptx/src/write/shapes.rs @@ -94,7 +94,7 @@ pub fn geometry(w: &mut W, g: &Geom) { w.empty0("a:avLst"); } else { // PowerPoint wants the complete guide list once any is given. - let defaults = deckcraft_geom::preset::info(name).map(|i| i.defaults).unwrap_or(&[]); + let defaults = deckcraft_geom::preset::adjust_defaults(name); let mut vals: Vec = adj.iter().take(16).copied().collect(); while vals.len() < defaults.len() { vals.push(defaults.get(vals.len()).copied().unwrap_or(0.0));