diff --git a/crates/engine/src/cmd/fileio/tests_psdread.rs b/crates/engine/src/cmd/fileio/tests_psdread.rs index 4e43565b56..a1c376e938 100644 --- a/crates/engine/src/cmd/fileio/tests_psdread.rs +++ b/crates/engine/src/cmd/fileio/tests_psdread.rs @@ -714,10 +714,14 @@ fn unembed_keeps_the_clipping_path_of_a_distorted_psd() { }; let ext = if *kind == "rgb" { ["png"].as_slice() } else { ["tif", "tiff"].as_slice() }; assert!(ext.contains(&super::extension(&path).as_str()), "{kind}: {path}"); - for step in ["unembed", "relink"] { + for step in ["unembed", "relink", "update"] { if step == "relink" { s.execute("links.relink", &json!({"ids": [image.0], "path": path})).unwrap(); } + if step == "update" { + let r = s.execute("links.update", &json!({"ids": [image.0]})).unwrap(); + assert_eq!(r["updated"], json!([image.0]), "{kind}: {r}"); + } let d = &s.doc().unwrap().doc; let NodeKind::Image(im) = &d.node(image).unwrap().kind else { panic!("an image") }; assert!(im.link.is_some(), "linked to the file written"); @@ -729,6 +733,21 @@ fn unembed_keeps_the_clipping_path_of_a_distorted_psd() { assert!(near && (even_odd, held) == (before.1, before.2), "{kind}, {step}, folder: {folder}: {anchors:?} vs {:?}", before.0); } } + // A path that converts the image writes a file without the clipping path: the clip group + // becomes a plain group of the image, as Relink to any file without one leaves it. + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 100, "height": 50})).unwrap(); + let data = vectorcraft_format::base64_encode(&red_psd(&triangle_resources())); + let r = s.execute("file.place", &json!({"name": "cut.psd", "dataBase64": data, "at": [50, 25]})).unwrap(); + let (group, image) = (NodeId(r["ids"][0].as_u64().unwrap()), NodeId(r["image"].as_u64().unwrap())); + s.execute("select.set", &json!({"ids": [group.0]})).unwrap(); + s.execute("object.distort", &json!({"corners": [[0, 0], [100, 8], [90, 50], [6, 44]]})).unwrap(); + s.execute("links.unembed", &json!({"id": image.0, "path": dir.join("converted.jpg")})).unwrap(); + match s.doc().unwrap().doc.node(group).map(|n| &n.kind) { + Some(NodeKind::Group { children, clip: false }) => assert_eq!(children.iter().map(|c| c.id).collect::>(), [image]), + other => panic!("a plain group of the image: {other:?}"), + } + assert!(s.doc().unwrap().doc.node(image).unwrap().is_distorted_image()); } /// The PNG a PSD file's merged image is kept as holds the clipping path the file names, and only a diff --git a/crates/engine/src/cmd/links.rs b/crates/engine/src/cmd/links.rs index 5ebe9c5f54..d83e1178fd 100644 --- a/crates/engine/src/cmd/links.rs +++ b/crates/engine/src/cmd/links.rs @@ -108,7 +108,7 @@ pub fn specs() -> Vec { "Unembed", [], None, - "{id?: an embedded image (default: the one selected), path?, ids?: [image ids] (instead of id; one id is the same as id), folder?} write the image's pixels to the file at path (PNG, JPEG, GIF or WebP as stored, other images as PNG; a path ending in .png/.jpg/.jpeg/.gif/.webp/.tif/.tiff/.bmp converts them) and link the image to it, keeping its bounds (an image changed by Perspective Distort or Free Distort keeps its corners and, when it came from a PSD or PSB file, the clip group of that file's clipping path, with or without folder). One undo step → {id, path}; no path → {name, dataBase64} (nothing changes: there is no file to link to). With folder: write each embedded image of ids or id (default: the selected embedded images) to a new file in folder, as stored (as PNG when that format is not one of VectorCraft's raster file formats), named after the image (characters a file name can't hold become _; Image when nothing is left), with Name 2 … Name 99 when the name is taken; a file already there is never replaced. Linked images among ids are left as they are. Each image links to its file and keeps its bounds (a distorted image its corners). One undo step (undo does not remove the files); when a file can't be written, the files this call wrote are removed and nothing changes → {unembedded: [{id, path}], skipped: [ids of linked images]}; id with ids, path with folder, and ids of more or fewer than one image without folder are errors", + "{id?: an embedded image (default: the one selected), path?, ids?: [image ids] (instead of id; one id is the same as id), folder?} write the image's pixels to the file at path (PNG, JPEG, GIF or WebP as stored, other images as PNG; a path ending in .png/.jpg/.jpeg/.gif/.webp/.tif/.tiff/.bmp converts them) and link the image to it, keeping its bounds (an image changed by Perspective Distort or Free Distort keeps its corners; written as stored (here and with folder), such an image from a PSD or PSB file also keeps the clip group of the clipping path that file names, and the file written keeps the path, so Relink and Update Links to it keep the clip group; a path that converts the image writes no clipping path, and the clip group becomes a plain group). One undo step → {id, path}; no path → {name, dataBase64} (nothing changes: there is no file to link to). With folder: write each embedded image of ids or id (default: the selected embedded images) to a new file in folder, as stored (as PNG when that format is not one of VectorCraft's raster file formats), named after the image (characters a file name can't hold become _; Image when nothing is left), with Name 2 … Name 99 when the name is taken; a file already there is never replaced. Linked images among ids are left as they are. Each image links to its file and keeps its bounds (a distorted image its corners). One undo step (undo does not remove the files); when a file can't be written, the files this call wrote are removed and nothing changes → {unembedded: [{id, path}], skipped: [ids of linked images]}; id with ids, path with folder, and ids of more or fewer than one image without folder are errors", has_doc, unembed ), diff --git a/docs/mcp.md b/docs/mcp.md index f80563dc27..5144c4698c 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -6669,10 +6669,11 @@ Crop Image (`object.cropImage`), Image Trace (`imageTrace.make`, `imageTrace.mak Relink's `preserve`; Relink then adds a `warnings` entry naming those images. The clipping path a PSD, PSB or DCS file names is drawn through the corners: the clip group of the old file's clipping path gets the new file's clipping path, or becomes a plain group when the new file names none. Embed (`links.embed`) and Unembed (`links.unembed`) keep -the corners, each in one undo step. Unembed of a distorted image from a PSD or PSB file keeps the clip group of that -file's clipping path, and so does Relink to the PNG or TIFF it wrote. Mask (`object.maskImage`) draws its clipping -path through the image's corners. Rasterize (`object.rasterize`) draws the image between its corners and makes a -plain image of the result. These rules are VectorCraft's own. +the corners, each in one undo step. Unembed of a distorted image from a PSD or PSB file, written as stored (PNG, or +TIFF for a CMYK file), keeps the clip group of that file's clipping path, and so do Relink and Update Links to the +file it wrote; a path that converts the image writes no clipping path, and the clip group becomes a plain group. Mask +(`object.maskImage`) draws its clipping path through the image's corners. Rasterize (`object.rasterize`) draws the +image between its corners and makes a plain image of the result. These rules are VectorCraft's own. ```json {"name":"run_command","arguments":{"command":"object.distort","params":{"corners":[[40,0],[60,0],[100,100],[0,100]]}}}