mirror of
https://github.com/storytold/deckcraft.git
synced 2026-11-10 12:29:34 -06:00
Merge branch 'main' into copy-the-fix
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
use super::{
|
||||
Arc, Fill, NO_ID_SPACE, PhType, Result, Run, RunKind, Session, Shape, ShapeId, Size, Target, TextBody, Value, bad, bool_param, json,
|
||||
master_index, ok, opt_usize_param, rect_param, str_param, usize_param,
|
||||
master_index, ok, opt_usize_param, rect_param, str_param,
|
||||
};
|
||||
|
||||
pub(super) fn master_view(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let st = s.doc()?;
|
||||
let mi = usize_param(p, "master").unwrap_or_else(|| master_index(&st.doc, &st.selection));
|
||||
let mi = opt_usize_param(p, "master", "view.slideMaster")?.unwrap_or_else(|| master_index(&st.doc, &st.selection));
|
||||
// A master thumbnail sends `{master}` and means the master itself. `{master, layout}` selects
|
||||
// that layout. With neither key, follow the current slide's layout.
|
||||
let layout = if p.get("master").is_some() && p.get("layout").is_none() {
|
||||
None
|
||||
} else {
|
||||
usize_param(p, "layout")
|
||||
opt_usize_param(p, "layout", "view.slideMaster")?
|
||||
.or_else(|| st.current_slide().and_then(|sl| st.doc.masters.get(mi).and_then(|m| m.layouts.iter().position(|l| l.id == sl.layout))))
|
||||
};
|
||||
let target = match layout {
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
use super::{
|
||||
Arc, BTreeSet, Background, Fill, NO_ID_SPACE, Presentation, Result, Session, Target, Value, bad, bool_or, bool_param, color_param, color_value,
|
||||
f64_param, ok, usize_param, with_param,
|
||||
f64_param, ok, opt_usize_param, usize_param, with_param,
|
||||
};
|
||||
|
||||
pub(super) fn background(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if bool_or(p, "copy", false) {
|
||||
return copy_slide_background(s);
|
||||
}
|
||||
// Check the index before anything is edited: a picture is added to the media first.
|
||||
let index = opt_usize_param(p, "index", "design.background")?;
|
||||
let props = p.get("pictureProps").filter(|v| v.is_object()).cloned();
|
||||
let transparency = f64_param(p, "transparency");
|
||||
let reset = bool_or(p, "reset", false);
|
||||
@@ -62,7 +64,6 @@ pub(super) fn background(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
));
|
||||
};
|
||||
let all = bool_or(p, "all", false);
|
||||
let index = usize_param(p, "index");
|
||||
if matches!(op, BgOp::Adjust) {
|
||||
let next = {
|
||||
let st = s.doc()?;
|
||||
|
||||
@@ -485,3 +485,16 @@ fn background_all_clears_layout_overrides_even_if_slides_and_master_match() {
|
||||
s.execute("design.background", &json!({"color": "#AA0000", "all": true})).unwrap();
|
||||
assert_eq!(undo_len(&s), n + 1, "now it is truly a no-op");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn background_rejects_invalid_index() {
|
||||
let mut s = Session::with_new();
|
||||
s.execute("slide.new", &json!({})).unwrap();
|
||||
s.execute("slide.go", &json!({"index": 0})).unwrap();
|
||||
let before = s.doc().unwrap().doc.slides[0].background.clone();
|
||||
for bad in [json!(-1), json!(1.5)] {
|
||||
assert!(s.execute("design.background", &json!({"color": "#0000C8", "index": bad})).is_err());
|
||||
assert!(s.execute("design.background", &json!({"transparency": 0.5, "index": bad})).is_err());
|
||||
assert_eq!(s.doc().unwrap().doc.slides[0].background, before);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,6 +345,7 @@ pub fn save_bytes(doc: &Presentation, format: &str) -> Result<Vec<u8>> {
|
||||
"rtf" => Ok(deckcraft_format::rtf::slides_to_rtf(doc).into_bytes()),
|
||||
"pdf" => deckcraft_pdf::export(doc, &Default::default()).map_err(|e| EngineError::Other(e.to_string())),
|
||||
"gif" => gif_bytes(doc, &Value::Null),
|
||||
"png" | "jpeg" | "jpg" => Err(EngineError::Other("saving a presentation as a single image isn't supported; use file.export".into())),
|
||||
_ => deckcraft_format::save(doc).map_err(|e| EngineError::Other(e.to_string())),
|
||||
}
|
||||
}
|
||||
@@ -359,7 +360,13 @@ pub fn pdf_options(p: &Value, count: usize) -> Result<deckcraft_pdf::PdfOptions>
|
||||
let mut o = deckcraft_pdf::PdfOptions { layout: deckcraft_pdf::PageLayout::Slides, ..Default::default() };
|
||||
o.layout = match str_param(p, "layout").unwrap_or("slides") {
|
||||
"notes" => deckcraft_pdf::PageLayout::Notes,
|
||||
"handouts" => deckcraft_pdf::PageLayout::Handouts { per_page: usize_param(p, "perPage").unwrap_or(6).clamp(1, 9) as u8 },
|
||||
"handouts" => {
|
||||
let per_page = opt_usize_param(p, "perPage", "file.export")?.unwrap_or(6);
|
||||
if ![1, 2, 3, 4, 6, 9].contains(&per_page) {
|
||||
return Err(bad("file.export", format!("perPage {per_page} isn't one of 1, 2, 3, 4, 6, 9")));
|
||||
}
|
||||
deckcraft_pdf::PageLayout::Handouts { per_page: per_page as u8 }
|
||||
}
|
||||
_ => deckcraft_pdf::PageLayout::Slides,
|
||||
};
|
||||
o.dpi = f64_or(p, "dpi", o.dpi).clamp(36.0, 600.0);
|
||||
|
||||
@@ -55,6 +55,7 @@ pub(super) fn bullets(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
if size.is_some() {
|
||||
para.props.bullet_size = size;
|
||||
para.props.bullet_size_points = None;
|
||||
para.props.bullet_size_follow_text = None;
|
||||
}
|
||||
if para.props.indent.is_none_or(|i| i >= 0.0) && para.props.margin_left.is_none_or(|m| m == 0.0) {
|
||||
@@ -85,6 +86,7 @@ pub(super) fn numbering(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
if size.is_some() {
|
||||
para.props.bullet_size = size;
|
||||
para.props.bullet_size_points = None;
|
||||
para.props.bullet_size_follow_text = None;
|
||||
}
|
||||
para.props.margin_left = Some(27.0 + 36.0 * para.level as f64);
|
||||
|
||||
@@ -103,7 +103,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Shape Fill",
|
||||
["Shape Format", "Shape Styles"],
|
||||
None,
|
||||
"{color? | none?: true | background?: true (the slide background shows through; shapes and text boxes only) | gradient?: {stops: [[pos, color]], angle?, kind?: linear|radial} | picture?: base64 | pattern?: {preset, fg, bg} | transparency?: 0..1 | reset?: true, ids?}; pictureProps?: {tile?: bool, offsetX?, offsetY?: pt, scaleX?, scaleY?: 0..10, align?: tl|t|tr|l|ctr|r|bl|b|br, mirror?: none|x|y|xy, stretch?: [l, t, r, b] fractions, rotateWithShape?: bool} adjusts a picture fill; a group also formats its members",
|
||||
"{color? | none?: true | background?: true (the slide background shows through; shapes and text boxes only) | gradient?: {stops: [[pos 0..1, color]], kind?: linear|radial|rectangular|path, angle?: deg (linear), focus?: [l, t, r, b] fractions (radial, rectangular and path: where the first stop sits), rotateWithShape?: bool} | picture?: base64 | pattern?: {preset, fg, bg} | transparency?: 0..1 | reset?: true, ids?}; pictureProps?: {tile?: bool, offsetX?, offsetY?: pt, scaleX?, scaleY?: 0..10, align?: tl|t|tr|l|ctr|r|bl|b|br, mirror?: none|x|y|xy, stretch?: [l, t, r, b] fractions, rotateWithShape?: bool} adjusts a picture fill; a group also formats its members",
|
||||
has_selection,
|
||||
fill
|
||||
),
|
||||
|
||||
+17
-2
@@ -41,12 +41,13 @@ pub fn write_file(path: &str, bytes: &[u8]) -> Result<(), String> {
|
||||
Ok(canonical) => canonical,
|
||||
Err(_) => std::path::PathBuf::from(path),
|
||||
};
|
||||
let target_str = target_path.to_str().unwrap_or(path);
|
||||
let existing_perms = std::fs::metadata(&target_path).ok().map(|m| m.permissions());
|
||||
|
||||
let mut attempts = 0;
|
||||
let (tmp, mut file) = loop {
|
||||
let tmp = format!("{target_str}.{}.{}.saving", std::process::id(), COUNTER.fetch_add(1, Ordering::Relaxed));
|
||||
// A short fixed-size name: appending to the target's name could exceed the file name limit.
|
||||
let tmp_name = format!(".deckcraft.{}.{}.saving", std::process::id(), COUNTER.fetch_add(1, Ordering::Relaxed));
|
||||
let tmp = target_path.with_file_name(tmp_name);
|
||||
match std::fs::OpenOptions::new().write(true).create_new(true).open(&tmp) {
|
||||
Ok(f) => break (tmp, f),
|
||||
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists && attempts < 16 => attempts += 1,
|
||||
@@ -120,4 +121,18 @@ mod tests {
|
||||
let _ = std::fs::remove_file(&test_file);
|
||||
let _ = std::fs::remove_dir(&tmp_dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_file_overwrites_file_with_name_near_the_length_limit() {
|
||||
let dir = std::env::temp_dir().join("deckcraft_io_long_name_test");
|
||||
let _ = std::fs::create_dir_all(&dir);
|
||||
let file = dir.join(format!("{}.pptx", "a".repeat(250)));
|
||||
std::fs::write(&file, b"old").unwrap();
|
||||
let path_str = file.to_str().unwrap();
|
||||
|
||||
write_file(path_str, b"new").unwrap();
|
||||
assert_eq!(read_file(path_str).unwrap(), b"new");
|
||||
|
||||
let _ = std::fs::remove_file(&file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -709,7 +709,8 @@ pub fn paragraph_words(p: &deckcraft_model::Paragraph, default: &str) -> Vec<Wor
|
||||
chars.extend(r.content().chars().map(|c| (c, ri)));
|
||||
}
|
||||
let lang_of = |ri: usize| p.runs.get(ri).and_then(|r| r.props.lang.clone()).filter(|l| !l.is_empty()).unwrap_or_else(|| default.to_string());
|
||||
let inside = |c: char| c.is_alphanumeric() || c == '\'' || c == '’' || c == '-';
|
||||
// Combining marks (decomposed accents) belong to the letter before them.
|
||||
let inside = |c: char| c.is_alphanumeric() || deckcraft_model::words::is_combining_mark(c) || c == '\'' || c == '’' || c == '-';
|
||||
let mut out = vec![];
|
||||
let mut i = 0;
|
||||
while i < chars.len() {
|
||||
@@ -725,8 +726,14 @@ pub fn paragraph_words(p: &deckcraft_model::Paragraph, default: &str) -> Vec<Wor
|
||||
while a < b && !chars[a].0.is_alphanumeric() {
|
||||
a += 1;
|
||||
}
|
||||
while b > a && !chars[b - 1].0.is_alphanumeric() {
|
||||
b -= 1;
|
||||
// Trim back to the last letter or digit, keeping only the marks that sit on it
|
||||
// (a mark on a trailing apostrophe goes with the apostrophe).
|
||||
while b > a {
|
||||
let k = (a..b).rev().find(|&k| !deckcraft_model::words::is_combining_mark(chars[k].0)).unwrap_or(a);
|
||||
if chars[k].0.is_alphanumeric() {
|
||||
break;
|
||||
}
|
||||
b = k;
|
||||
}
|
||||
let text: String = chars[a..b].iter().map(|c| c.0).collect();
|
||||
if text.is_empty() || text.chars().any(|c| c.is_ascii_digit()) || !text.chars().any(char::is_alphabetic) {
|
||||
@@ -819,6 +826,20 @@ SFX D Y 1\nSFX D 0 ed/S .\n";
|
||||
Dictionary::parse(AFF.as_bytes(), DIC.as_bytes())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nfd_word_not_split() {
|
||||
let p = deckcraft_model::Paragraph::new("Das na\u{ef}ve Caf\u{e9} und cafe\u{301} na\u{308}ive");
|
||||
let w: Vec<String> = paragraph_words(&p, "en-US").into_iter().map(|w| w.text).collect();
|
||||
assert_eq!(w, ["Das", "na\u{ef}ve", "Caf\u{e9}", "und", "cafe\u{301}", "na\u{308}ive"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_mark_on_trailing_punctuation_is_trimmed_with_it() {
|
||||
let p = deckcraft_model::Paragraph::new("word'\u{301} cafe\u{301}' x");
|
||||
let w: Vec<String> = paragraph_words(&p, "en-US").into_iter().map(|w| w.text).collect();
|
||||
assert_eq!(w, ["word", "cafe\u{301}", "x"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn curly_apostrophe_matches_ascii_entry() {
|
||||
let d = Dictionary::parse(AFF.as_bytes(), "2\ndon't\nwork\n".as_bytes());
|
||||
|
||||
@@ -2595,6 +2595,23 @@ fn pdf_options_take_paper_and_orientation() {
|
||||
assert!(cmd::file::pdf_options(&json!({"orientation": "sideways"}), 1).is_err());
|
||||
}
|
||||
|
||||
/// Handout `perPage` accepts only 1, 2, 3, 4, 6 and 9; anything else is an error, not a 9-up page.
|
||||
#[test]
|
||||
fn pdf_options_reject_unsupported_per_page() {
|
||||
for n in [1, 2, 3, 4, 6, 9] {
|
||||
let o = cmd::file::pdf_options(&json!({"layout": "handouts", "perPage": n}), 1).unwrap();
|
||||
assert!(matches!(o.layout, deckcraft_pdf::PageLayout::Handouts { per_page } if per_page as usize == n));
|
||||
}
|
||||
for n in [0, 5, 7, 8, 10] {
|
||||
let e = cmd::file::pdf_options(&json!({"layout": "handouts", "perPage": n}), 1).unwrap_err();
|
||||
assert!(e.to_string().contains("1, 2, 3, 4, 6, 9"), "perPage {n}: {e}");
|
||||
}
|
||||
// Not a count at all: refused too, instead of falling back to 6.
|
||||
for v in [json!(-1), json!(5.5), json!("6")] {
|
||||
assert!(cmd::file::pdf_options(&json!({"layout": "handouts", "perPage": v}), 1).is_err(), "perPage {v}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shape_line_sets_compound_and_arrow_sizes() {
|
||||
// The Format Shape pane's Line page: compound type, arrowheads and their sizes.
|
||||
@@ -3391,6 +3408,7 @@ fn numbering_takes_color_and_size() {
|
||||
props.bullet_font_follow_text = Some(true);
|
||||
props.bullet_color_follow_text = Some(true);
|
||||
props.bullet_size_follow_text = Some(true);
|
||||
props.bullet_size_points = Some(12.0);
|
||||
}
|
||||
s.execute("format.numbering", &json!({"on": true, "scheme": "romanUcPeriod", "start": 3, "color": "accent2", "size": 150})).unwrap();
|
||||
let para = |s: &Session| {
|
||||
@@ -3404,9 +3422,11 @@ fn numbering_takes_color_and_size() {
|
||||
assert_eq!(pp.bullet_font_follow_text, Some(true));
|
||||
assert_eq!(pp.bullet_color_follow_text, None);
|
||||
assert_eq!(pp.bullet_size_follow_text, None);
|
||||
assert_eq!(pp.bullet_size_points, None);
|
||||
assert_eq!(pp.bullet_color, Some(deckcraft_model::ColorRef::scheme(deckcraft_color::SchemeSlot::Accent2)));
|
||||
s.execute("format.bullets", &json!({"on": true, "char": "★", "size": 9000})).unwrap();
|
||||
assert_eq!(para(&s).bullet_size, Some(4.0));
|
||||
assert_eq!(para(&s).bullet_size_points, None);
|
||||
assert_eq!(para(&s).bullet_font_follow_text, None);
|
||||
}
|
||||
|
||||
@@ -4479,6 +4499,38 @@ fn a_params_doc_spells_out_each_parameter() {
|
||||
);
|
||||
}
|
||||
|
||||
/// `shape.fill`'s params doc names each key and kind its `gradient` takes.
|
||||
#[test]
|
||||
fn shape_fill_documents_each_gradient_key_and_kind() {
|
||||
use deckcraft_model::style::GradientShape;
|
||||
let params = cmd::parse_params(find_command("shape.fill").unwrap().params).unwrap();
|
||||
let about = params.iter().find(|p| p.name == "gradient").unwrap().about;
|
||||
assert_eq!(cmd::param_keys(about).unwrap(), ["stops", "kind", "angle", "focus", "rotateWithShape"]);
|
||||
for kind in ["linear", "radial", "rectangular", "path"] {
|
||||
assert!(about.contains(kind), "{kind}: {about}");
|
||||
let g = cmd::shape::gradient_param(&json!({
|
||||
"stops": [[0, "#ffffff"], [1, "#000000"]],
|
||||
"kind": kind,
|
||||
"angle": 30,
|
||||
"focus": [0, 0, 1, 1],
|
||||
"rotateWithShape": false
|
||||
}))
|
||||
.unwrap();
|
||||
assert!(!g.rotate_with_shape, "{kind}");
|
||||
match g.shape {
|
||||
GradientShape::Linear { angle, .. } => assert_eq!((kind, angle), ("linear", 30.0)),
|
||||
GradientShape::Path { path, focus } => {
|
||||
let expected = match kind {
|
||||
"radial" => "circle",
|
||||
"rectangular" => "rect",
|
||||
_ => "shape",
|
||||
};
|
||||
assert_eq!((path.as_str(), focus), (expected, [0.0, 0.0, 1.0, 1.0]), "{kind}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn what_a_command_acts_on_names_only_keys_it_takes() {
|
||||
for c in command_specs() {
|
||||
@@ -5757,6 +5809,170 @@ fn edit_points_conversion_is_one_undo_step() {
|
||||
assert!(preset(&s), "the only step was the conversion");
|
||||
}
|
||||
|
||||
/// #1621: build overlapping objects with an ordinary quick style on the foreground shape.
|
||||
fn no_fill_overlap(s: &mut Session, text: bool) -> (ShapeId, ShapeId) {
|
||||
s.execute("slide.new", &json!({"layout": "blank"})).unwrap();
|
||||
let under = s
|
||||
.execute(
|
||||
if text { "insert.textBox" } else { "shape.insert" },
|
||||
&json!({"preset": "rect", "rect": [100, 300, 300, 60], "text": if text { "UNDERLYING TEXT" } else { "" }}),
|
||||
)
|
||||
.unwrap()["id"]
|
||||
.as_u64()
|
||||
.unwrap();
|
||||
let over = s.execute("shape.insert", &json!({"preset": "rect", "rect": [80, 270, 350, 140]})).unwrap()["id"].as_u64().unwrap();
|
||||
(ShapeId(under as u32), ShapeId(over as u32))
|
||||
}
|
||||
|
||||
/// No Fill passes interior clicks through while preserving outline and actual-fill targets.
|
||||
#[test]
|
||||
fn no_fill_shape_allows_selecting_and_editing_underlying_text() {
|
||||
let mut s = session();
|
||||
let (under, over) = no_fill_overlap(&mut s, true);
|
||||
s.execute("shape.fill", &json!({"none": true})).unwrap();
|
||||
assert!(s.doc().unwrap().shape(over).unwrap().style.is_some(), "the ordinary quick style remains");
|
||||
s.execute("edit.deselect", &json!({})).unwrap();
|
||||
let p = deckcraft_geom::Point::new(200.0, 310.0);
|
||||
assert!(matches!(s.hit_test(p, 3.0), Some(tools::Hit::Shape { id, .. }) if id == under));
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(tev(kind, p.x, p.y)).unwrap();
|
||||
}
|
||||
assert_eq!(s.doc().unwrap().selection.shapes, vec![under]);
|
||||
assert_eq!(text_sel(&s).unwrap().shape, under);
|
||||
// The transparent foreground also leaves an already-active text editor's caret alone.
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(tev(kind, p.x + 20.0, p.y)).unwrap();
|
||||
}
|
||||
assert_eq!(text_sel(&s).unwrap().shape, under);
|
||||
s.execute("edit.deselect", &json!({})).unwrap();
|
||||
// The rectangle's outline is still a target, and selecting it does not remove its style.
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(tev(kind, 80.0, 330.0)).unwrap();
|
||||
}
|
||||
assert_eq!(s.doc().unwrap().selection.shapes, vec![over]);
|
||||
assert!(s.doc().unwrap().shape(over).unwrap().style.is_some());
|
||||
// A real fill still catches clicks, even with 100% transparency (distinct from No Fill).
|
||||
for transparency in [0.0, 1.0] {
|
||||
s.execute("edit.select", &json!({"ids": [over.0]})).unwrap();
|
||||
s.execute("shape.fill", &json!({"color": "#336699", "transparency": transparency})).unwrap();
|
||||
s.execute("edit.deselect", &json!({})).unwrap();
|
||||
assert!(matches!(s.hit_test(p, 3.0), Some(tools::Hit::Shape { id, .. }) if id == over));
|
||||
}
|
||||
}
|
||||
|
||||
/// Rotation and pointer tolerance must preserve both pass-through interiors and outline hits.
|
||||
#[test]
|
||||
fn no_fill_shape_hit_testing_respects_rotation_and_pointer_tolerance() {
|
||||
let mut s = session();
|
||||
let (under, over) = no_fill_overlap(&mut s, false);
|
||||
s.execute("shape.fill", &json!({"none": true})).unwrap();
|
||||
s.execute("shape.rotate", &json!({"deg": 30})).unwrap();
|
||||
let x = s.doc().unwrap().shape(over).unwrap().xfrm.unwrap();
|
||||
let p = x.affine() * deckcraft_geom::Point::new(x.w / 2.0, x.h / 2.0);
|
||||
let edge = x.affine() * deckcraft_geom::Point::new(0.0, x.h / 4.0);
|
||||
for tol in [0.5, 3.0, 8.0] {
|
||||
s.execute("edit.deselect", &json!({})).unwrap();
|
||||
assert!(matches!(s.hit_test(p, tol), Some(tools::Hit::Shape { id, .. }) if id == under));
|
||||
assert!(matches!(s.hit_test(edge, tol), Some(tools::Hit::Shape { id, .. }) if id == over));
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(PointerEvent { tol, ..tev(kind, p.x, p.y) }).unwrap();
|
||||
}
|
||||
assert_eq!(s.doc().unwrap().selection.shapes, vec![under]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Style, theme and absent fills follow rendering, with explicit fill taking precedence.
|
||||
#[test]
|
||||
fn no_fill_hit_testing_resolves_style_and_theme_fills() {
|
||||
use std::sync::Arc;
|
||||
for source in ["style", "theme", "absent"] {
|
||||
let mut s = session();
|
||||
let (under, over) = no_fill_overlap(&mut s, true);
|
||||
{
|
||||
let st = s.doc_mut().unwrap();
|
||||
let doc = Arc::make_mut(&mut st.doc);
|
||||
if source == "theme" {
|
||||
Arc::make_mut(&mut doc.masters[0]).theme.format.fills[0] = model::Fill::None;
|
||||
}
|
||||
let sh = Arc::make_mut(&mut doc.slides[st.selection.slide]).shapes.iter_mut().find(|sh| sh.id == over).unwrap();
|
||||
assert!(sh.fill.is_none(), "the shape has no explicit fill override");
|
||||
if source == "absent" {
|
||||
sh.style = None;
|
||||
} else {
|
||||
sh.style.as_mut().unwrap().fill_ref.0 = if source == "style" { 0 } else { 1 };
|
||||
}
|
||||
}
|
||||
s.execute("edit.deselect", &json!({})).unwrap();
|
||||
let p = deckcraft_geom::Point::new(200.0, 310.0);
|
||||
assert!(matches!(s.hit_test(p, 3.0), Some(tools::Hit::Shape { id, .. }) if id == under), "{source}");
|
||||
// An explicit fill takes precedence over the no-fill style/theme.
|
||||
s.execute("edit.select", &json!({"ids": [over.0]})).unwrap();
|
||||
s.execute("shape.fill", &json!({"color": "#336699"})).unwrap();
|
||||
s.execute("edit.deselect", &json!({})).unwrap();
|
||||
assert!(matches!(s.hit_test(p, 3.0), Some(tools::Hit::Shape { id, .. }) if id == over), "{source}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Text on a foreground No Fill shape retains its selection and editing target.
|
||||
#[test]
|
||||
fn no_fill_text_shapes_keep_their_interior_text_target() {
|
||||
let mut s = session();
|
||||
let (_, over) = no_fill_overlap(&mut s, true);
|
||||
s.execute("text.set", &json!({"id": over.0, "text": "FOREGROUND TEXT"})).unwrap();
|
||||
s.execute("shape.fill", &json!({"none": true})).unwrap();
|
||||
s.execute("edit.deselect", &json!({})).unwrap();
|
||||
let p = deckcraft_geom::Point::new(200.0, 310.0);
|
||||
assert!(matches!(s.hit_test(p, 3.0), Some(tools::Hit::Shape { id, text: true }) if id == over));
|
||||
s.pointer(tev(PointerKind::DoubleClick, p.x, p.y)).unwrap();
|
||||
assert_eq!(text_sel(&s).unwrap().shape, over);
|
||||
}
|
||||
|
||||
/// A locked No Fill shape remains selectable on its outline, but dragging cannot move it.
|
||||
#[test]
|
||||
fn no_fill_locked_shape_keeps_outline_selection_without_moving() {
|
||||
let mut s = session();
|
||||
let (under, over) = no_fill_overlap(&mut s, true);
|
||||
s.execute("shape.fill", &json!({"none": true})).unwrap();
|
||||
s.execute("shape.lock", &json!({"locked": true})).unwrap();
|
||||
let before = s.doc().unwrap().shape(over).unwrap().xfrm;
|
||||
s.execute("edit.deselect", &json!({})).unwrap();
|
||||
let inside = deckcraft_geom::Point::new(200.0, 310.0);
|
||||
assert!(matches!(s.hit_test(inside, 3.0), Some(tools::Hit::Shape { id, .. }) if id == under));
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(tev(kind, inside.x, inside.y)).unwrap();
|
||||
}
|
||||
assert_eq!(text_sel(&s).unwrap().shape, under);
|
||||
s.execute("edit.deselect", &json!({})).unwrap();
|
||||
let edge = deckcraft_geom::Point::new(80.0, 330.0);
|
||||
assert!(matches!(s.hit_test(edge, 3.0), Some(tools::Hit::Shape { id, .. }) if id == over));
|
||||
s.pointer(tev(PointerKind::Down, edge.x, edge.y)).unwrap();
|
||||
s.pointer(tev(PointerKind::Drag, edge.x + 40.0, edge.y + 20.0)).unwrap();
|
||||
s.pointer(tev(PointerKind::Up, edge.x + 40.0, edge.y + 20.0)).unwrap();
|
||||
let st = s.doc().unwrap();
|
||||
assert_eq!(st.selection.shapes, vec![over]);
|
||||
assert_eq!(st.shape(over).unwrap().xfrm, before);
|
||||
assert!(st.shape(over).unwrap().locked);
|
||||
}
|
||||
|
||||
/// Removing both fill and outline leaves the empty interior transparent to clicks, locked or not.
|
||||
#[test]
|
||||
fn no_fill_shape_without_text_or_outline_passes_interior_clicks() {
|
||||
for locked in [false, true] {
|
||||
let mut s = session();
|
||||
let (under, _) = no_fill_overlap(&mut s, false);
|
||||
s.execute("shape.fill", &json!({"none": true})).unwrap();
|
||||
s.execute("shape.line", &json!({"none": true})).unwrap();
|
||||
s.execute("shape.lock", &json!({"locked": locked})).unwrap();
|
||||
s.execute("edit.deselect", &json!({})).unwrap();
|
||||
let p = deckcraft_geom::Point::new(200.0, 310.0);
|
||||
assert!(matches!(s.hit_test(p, 3.0), Some(tools::Hit::Shape { id, .. }) if id == under));
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(tev(kind, p.x, p.y)).unwrap();
|
||||
}
|
||||
assert_eq!(s.doc().unwrap().selection.shapes, vec![under]);
|
||||
}
|
||||
}
|
||||
|
||||
/// #931: while the text of a placeholder is being edited, a shape in front of it still takes a
|
||||
/// click (as in PowerPoint); a click on the text where nothing is in front still moves the caret.
|
||||
#[test]
|
||||
@@ -5830,6 +6046,204 @@ fn box_of(s: &mut Session, id: u64) -> serde_json::Value {
|
||||
s.execute("shape.inspect", &json!({"id": id})).unwrap()["box"].clone()
|
||||
}
|
||||
|
||||
/// Two selected boxes with different sizes and aligned right edges, on a blank slide.
|
||||
fn resize_selection_scene() -> (Session, [u64; 2]) {
|
||||
let mut s = session();
|
||||
s.execute("slide.new", &json!({"layout": "blank"})).unwrap();
|
||||
s.prefs.smart_guides = false;
|
||||
s.prefs.snap_to_grid = false;
|
||||
let ids = [[100, 100, 100, 80], [120, 300, 80, 100]]
|
||||
.map(|rect| s.execute("shape.insert", &json!({"preset": "rect", "rect": rect, "text": "Resize test"})).unwrap()["id"].as_u64().unwrap());
|
||||
s.execute("edit.select", &json!({"ids": ids})).unwrap();
|
||||
(s, ids)
|
||||
}
|
||||
|
||||
/// Simulate file-loaded shapes whose stored boxes have not yet been fitted to their text.
|
||||
fn pending_resize_autofit(s: &mut Session, ids: &[u64]) {
|
||||
s.edit(|doc, sel| {
|
||||
let shapes = crate::shapes_mut(doc, sel).unwrap();
|
||||
for id in ids {
|
||||
let sh = deckcraft_model::find_shape_mut(shapes, ShapeId(*id as u32)).unwrap();
|
||||
sh.text.as_mut().unwrap().body.autofit = Some(deckcraft_model::text::AutoFit::Shape);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// Resizing multiple selected shapes scales them proportionally around their anchors in one undo step.
|
||||
#[test]
|
||||
fn resizing_selected_shapes_is_one_undo_step() {
|
||||
let (mut s, [a, b]) = resize_selection_scene();
|
||||
let before = s.doc().unwrap().doc.clone();
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
let down = drag_gesture(&mut s, (200.0, 180.0), (250.0, 210.0));
|
||||
assert_eq!(down["hit"]["kind"], "resize");
|
||||
assert_eq!(down["hit"]["id"], a);
|
||||
for (id, expected) in [(a, [100.0, 100.0, 150.0, 110.0]), (b, [120.0, 300.0, 120.0, 137.5])] {
|
||||
let actual = box_of(&mut s, id);
|
||||
for (key, value) in ["x", "y", "w", "h"].into_iter().zip(expected) {
|
||||
assert_eq!(actual[key], value, "{id}: {key}");
|
||||
}
|
||||
}
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1);
|
||||
let after = s.doc().unwrap().doc.clone();
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc, before, "one undo restores both shapes");
|
||||
s.execute("edit.redo", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc, after, "one redo resizes both shapes again");
|
||||
}
|
||||
|
||||
/// Resizing selected shapes refits their text boxes inside the same undo transaction.
|
||||
#[test]
|
||||
fn resizing_selected_shapes_refits_text_in_the_same_undo_step() {
|
||||
let (mut s, ids) = resize_selection_scene();
|
||||
pending_resize_autofit(&mut s, &ids);
|
||||
let before = s.doc().unwrap().doc.clone();
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
// An east-handle drag changes width only; a height change must come from text fitting.
|
||||
drag_gesture(&mut s, (200.0, 140.0), (250.0, 140.0));
|
||||
for (id, old_height) in ids.into_iter().zip([80.0, 100.0]) {
|
||||
assert_ne!(box_of(&mut s, id)["h"], old_height, "both shapes' text is refitted");
|
||||
}
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1);
|
||||
let after = s.doc().unwrap().doc.clone();
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc, before);
|
||||
s.execute("edit.redo", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc, after, "redo includes the final text fit");
|
||||
}
|
||||
|
||||
/// Clicking a resize handle without dragging neither modifies shapes nor triggers text autofit.
|
||||
#[test]
|
||||
fn clicking_a_resize_handle_does_not_change_or_refit_selected_shapes() {
|
||||
let (mut s, ids) = resize_selection_scene();
|
||||
pending_resize_autofit(&mut s, &ids);
|
||||
let before = s.doc().unwrap().doc.clone();
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
let revision = s.doc().unwrap().revision;
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(PointerEvent { kind, x: 200.0, y: 180.0, tol: 3.0, ..Default::default() }).unwrap();
|
||||
}
|
||||
assert_eq!(s.doc().unwrap().doc, before);
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps, "a click creates no undo entry");
|
||||
assert_eq!(s.doc().unwrap().revision, revision);
|
||||
assert!(std::sync::Arc::ptr_eq(&s.doc().unwrap().doc, &before), "a click does not dirty the document");
|
||||
// Ensure this fixture would catch an accidental refit on release.
|
||||
for id in ids {
|
||||
cmd::text::fit_text_box(&mut s, ShapeId(id as u32)).unwrap();
|
||||
}
|
||||
assert_ne!(s.doc().unwrap().doc, before);
|
||||
}
|
||||
|
||||
/// Locked shapes in a multi-selection are excluded from both resizing and post-resize text fitting.
|
||||
#[test]
|
||||
fn resizing_selected_shapes_skips_locked_shapes_and_their_text_fit() {
|
||||
let (mut s, [a, b]) = resize_selection_scene();
|
||||
pending_resize_autofit(&mut s, &[b]);
|
||||
s.execute("shape.lock", &json!({"ids": [b], "locked": true})).unwrap();
|
||||
s.execute("edit.select", &json!({"ids": [a, b]})).unwrap();
|
||||
let locked = s.doc().unwrap().shape(ShapeId(b as u32)).unwrap().clone();
|
||||
let before = s.doc().unwrap().doc.clone();
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
drag_gesture(&mut s, (200.0, 180.0), (250.0, 210.0));
|
||||
assert_eq!(box_of(&mut s, a)["w"], 150.0);
|
||||
assert_eq!(box_of(&mut s, a)["h"], 110.0);
|
||||
assert_eq!(s.doc().unwrap().shape(ShapeId(b as u32)).unwrap(), &locked, "the locked shape is neither resized nor refitted");
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1);
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc, before);
|
||||
}
|
||||
|
||||
/// Resizing selected shapes excludes other selected resize targets from smart-guide snapping.
|
||||
#[test]
|
||||
fn resizing_selected_shapes_does_not_snap_to_other_resize_targets() {
|
||||
for reverse in [false, true] {
|
||||
let (mut s, [a, b]) = resize_selection_scene();
|
||||
s.prefs.smart_guides = true;
|
||||
let ids = if reverse { [b, a] } else { [a, b] };
|
||||
s.execute("edit.select", &json!({"ids": ids})).unwrap();
|
||||
// Within snap tolerance of the other selected shape's original right edge.
|
||||
drag_gesture(&mut s, (200.0, 140.0), (203.0, 140.0));
|
||||
assert_eq!(box_of(&mut s, a)["w"], 103.0, "first shape must not snap back");
|
||||
assert_eq!(box_of(&mut s, b)["w"], 82.4, "selection order must not affect snapping");
|
||||
}
|
||||
}
|
||||
|
||||
/// Resizing selected shapes snaps the active shape against unselected stationary shapes and scales others proportionally.
|
||||
#[test]
|
||||
fn resizing_selected_shapes_still_snaps_to_stationary_shapes() {
|
||||
let (mut s, [a, b]) = resize_selection_scene();
|
||||
let fixed = s.execute("shape.insert", &json!({"preset": "rect", "rect": [207, 430, 100, 80]})).unwrap()["id"].as_u64().unwrap();
|
||||
let fixed_before = box_of(&mut s, fixed);
|
||||
s.execute("edit.select", &json!({"ids": [a, b]})).unwrap();
|
||||
s.prefs.smart_guides = true;
|
||||
drag_gesture(&mut s, (200.0, 140.0), (203.0, 140.0));
|
||||
assert_eq!(box_of(&mut s, a)["w"], 107.0);
|
||||
assert!((box_of(&mut s, b)["w"].as_f64().unwrap() - 85.6).abs() < 1e-9);
|
||||
assert_eq!(box_of(&mut s, fixed), fixed_before);
|
||||
}
|
||||
|
||||
/// Secondary pictures resize uniformly around their anchor, preserving independent flips
|
||||
/// and keeping the complete multi-selection resize in one undo step.
|
||||
#[test]
|
||||
fn resizing_selected_shapes_resizes_secondary_pictures() {
|
||||
// Pointer destination, Alt, expected rectangle, expected picture, expected flips.
|
||||
let cases = [
|
||||
((180.0, 200.0), false, [100.0, 100.0, 80.0, 100.0], [300.0, 300.0, 80.0, 80.0], [false, false]),
|
||||
((200.0, 180.0), false, [100.0, 100.0, 100.0, 80.0], [300.0, 300.0, 80.0, 80.0], [false, false]),
|
||||
((220.0, 200.0), false, [100.0, 100.0, 120.0, 100.0], [300.0, 300.0, 120.0, 120.0], [false, false]),
|
||||
((200.0, 220.0), false, [100.0, 100.0, 100.0, 120.0], [300.0, 300.0, 120.0, 120.0], [false, false]),
|
||||
((180.0, 200.0), true, [120.0, 100.0, 60.0, 100.0], [320.0, 320.0, 60.0, 60.0], [false, false]),
|
||||
((200.0, 180.0), true, [100.0, 120.0, 100.0, 60.0], [320.0, 320.0, 60.0, 60.0], [false, false]),
|
||||
((80.0, 200.0), false, [80.0, 100.0, 20.0, 100.0], [280.0, 300.0, 20.0, 20.0], [true, false]),
|
||||
((200.0, 80.0), false, [100.0, 80.0, 100.0, 20.0], [300.0, 280.0, 20.0, 20.0], [false, true]),
|
||||
];
|
||||
|
||||
for (to, alt, expected_rect, expected_picture, flips) in cases {
|
||||
let mut s = session();
|
||||
s.execute("slide.new", &json!({"layout": "blank"})).unwrap();
|
||||
s.prefs.smart_guides = false;
|
||||
s.prefs.snap_to_grid = false;
|
||||
|
||||
let rect = s.execute("shape.insert", &json!({"preset": "rect", "rect": [100, 100, 100, 100]})).unwrap()["id"].as_u64().unwrap();
|
||||
let picture = ramp_picture(&mut s, 1, [300, 300, 100, 100]).as_u64().unwrap();
|
||||
s.execute("edit.select", &json!({"ids": [rect, picture]})).unwrap();
|
||||
|
||||
let before = s.doc().unwrap().doc.clone();
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
let mods = Mods { alt, ..Default::default() };
|
||||
let ev = |kind, (x, y): (f64, f64)| PointerEvent { kind, x, y, mods, tol: 3.0, pressure: None };
|
||||
|
||||
let down = s.pointer(ev(PointerKind::Down, (200.0, 200.0))).unwrap();
|
||||
assert_eq!(down["hit"]["kind"], "resize");
|
||||
assert_eq!(down["hit"]["id"], rect);
|
||||
assert_eq!(down["hit"]["handle"], 4);
|
||||
|
||||
s.pointer(ev(PointerKind::Drag, ((200.0 + to.0) / 2.0, (200.0 + to.1) / 2.0))).unwrap();
|
||||
s.pointer(ev(PointerKind::Drag, to)).unwrap();
|
||||
s.pointer(ev(PointerKind::Up, to)).unwrap();
|
||||
|
||||
for (id, expected) in [(rect, expected_rect), (picture, expected_picture)] {
|
||||
let actual = box_of(&mut s, id);
|
||||
for (key, value) in ["x", "y", "w", "h"].into_iter().zip(expected) {
|
||||
let got = actual[key].as_f64().unwrap();
|
||||
assert!((got - value).abs() < 1e-9, "{to:?}, alt={alt}, shape={id}, {key}: expected {value}, got {got}");
|
||||
}
|
||||
|
||||
let xfrm = s.doc().unwrap().shape(ShapeId(id as u32)).unwrap().xfrm.unwrap();
|
||||
assert_eq!([xfrm.flip_h, xfrm.flip_v], flips, "{to:?}, alt={alt}, shape={id}");
|
||||
}
|
||||
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1);
|
||||
let after = s.doc().unwrap().doc.clone();
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc, before);
|
||||
s.execute("edit.redo", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc, after);
|
||||
}
|
||||
}
|
||||
|
||||
/// #961: dragging the east handle snaps the dragged (right) edge, even when the fixed left edge
|
||||
/// already lines up with another shape. The nearest line used to be the fixed edge's, at distance 0.
|
||||
#[test]
|
||||
@@ -6249,3 +6663,30 @@ fn master_body_placeholder_format_keeps_per_level_formatting() {
|
||||
assert_eq!((level(&s, 0).run.size, level(&s, 1).run.size), (Some(28.0), Some(24.0)));
|
||||
assert_eq!(shown(&s), vec![Some(28.0), Some(24.0)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slide_master_view_rejects_invalid_indices() {
|
||||
let mut s = Session::with_new();
|
||||
for p in [json!({"master": -1}), json!({"master": 0.5}), json!({"master": 0, "layout": -1}), json!({"master": 0, "layout": 1.5})] {
|
||||
let r = s.execute("view.slideMaster", &p);
|
||||
assert!(r.is_err(), "invalid index accepted for {p}: {r:?}");
|
||||
}
|
||||
assert!(s.execute("view.slideMaster", &json!({})).is_ok());
|
||||
assert!(s.execute("view.slideMaster", &json!({"master": 0})).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_to_image_path_is_an_error_not_zip_bytes() {
|
||||
let dir = std::env::temp_dir().join(format!("deckcraft-save-img-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
for (cmd, name) in [("file.save", "a.png"), ("file.saveAs", "a.jpg"), ("file.save", "a.jpeg")] {
|
||||
let mut s = Session::new();
|
||||
sample::open_sample(&mut s).unwrap();
|
||||
let path = dir.join(name).to_string_lossy().to_string();
|
||||
let before = s.doc().unwrap().path.clone();
|
||||
assert!(s.execute(cmd, &json!({"path": path})).is_err(), "{cmd} {name} should fail");
|
||||
assert!(!std::path::Path::new(&path).exists(), "{name} must not be written");
|
||||
assert_eq!(s.doc().unwrap().path, before);
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
@@ -150,8 +150,10 @@ enum Drag {
|
||||
},
|
||||
Resize {
|
||||
id: ShapeId,
|
||||
handle: u8,
|
||||
orig: Xfrm,
|
||||
ids: Vec<ShapeId>,
|
||||
handle: u8,
|
||||
origs: Vec<(ShapeId, Xfrm)>,
|
||||
start: Point,
|
||||
},
|
||||
LineEnd {
|
||||
|
||||
@@ -13,6 +13,7 @@ struct MoveDrag {
|
||||
}
|
||||
|
||||
impl Session {
|
||||
/// Update the active drag interaction using the pointer position and modifiers.
|
||||
pub(super) fn drag(&mut self, p: Point, mods: Mods, tol: f64) -> Result<Value> {
|
||||
let Some(drag) = self.tool.drag.clone() else { return Ok(Value::Null) };
|
||||
match drag {
|
||||
@@ -26,10 +27,48 @@ impl Session {
|
||||
Drag::Move { ids, start, origs, moved, duplicate, enter_text } => {
|
||||
return self.drag_move(MoveDrag { ids, start, origs, moved, duplicate, enter_text }, p, mods, tol);
|
||||
}
|
||||
Drag::Resize { id, handle, orig, start } => {
|
||||
let nx = resize_box(&orig, handle, p - start, mods.shift || self.is_picture(id), mods.alt);
|
||||
let nx = self.snap_resize(nx, &orig, handle, id, tol);
|
||||
self.set_xfrm(id, nx)?;
|
||||
Drag::Resize { id, orig, ids, handle, origs, start } => {
|
||||
let keep_aspect = mods.shift || self.is_picture(id);
|
||||
let nx = resize_box(&orig, handle, p - start, keep_aspect, mods.alt);
|
||||
let nx = self.snap_resize(nx, handle, &ids, tol);
|
||||
let sx = if orig.w > 1e-9 { (nx.w / orig.w) * if nx.flip_h != orig.flip_h { -1.0 } else { 1.0 } - 1.0 } else { 0.0 };
|
||||
let sy = if orig.h > 1e-9 { (nx.h / orig.h) * if nx.flip_v != orig.flip_v { -1.0 } else { 1.0 } - 1.0 } else { 0.0 };
|
||||
let div = if mods.alt { 2.0 } else { 1.0 };
|
||||
let hx = match handle {
|
||||
0 | 6 | 7 => -1.0,
|
||||
2..=4 => 1.0,
|
||||
_ => 0.0,
|
||||
};
|
||||
let hy = match handle {
|
||||
0..=2 => -1.0,
|
||||
4..=6 => 1.0,
|
||||
_ => 0.0,
|
||||
};
|
||||
for (tid, o) in &origs {
|
||||
let target_nx = if *tid == id {
|
||||
nx
|
||||
} else {
|
||||
let picture = self.is_picture(*tid);
|
||||
let (sx, sy) = if picture && matches!(handle, 0 | 2 | 4 | 6) {
|
||||
// Use the axis with the larger relative change so an unchanged
|
||||
// dimension cannot cancel shrinking. Preserve each axis's flip.
|
||||
let scale_x = 1.0 + sx;
|
||||
let scale_y = 1.0 + sy;
|
||||
let scale = if sx.abs() >= sy.abs() { scale_x.abs() } else { scale_y.abs() };
|
||||
(scale.copysign(scale_x) - 1.0, scale.copysign(scale_y) - 1.0)
|
||||
} else {
|
||||
(sx, sy)
|
||||
};
|
||||
|
||||
let lp = Affine::rotate(o.rot.to_radians())
|
||||
* Point::new(
|
||||
hx * sx * o.w / div * if o.flip_h { -1.0 } else { 1.0 },
|
||||
hy * sy * o.h / div * if o.flip_v { -1.0 } else { 1.0 },
|
||||
);
|
||||
resize_box(o, handle, Vec2::new(lp.x, lp.y), picture, mods.alt)
|
||||
};
|
||||
self.set_xfrm(*tid, target_nx)?;
|
||||
}
|
||||
}
|
||||
Drag::LineEnd { id, end, orig } => {
|
||||
let a = orig.affine();
|
||||
|
||||
@@ -228,7 +228,7 @@ impl Session {
|
||||
}
|
||||
|
||||
/// Snap the edges that resize handle `handle` drags in the resized box `x` to the smart guides.
|
||||
pub(super) fn snap_resize(&mut self, x: Xfrm, _orig: &Xfrm, handle: u8, id: ShapeId, tol: f64) -> Xfrm {
|
||||
pub(super) fn snap_resize(&mut self, x: Xfrm, handle: u8, exclude: &[ShapeId], tol: f64) -> Xfrm {
|
||||
if x.rot != 0.0 {
|
||||
self.tool.guides.clear();
|
||||
return x;
|
||||
@@ -241,7 +241,7 @@ impl Session {
|
||||
let (top, bottom) = (matches!(handle, 0..=2), matches!(handle, 4..=6));
|
||||
let (moves_left, moves_right) = if x.flip_h { (right, left) } else { (left, right) };
|
||||
let (moves_top, moves_bottom) = if x.flip_v { (bottom, top) } else { (top, bottom) };
|
||||
let (off, guides) = self.snap_edges(r, &[id], tol * 1.5, true, [moves_left, false, moves_right], [moves_top, false, moves_bottom]);
|
||||
let (off, guides) = self.snap_edges(r, exclude, tol * 1.5, true, [moves_left, false, moves_right], [moves_top, false, moves_bottom]);
|
||||
let mut nx = x;
|
||||
if moves_left {
|
||||
nx.x += off.x;
|
||||
|
||||
@@ -216,6 +216,7 @@ pub(super) fn in_table_cell(st: &crate::DocState, id: ShapeId, p: Point) -> bool
|
||||
})
|
||||
}
|
||||
|
||||
/// Resolve a shape's target at slide point `p`, using its effective fill for interior hits.
|
||||
pub(super) fn hit_shape(st: &crate::DocState, sh: &Shape, p: Point, tol: f64) -> Option<Hit> {
|
||||
let x = xfrm_of(&st.doc, &st.selection, sh);
|
||||
let inv = x.affine().inverse();
|
||||
@@ -267,8 +268,11 @@ pub(super) fn hit_shape(st: &crate::DocState, sh: &Shape, p: Point, tol: f64) ->
|
||||
return None;
|
||||
}
|
||||
let has_text = matches!(sh.kind, ShapeKind::Shape) && (sh.text.as_ref().is_some_and(|t| !t.is_empty()) || sh.ph.is_some() || sh.text_box);
|
||||
// Empty interiors of unfilled, text-less shapes don't catch clicks.
|
||||
let filled = !matches!(sh.fill, Some(deckcraft_model::Fill::None)) || sh.style.is_some();
|
||||
// Match rendering: an explicit No Fill overrides the style, and style/theme fills
|
||||
// can themselves be No Fill. Empty, text-less interiors then let clicks through.
|
||||
let fill =
|
||||
cmd::text::ctx_for(&st.doc, &st.selection).map(|ctx| deckcraft_model::resolve::fill(&ctx, sh).0).unwrap_or_else(|| sh.fill.clone());
|
||||
let filled = !matches!(fill, None | Some(deckcraft_model::Fill::None));
|
||||
let geo = deckcraft_render::shape_geometry(sh, x.w, x.h);
|
||||
let in_geo = {
|
||||
use deckcraft_geom::KurboShape;
|
||||
|
||||
@@ -220,6 +220,7 @@ impl Session {
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle a pointer press and start the applicable tool interaction.
|
||||
fn down(&mut self, p: Point, mods: Mods, tol: f64) -> Result<Value> {
|
||||
if let Some(Drag::Freeform { mode, mut points, .. }) = self.tool.drag.clone() {
|
||||
// Next click of a freeform: close on the start point, else add a vertex.
|
||||
@@ -303,8 +304,12 @@ impl Session {
|
||||
Some(Hit::TableRow { id, row }) => self.begin_table_border(id, false, row, p)?,
|
||||
Some(Hit::Resize { id, handle }) => {
|
||||
let orig = st.shape(id).map(|s| xfrm_of(&st.doc, &st.selection, s)).unwrap_or_default();
|
||||
let ids: Vec<ShapeId> = if st.selection.shapes.contains(&id) { st.selection.shapes.clone() } else { vec![id] };
|
||||
let origs: Vec<(ShapeId, Xfrm)> =
|
||||
ids.iter().filter_map(|i| st.shape(*i).filter(|s| !s.locked).map(|s| (*i, xfrm_of(&st.doc, &st.selection, s)))).collect();
|
||||
let ids: Vec<ShapeId> = origs.iter().map(|(id, _)| *id).collect();
|
||||
self.begin("Size");
|
||||
self.tool.drag = Some(Drag::Resize { id, handle, orig, start: p });
|
||||
self.tool.drag = Some(Drag::Resize { id, orig, ids, handle, origs, start: p });
|
||||
}
|
||||
Some(Hit::LineEnd { id, end }) => {
|
||||
let orig = st.shape(id).map(|s| xfrm_of(&st.doc, &st.selection, s)).unwrap_or_default();
|
||||
@@ -436,6 +441,7 @@ impl Session {
|
||||
Ok(json!({"hit": serde_json::to_value(&hit).unwrap_or_default()}))
|
||||
}
|
||||
|
||||
/// Handle a pointer release and finalize the active tool interaction.
|
||||
fn up(&mut self, p: Point, mods: Mods) -> Result<Value> {
|
||||
let drag = self.tool.drag.take();
|
||||
self.tool.guides.clear();
|
||||
@@ -558,10 +564,22 @@ impl Session {
|
||||
out = self.add_ink(points)?;
|
||||
}
|
||||
}
|
||||
Some(Drag::Resize { id, .. }) => {
|
||||
Some(Drag::Resize { origs, .. }) => {
|
||||
let changed: Vec<ShapeId> = origs
|
||||
.iter()
|
||||
.filter_map(|(id, orig)| {
|
||||
let current = self.active().and_then(|st| st.shape(*id).map(|s| xfrm_of(&st.doc, &st.selection, s)))?;
|
||||
|
||||
(current != *orig).then_some(*id)
|
||||
})
|
||||
.collect();
|
||||
if !changed.is_empty() {
|
||||
for id in changed {
|
||||
let _ = cmd::text::fit_text_box(self, id);
|
||||
self.refit_after_resize(id)?;
|
||||
}
|
||||
}
|
||||
self.commit();
|
||||
let _ = cmd::text::fit_text_box(self, id);
|
||||
self.refit_after_resize(id)?;
|
||||
}
|
||||
Some(Drag::TextSelect { before, .. }) => {
|
||||
out = self.paint_if_selection_changed(before, out)?;
|
||||
|
||||
Reference in New Issue
Block a user