Skip to content

Commit f9bc097

Browse files
authored
Shapes: the 3- and 4-bend elbow and curved connectors follow presetShapeDefinitions (#1851)
* 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).
1 parent 6c52db0 commit f9bc097

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎crates/engine/src/cmd/shape/appearance.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(super) fn adjust(s: &mut Session, p: &Value) -> Result<Value> {
99
let v = f64_param(p, "value").ok_or_else(|| bad("shape.adjust", "missing `value`"))?;
1010
edit_geometry(s, p, "shape.adjust", |sh| {
1111
if let Geom::Preset { name, adj } = &mut sh.geom {
12-
let defaults = deckcraft_geom::preset::info(name).map(|x| x.defaults).unwrap_or(&[]);
12+
let defaults = deckcraft_geom::preset::adjust_defaults(name);
1313
while adj.len() <= i {
1414
let k = adj.len();
1515
adj.push(defaults.get(k).copied().unwrap_or(0.0));

‎crates/engine/src/tools/drag.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl Session {
293293
if let Some(sh) = deckcraft_model::find_shape_mut(list, id)
294294
&& let deckcraft_model::Geom::Preset { name, adj } = &mut sh.geom
295295
{
296-
let defaults = deckcraft_geom::preset::info(name).map(|x| x.defaults).unwrap_or(&[]);
296+
let defaults = deckcraft_geom::preset::adjust_defaults(name);
297297
for (i, v) in &vals {
298298
while adj.len() <= *i {
299299
let k = adj.len();

‎crates/pptx/src/read/shapes.rs‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn base(imp: &mut Imp, part: &Part, ctx: &mut IdCtx, nv: Option<&El>) -> Shape {
177177

178178
fn preset_geom(pg: &El) -> Geom {
179179
let name = pg.attr("prst").unwrap_or("rect").to_string();
180-
let defaults: Vec<f64> = preset::info(&name).map(|i| i.defaults.to_vec()).unwrap_or_default();
180+
let defaults: Vec<f64> = preset::adjust_defaults(&name).to_vec();
181181
let mut adj = defaults;
182182
let mut any = false;
183183
if let Some(av) = pg.child("avLst") {
@@ -897,3 +897,25 @@ fn cell(imp: &mut Imp, part: &Part, tc: &El) -> Cell {
897897
}
898898
c
899899
}
900+
901+
#[cfg(test)]
902+
mod preset_geom_tests {
903+
use super::*;
904+
905+
fn geom(xml: &str) -> Geom {
906+
let doc = crate::xml::parse(xml.as_bytes()).unwrap();
907+
preset_geom(&doc.root)
908+
}
909+
910+
// A file may give some adjust values and rely on the defaults for the rest. A preset outside the
911+
// gallery had no defaults, so a missing value read as 0: a bentConnector4 with only adj2 lost
912+
// its middle leg.
913+
#[test]
914+
fn a_missing_adjust_value_takes_the_spec_default() {
915+
let a = r#"xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main""#;
916+
let g = geom(&format!(r#"<a:prstGeom {a} prst="bentConnector4"><a:avLst><a:gd name="adj2" fmla="val 25000"/></a:avLst></a:prstGeom>"#));
917+
assert!(matches!(&g, Geom::Preset { name, adj } if name == "bentConnector4" && adj == &[50000.0, 25000.0]), "{g:?}");
918+
let g = geom(&format!(r#"<a:prstGeom {a} prst="bentConnector5"><a:avLst><a:gd name="adj3" fmla="val 10000"/></a:avLst></a:prstGeom>"#));
919+
assert!(matches!(&g, Geom::Preset { adj, .. } if adj == &[50000.0, 50000.0, 10000.0]), "{g:?}");
920+
}
921+
}

‎crates/pptx/src/write/shapes.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn geometry(w: &mut W, g: &Geom) {
9494
w.empty0("a:avLst");
9595
} else {
9696
// PowerPoint wants the complete guide list once any is given.
97-
let defaults = deckcraft_geom::preset::info(name).map(|i| i.defaults).unwrap_or(&[]);
97+
let defaults = deckcraft_geom::preset::adjust_defaults(name);
9898
let mut vals: Vec<f64> = adj.iter().take(16).copied().collect();
9999
while vals.len() < defaults.len() {
100100
vals.push(defaults.get(vals.len()).copied().unwrap_or(0.0));

0 commit comments

Comments
 (0)