mirror of
https://github.com/storytold/deckcraft.git
synced 2026-11-17 15:44:44 +00:00
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).
This commit is contained in:
1 parent
6c52db0172
commit
f9bc097b4e
4 files changed
+26
-4
No files matched your search
@@ -9,7 +9,7 @@ pub(super) fn adjust(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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));
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<f64> = preset::info(&name).map(|i| i.defaults.to_vec()).unwrap_or_default();
|
||||
let defaults: Vec<f64> = 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#"<a:prstGeom {a} prst="bentConnector4"><a:avLst><a:gd name="adj2" fmla="val 25000"/></a:avLst></a:prstGeom>"#));
|
||||
assert!(matches!(&g, Geom::Preset { name, adj } if name == "bentConnector4" && adj == &[50000.0, 25000.0]), "{g:?}");
|
||||
let g = geom(&format!(r#"<a:prstGeom {a} prst="bentConnector5"><a:avLst><a:gd name="adj3" fmla="val 10000"/></a:avLst></a:prstGeom>"#));
|
||||
assert!(matches!(&g, Geom::Preset { adj, .. } if adj == &[50000.0, 50000.0, 10000.0]), "{g:?}");
|
||||
}
|
||||
}
|
||||
@@ -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<f64> = adj.iter().take(16).copied().collect();
|
||||
while vals.len() < defaults.len() {
|
||||
vals.push(defaults.get(vals.len()).copied().unwrap_or(0.0));
|
||||
|
||||
Reference in new issue
Block a user