mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-21 20:28:51 +00:00
Merge pull request #8532 from dotCooCoo/feat/distorted-image-commands
Links: Relink, Embed and Unembed keep a distorted image's corners
This commit is contained in:
+20
-3
@@ -1162,9 +1162,15 @@ impl Lerp {
|
||||
&& let (Some(qa), Some(qb)) = (a.image_corners(), b.image_corners())
|
||||
{
|
||||
let near = if t < 0.5 { qa } else { qb };
|
||||
if n.set_image_corners([0, 1, 2, 3].map(|i| qa[i].lerp(qb[i], t))).is_err() {
|
||||
// The nearer key's corners passed the same check when it was distorted.
|
||||
let _ = n.set_image_corners(near);
|
||||
if n.set_image_corners([0, 1, 2, 3].map(|i| qa[i].lerp(qb[i], t))).is_err() && n.set_image_corners(near).is_err() {
|
||||
// Corners from a transform that collapses the image fail the check too: the
|
||||
// step is then placed as the nearer key is.
|
||||
if let (NodeKind::Image(o), NodeKind::Image(k)) = (&mut n.kind, &base.kind) {
|
||||
o.xf = k.xf;
|
||||
}
|
||||
if n.extras().image_quad != base.extras().image_quad {
|
||||
n.extras_mut().image_quad = base.extras().image_quad.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
n.extras_mut().mask = None;
|
||||
@@ -2343,6 +2349,17 @@ mod tests {
|
||||
let near = (if t < 0.5 { &a } else { b }).image_corners().unwrap();
|
||||
assert!(got.iter().zip(near).all(|(g, w)| g.distance(w) < 1e-9), "{t}: {got:?} against {near:?}");
|
||||
}
|
||||
// Toward an image whose transform has no height, neither the step's corners nor the
|
||||
// nearer key's pass the check: the step is placed as that key is.
|
||||
let mut flat = image([(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0)]);
|
||||
let collapsed = Affine::new([-3.0, 0.0, 0.0, 0.0, 100.0, 0.0]);
|
||||
if let NodeKind::Image(im) = &mut flat.kind {
|
||||
im.xf = collapsed;
|
||||
}
|
||||
let step = Lerp::new(&a, &flat, (None, None)).at(0.5);
|
||||
let NodeKind::Image(im) = &step.kind else { panic!("an image") };
|
||||
assert_eq!(im.xf, collapsed);
|
||||
assert!(!step.is_distorted_image() && step.extras().image_quad.is_none());
|
||||
}
|
||||
|
||||
fn key(x: f64) -> Arc<Node> {
|
||||
|
||||
@@ -392,6 +392,11 @@ mod tests {
|
||||
assert_eq!(n.image_quad(), None);
|
||||
assert!(distorted_art(&n).is_none());
|
||||
assert_eq!(n.image_corners(), Some(rect_corners(Rect::new(0.0, 0.0, 100.0, 100.0))));
|
||||
// Reading the file drops it, so a later transform can't make it a distortion.
|
||||
let mut back: Node = serde_json::from_value(serde_json::to_value(&n).unwrap()).unwrap();
|
||||
assert!(back.extras().image_quad.is_none());
|
||||
back.transform(Affine::scale_non_uniform(1e6, 1.0), false);
|
||||
assert!(!back.is_distorted_image());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -42,7 +42,7 @@ pub mod jxlread;
|
||||
mod legacy_ai;
|
||||
mod load;
|
||||
mod mesh3d;
|
||||
pub(crate) use load::{MAX_RASTER_ALLOC, file_clipped, image_clip, size_note};
|
||||
pub(crate) use load::{MAX_RASTER_ALLOC, file_clipped, image_clip, preview_with_clip, size_note};
|
||||
mod heifread;
|
||||
pub mod hpgl;
|
||||
mod jp2read;
|
||||
|
||||
@@ -1370,6 +1370,20 @@ pub(crate) fn image_clip(blob: &ImageBlob) -> Option<vectorcraft_geom::PathData>
|
||||
vectorcraft_geom::path::with_anchor_budget(vectorcraft_geom::path::MAX_READ_ANCHORS, || serde_json::from_slice(json).ok())
|
||||
}
|
||||
|
||||
/// `blob` with its preview keeping the clipping path its PNG or TIFF keeps ([`image_clip`]), in a
|
||||
/// text chunk of the preview PNG as [`png_with_clip`] writes it: a document saved without its
|
||||
/// linked files holds the preview alone, and the Links commands then still know a clip group of
|
||||
/// that path as the file's. Unchanged without a preview or a clipping path.
|
||||
pub(crate) fn preview_with_clip(mut blob: ImageBlob) -> ImageBlob {
|
||||
let Some(proxy) = blob.proxy.clone().filter(|p| !std::sync::Arc::ptr_eq(p, &blob.bytes) && png_clip(p).is_none()) else { return blob };
|
||||
let Some(json) = image_clip(&blob).and_then(|clip| serde_json::to_string(&clip).ok()).filter(|j| j.len() <= MAX_PNG_CLIP) else {
|
||||
return blob;
|
||||
};
|
||||
let png = vectorcraft_render::encode::png::with_text(proxy.to_vec(), &[(CLIP_KEYWORD, json.into())]);
|
||||
blob.proxy = Some(std::sync::Arc::new(png));
|
||||
blob
|
||||
}
|
||||
|
||||
/// An image as a document of its physical size at the resolution it declares (as Place sizes it;
|
||||
/// 72 ppi, 1 px = 1 pt, when it declares none), the image named after the file.
|
||||
pub(super) fn raster_doc(name: &str, bytes: &[u8]) -> Result<Document> {
|
||||
|
||||
@@ -602,6 +602,217 @@ fn relink_and_update_follow_the_clipping_path_of_a_linked_psd() {
|
||||
assert_eq!(clip_group(&s.doc().unwrap().doc, group), (squared, true, NodeId(image)), "links.update reads the clipping path again");
|
||||
}
|
||||
|
||||
/// links.relink follows the clipping path of a linked PSD file for an image changed by Perspective
|
||||
/// Distort or Free Distort too: the new file's clipping path is mapped through the image's corners,
|
||||
/// a clip group of the old file's clipping path loses it when the new file names none, and a later
|
||||
/// file's clipping path clips it again.
|
||||
#[test]
|
||||
fn relink_follows_the_clipping_path_of_a_distorted_psd() {
|
||||
let dir = vectorcraft_testkit::TempDir::new("psd-relink-distorted");
|
||||
let cut = write_file(&dir, "cut.psd", &red_psd(&triangle_resources()));
|
||||
let square = write_file(&dir, "square.psd", &red_psd(&square_resources()));
|
||||
let plain = write_file(&dir, "plain.psd", &red_psd(&[]));
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 100, "height": 50})).unwrap();
|
||||
let r = s.execute("file.place", &json!({"path": cut, "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();
|
||||
let node = |s: &Session| s.doc().unwrap().doc.node(image).unwrap().clone();
|
||||
assert!(node(&s).is_distorted_image());
|
||||
let corners = node(&s).image_corners().unwrap();
|
||||
// A path's anchors (in the image's pixels) where the image's corners put them.
|
||||
let mapped = |s: &Session, pixels: &[[f64; 2]]| -> Vec<[f64; 2]> {
|
||||
let map = node(s).image_map().unwrap();
|
||||
pixels.iter().map(|[x, y]| map.apply(vectorcraft_geom::Point::new(*x, *y)).unwrap()).map(|p| [p.x, p.y]).collect()
|
||||
};
|
||||
let near =
|
||||
|a: &[[f64; 2]], b: &[[f64; 2]]| a.len() == b.len() && a.iter().zip(b).all(|(p, q)| (p[0] - q[0]).abs() < 1e-6 && (p[1] - q[1]).abs() < 1e-6);
|
||||
let (anchors, even_odd, held) = clip_group(&s.doc().unwrap().doc, group);
|
||||
let triangle = mapped(&s, &[[50.0, 0.0], [100.0, 50.0], [0.0, 50.0]]);
|
||||
assert!(near(&anchors, &triangle) && even_odd && held == image, "{anchors:?} vs {triangle:?}");
|
||||
s.execute("links.relink", &json!({"ids": [image.0], "path": square})).unwrap();
|
||||
let (anchors, even_odd, held) = clip_group(&s.doc().unwrap().doc, group);
|
||||
let squared = mapped(&s, &[[25.0, 12.5], [75.0, 12.5], [75.0, 37.5], [25.0, 37.5]]);
|
||||
assert!(near(&anchors, &squared) && even_odd && held == image, "the new file's clipping path: {anchors:?} vs {squared:?}");
|
||||
assert_eq!(node(&s).image_corners().unwrap(), corners);
|
||||
s.execute("links.relink", &json!({"ids": [image.0], "path": plain})).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::<Vec<_>>(), [image]),
|
||||
other => panic!("a plain group of the image: {other:?}"),
|
||||
}
|
||||
s.execute("links.relink", &json!({"ids": [image.0], "path": cut})).unwrap();
|
||||
let (anchors, _, held) = clip_group(&s.doc().unwrap().doc, group);
|
||||
assert!(near(&anchors, &triangle) && held == image, "clipped again: {anchors:?} vs {triangle:?}");
|
||||
assert!(node(&s).is_distorted_image());
|
||||
assert_eq!(node(&s).image_corners().unwrap(), corners);
|
||||
}
|
||||
|
||||
/// Update Links follows the clipping path of a linked PSD file for an image changed by Perspective
|
||||
/// Distort or Free Distort: the file's new clipping path is drawn through the image's corners, and
|
||||
/// a file without one leaves a plain group.
|
||||
#[test]
|
||||
fn update_links_follows_the_clipping_path_of_a_distorted_psd() {
|
||||
let dir = vectorcraft_testkit::TempDir::new("psd-update-distorted");
|
||||
let cut = write_file(&dir, "cut.psd", &red_psd(&triangle_resources()));
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 100, "height": 50})).unwrap();
|
||||
let r = s.execute("file.place", &json!({"path": cut, "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();
|
||||
let node = |s: &Session| s.doc().unwrap().doc.node(image).unwrap().clone();
|
||||
let corners = node(&s).image_corners().unwrap();
|
||||
let map = node(&s).image_map().unwrap();
|
||||
let squared: Vec<[f64; 2]> = [[25.0, 12.5], [75.0, 12.5], [75.0, 37.5], [25.0, 37.5]]
|
||||
.iter()
|
||||
.map(|[x, y]| map.apply(vectorcraft_geom::Point::new(*x, *y)).unwrap())
|
||||
.map(|p| [p.x, p.y])
|
||||
.collect();
|
||||
std::fs::write(&cut, red_psd(&square_resources())).unwrap();
|
||||
s.execute("links.update", &json!({"ids": [image.0]})).unwrap();
|
||||
let (anchors, even_odd, held) = clip_group(&s.doc().unwrap().doc, group);
|
||||
let near = anchors.len() == squared.len() && anchors.iter().zip(&squared).all(|(p, q)| (p[0] - q[0]).abs() < 1e-6 && (p[1] - q[1]).abs() < 1e-6);
|
||||
assert!(near && even_odd && held == image, "the file's new clipping path: {anchors:?} vs {squared:?}");
|
||||
assert_eq!(node(&s).image_corners().unwrap(), corners);
|
||||
std::fs::write(&cut, red_psd(&[])).unwrap();
|
||||
s.execute("links.update", &json!({"ids": [image.0]})).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::<Vec<_>>(), [image]),
|
||||
other => panic!("a plain group of the image: {other:?}"),
|
||||
}
|
||||
assert_eq!(node(&s).image_corners().unwrap(), corners);
|
||||
}
|
||||
|
||||
/// A document saved without its linked files keeps a linked PSD file's image as a preview, smaller
|
||||
/// than the file. Reopened after the file's clipping path changed, Update Links still knows the
|
||||
/// clip group of the old clipping path as the file's and gives it the new one, for an image changed
|
||||
/// by Perspective Distort or Free Distort and for one that is not.
|
||||
#[test]
|
||||
fn update_links_after_reopening_from_the_preview_replaces_the_files_clipping_path() {
|
||||
let big = |resources: &[u8]| psd(1, 3, (400, 200), 8, 3, &[], resources, &[], &raw(&[&[255; 80000], &[0; 80000], &[0; 80000]]));
|
||||
for distorted in [false, true] {
|
||||
let dir = vectorcraft_testkit::TempDir::new(if distorted { "psd-preview-distorted" } else { "psd-preview" });
|
||||
let cut = write_file(&dir, "cut.psd", &big(&triangle_resources()));
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 400, "height": 200})).unwrap();
|
||||
let r = s.execute("file.place", &json!({"path": cut, "at": [200, 100]})).unwrap();
|
||||
let (group, image) = (NodeId(r["ids"][0].as_u64().unwrap()), NodeId(r["image"].as_u64().unwrap()));
|
||||
if distorted {
|
||||
s.execute("select.set", &json!({"ids": [group.0]})).unwrap();
|
||||
s.execute("object.distort", &json!({"corners": [[0, 0], [400, 30], [360, 200], [20, 180]]})).unwrap();
|
||||
}
|
||||
let node = |s: &Session| s.doc().unwrap().doc.node(image).unwrap().clone();
|
||||
let corners = node(&s).image_corners().unwrap();
|
||||
let doc_path = dir.join("poster.vectorcraft").to_string_lossy().into_owned();
|
||||
s.execute("document.save", &json!({"path": doc_path})).unwrap();
|
||||
std::fs::write(&cut, big(&square_resources())).unwrap();
|
||||
s.execute("document.open", &json!({"path": doc_path})).unwrap();
|
||||
let d = &s.doc().unwrap().doc;
|
||||
let NodeKind::Image(im) = &d.node(image).unwrap().kind else { panic!("an image") };
|
||||
assert!(d.images[&im.key].is_proxy(), "the saved preview shows");
|
||||
let r = s.execute("links.update", &json!({"ids": [image.0]})).unwrap();
|
||||
assert_eq!(r["updated"], json!([image.0]), "{r}");
|
||||
let map = node(&s).image_map().unwrap();
|
||||
let squared: Vec<[f64; 2]> = [[100.0, 50.0], [300.0, 50.0], [300.0, 150.0], [100.0, 150.0]]
|
||||
.iter()
|
||||
.map(|[x, y]| map.apply(vectorcraft_geom::Point::new(*x, *y)).unwrap())
|
||||
.map(|p| [p.x, p.y])
|
||||
.collect();
|
||||
let (anchors, even_odd, held) = clip_group(&s.doc().unwrap().doc, group);
|
||||
let near =
|
||||
anchors.len() == squared.len() && anchors.iter().zip(&squared).all(|(p, q)| (p[0] - q[0]).abs() < 1e-6 && (p[1] - q[1]).abs() < 1e-6);
|
||||
assert!(near && even_odd && held == image, "distorted: {distorted}: {anchors:?} vs {squared:?}");
|
||||
assert_eq!(node(&s).image_corners().unwrap(), corners);
|
||||
}
|
||||
}
|
||||
|
||||
/// Unembed of a distorted image from a PSD file, with a path and with a folder, keeps the clip
|
||||
/// group of the clipping path that file names, drawn through its corners, and so does relinking it
|
||||
/// to the file written. Update Links reads the clipping path the file on disk keeps then, and all
|
||||
/// four corners stay where they were.
|
||||
#[test]
|
||||
fn unembed_keeps_the_clipping_path_of_a_distorted_psd() {
|
||||
let dir = vectorcraft_testkit::TempDir::new("psd-unembed-distorted-clip");
|
||||
// An RGB file is kept as a PNG, a CMYK one as a TIFF.
|
||||
let cmyk = |resources: &[u8]| psd(1, 4, (100, 50), 8, 4, &[], resources, &[], &raw(&[&[0; 5000], &[255; 5000], &[255; 5000], &[0; 5000]]));
|
||||
let files = [("rgb", red_psd(&triangle_resources())), ("cmyk", cmyk(&triangle_resources()))];
|
||||
// The file Unembed writes, as stored, for the same kind of file clipped to the square.
|
||||
let squared_file = |kind: &str| {
|
||||
let file = if kind == "rgb" { red_psd(&square_resources()) } else { cmyk(&square_resources()) };
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 100, "height": 50})).unwrap();
|
||||
let r = s.execute("file.place", &json!({"name": "square.psd", "dataBase64": vectorcraft_format::base64_encode(&file)})).unwrap();
|
||||
let r = s.execute("links.unembed", &json!({"id": r["image"]})).unwrap();
|
||||
vectorcraft_format::base64_decode(r["dataBase64"].as_str().unwrap()).unwrap()
|
||||
};
|
||||
for ((kind, file), folder) in files.iter().flat_map(|f| [(f, false), (f, true)]) {
|
||||
let data = vectorcraft_format::base64_encode(file);
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 100, "height": 50})).unwrap();
|
||||
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();
|
||||
let before = clip_group(&s.doc().unwrap().doc, group);
|
||||
let corners = s.doc().unwrap().doc.node(image).unwrap().image_corners().unwrap();
|
||||
// Without an extension the image is written in the format it is stored in.
|
||||
let path = if folder {
|
||||
let out = dir.join(format!("folder-{kind}"));
|
||||
std::fs::create_dir_all(&out).unwrap();
|
||||
let r = s.execute("links.unembed", &json!({"ids": [image.0], "folder": out})).unwrap();
|
||||
r["unembedded"][0]["path"].as_str().unwrap().to_string()
|
||||
} else {
|
||||
let r = s.execute("links.unembed", &json!({"id": image.0, "path": dir.join(format!("written-{kind}"))})).unwrap();
|
||||
r["path"].as_str().unwrap().to_string()
|
||||
};
|
||||
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", "update"] {
|
||||
let mut want = before.0.clone();
|
||||
if step == "relink" {
|
||||
s.execute("links.relink", &json!({"ids": [image.0], "path": path})).unwrap();
|
||||
}
|
||||
if step == "update" {
|
||||
// The file on disk now keeps the square: Update Links reads it from there.
|
||||
std::fs::write(&path, squared_file(kind)).unwrap();
|
||||
let r = s.execute("links.update", &json!({"ids": [image.0]})).unwrap();
|
||||
assert_eq!(r["updated"], json!([image.0]), "{kind}: {r}");
|
||||
let map = s.doc().unwrap().doc.node(image).unwrap().image_map().unwrap();
|
||||
want = [[25.0, 12.5], [75.0, 12.5], [75.0, 37.5], [25.0, 37.5]]
|
||||
.iter()
|
||||
.map(|[x, y]| map.apply(vectorcraft_geom::Point::new(*x, *y)).unwrap())
|
||||
.map(|p| [p.x, p.y])
|
||||
.collect();
|
||||
}
|
||||
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");
|
||||
assert_eq!(d.node(image).unwrap().image_corners().unwrap(), corners, "{kind}, {step}, folder: {folder}");
|
||||
// The clipping path is drawn through the corners, within rounding.
|
||||
let (anchors, even_odd, held) = clip_group(d, group);
|
||||
let near =
|
||||
anchors.len() == want.len() && anchors.iter().zip(&want).all(|(p, q)| (p[0] - q[0]).abs() < 1e-6 && (p[1] - q[1]).abs() < 1e-6);
|
||||
assert!(near && (even_odd, held) == (before.1, before.2), "{kind}, {step}, folder: {folder}: {anchors:?} vs {want:?}");
|
||||
}
|
||||
}
|
||||
// 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::<Vec<_>>(), [image]),
|
||||
other => panic!("a plain group of the image: {other:?}"),
|
||||
}
|
||||
assert!(s.doc().unwrap().doc.node(image).unwrap().is_distorted_image());
|
||||
}
|
||||
|
||||
/// Unembed keeps the clip group of the clipping path an embedded PSD file's image came with, with a
|
||||
/// path and with a folder, and so do relinking to the written file, placing it and opening it.
|
||||
#[test]
|
||||
|
||||
+114
-54
@@ -33,7 +33,7 @@ use vectorcraft_doc::{
|
||||
Appearance, DataValue, Document, ImageBlob, ImageObject, LinkInfo, Node, NodeId, NodeKind, PageBox, PlacedDocument, PlacementOptions,
|
||||
StoredPlace, StoredRoot,
|
||||
};
|
||||
use vectorcraft_geom::{Affine, FillRule, PathData, Rect, shapes};
|
||||
use vectorcraft_geom::{Affine, FillRule, Homography, PathData, Rect, shapes};
|
||||
|
||||
use super::fileio::{self, RasterImage, absolute_path, file_created, file_stamp, read_file, write_file};
|
||||
use super::{CommandSpec, EngineError, Result, Session, bad, bool_or, cmd, has_doc, ids_param, object_param, str_param, switch_or, text_param};
|
||||
@@ -54,7 +54,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Update Links",
|
||||
[],
|
||||
None,
|
||||
"{ids?: [image or placed document ids] (default: the linked images whose file was modified or is showing its preview, and placed documents whose file was modified)} read their linked files again; each keeps its bounds. Images and placed documents inside symbols, graph designs, patterns, opacity masks and the art of stored brushes have ids of their own, as links.list gives them; those that show the same content as one read again are read again too. One undo step → {updated: [ids], missing: [ids], warnings?: [a DCS file's spot plate whose ink a swatch of the document already names, as file.place warns]}",
|
||||
"{ids?: [image or placed document ids] (default: the linked images whose file was modified or is showing its preview, and placed documents whose file was modified)} read their linked files again; each keeps its bounds. Images and placed documents inside symbols, graph designs, patterns, opacity masks and the art of stored brushes have ids of their own, as links.list gives them; those that show the same content as one read again are read again too. An image changed by Perspective Distort or Free Distort keeps its corners, with the file's pixels between them, and its Placement Options do not apply; the clipping path its file names is drawn through the corners, and a clip group of the old file's clipping path gets the new one, or becomes a plain group when the file names none. One undo step → {updated: [ids], missing: [ids], warnings?: [a DCS file's spot plate whose ink a swatch of the document already names, as file.place warns]}",
|
||||
has_doc,
|
||||
update
|
||||
),
|
||||
@@ -72,7 +72,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Relink",
|
||||
[],
|
||||
None,
|
||||
"{ids?: [image or placed document ids] (default: the selected ones; with folder and nothing selected, every missing link), path | folder, scope?: selected (default: ids) | all (ids and every other object linked to the same file as one of them, in the layers, opacity-mask art, symbols, graph designs, patterns and the art of stored brushes) | missingInFolder (with path: ids, then every other missing link whose file name is in path's folder, each to the file of its name there; names not there are in notFound; with copy, only images are looked for) | each (with paths), paths?: [{ids, path}] (with scope each, in place of ids, path and folder: each link to its own file; an id in two entries is an error), copy?: false (with path or paths, for images of a saved document: copy the file into the document's folder and link to the copy; the names Name.png, Name 2.png … Name 99.png are tried in turn until one is free, which gets the copy, or is a file with the same contents, which is used; an error for a DCS file that reads plate files of its own), preserve?: transforms|bounds|fileDimensions|fit|fill (how the new file takes each image's place this time, as links.placementOptions describes; default: each image's Placement Options; fit keeps the new file's aspect ratio inside the old bounds: Replace)} link images (or placed documents, each showing the same artboard or page of the new file) to the file at path, or each to the file of its link's name in folder; embedded images become linked; each keeps its bounds. One undo step → {relinked: [ids], notFound: [file names], copied?: [{from, to}], kept?: [{from, to}] (with copy; to is the file name alone when the document's folder is outside the automation read roots), warnings?: (as links.update's)}",
|
||||
"{ids?: [image or placed document ids] (default: the selected ones; with folder and nothing selected, every missing link), path | folder, scope?: selected (default: ids) | all (ids and every other object linked to the same file as one of them, in the layers, opacity-mask art, symbols, graph designs, patterns and the art of stored brushes) | missingInFolder (with path: ids, then every other missing link whose file name is in path's folder, each to the file of its name there; names not there are in notFound; with copy, only images are looked for) | each (with paths), paths?: [{ids, path}] (with scope each, in place of ids, path and folder: each link to its own file; an id in two entries is an error), copy?: false (with path or paths, for images of a saved document: copy the file into the document's folder and link to the copy; the names Name.png, Name 2.png … Name 99.png are tried in turn until one is free, which gets the copy, or is a file with the same contents, which is used; an error for a DCS file that reads plate files of its own), preserve?: transforms|bounds|fileDimensions|fit|fill (how the new file takes each image's place this time, as links.placementOptions describes; default: each image's Placement Options; fit keeps the new file's aspect ratio inside the old bounds: Replace)} link images (or placed documents, each showing the same artboard or page of the new file) to the file at path, or each to the file of its link's name in folder; embedded images become linked; each keeps its bounds. An image changed by Perspective Distort or Free Distort keeps its corners, with the new file's pixels between them, whatever preserve or its Placement Options say, and its clipping is handled as links.update handles it. One undo step → {relinked: [ids], notFound: [file names], copied?: [{from, to}], kept?: [{from, to}] (with copy; to is the file name alone when the document's folder is outside the automation read roots), warnings?: (as links.update's, and, when preserve is given, one naming the distorted images it was not applied to)}",
|
||||
has_doc,
|
||||
relink
|
||||
),
|
||||
@@ -99,7 +99,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Embed Image",
|
||||
[],
|
||||
None,
|
||||
"{ids?: [image or placed document ids] (default: the selected linked ones)} break the links (the Links panel's Break Link): images keep the linked files' pixels in the document; a placed document becomes an editable copy of its art, as placing its file without link gives (its symbols, patterns, swatches and images joining the document). An image whose file can't be found and that shows the saved preview, or a placed document whose file can't be read or changed, stays linked: relink or update it first. An image placed from a DCS file can't be embedded (an error, and nothing changes). One undo step → {embedded: [ids], missing: [ids]}",
|
||||
"{ids?: [image or placed document ids] (default: the selected linked ones)} break the links (the Links panel's Break Link): images keep the linked files' pixels in the document; a placed document becomes an editable copy of its art, as placing its file without link gives (its symbols, patterns, swatches and images joining the document). An image whose file can't be found and that shows the saved preview, or a placed document whose file can't be read or changed, stays linked: relink or update it first. An image placed from a DCS file can't be embedded (an error, and nothing changes). An image changed by Perspective Distort or Free Distort keeps its corners. One undo step → {embedded: [ids], missing: [ids]}",
|
||||
has_doc,
|
||||
embed
|
||||
),
|
||||
@@ -108,7 +108,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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; written as stored (here and with folder), an image from a PSD or PSB file keeps the clip group of the clipping path that file names, and the file written keeps the path, so Open, Place, Relink and Update Links read the file with that clip 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. 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 and link the image to it, keeping its bounds (an image changed by Perspective Distort or Free Distort keeps its corners). The image is written as stored (PNG, JPEG, GIF, WebP or TIFF; as PNG when that format is not one of VectorCraft's raster file formats) when path has no extension or names the stored format, and converted when path ends in another of .png/.jpg/.jpeg/.gif/.webp/.tif/.tiff/.bmp. Written as stored (here and with folder), an image from a PSD or PSB file keeps the clip group of the clipping path that file names, and the file written keeps the path, so Open, Place, Relink and Update Links read the file with that clip group (drawn through a distorted image's corners); a converted file holds 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
|
||||
),
|
||||
@@ -609,13 +609,14 @@ pub(crate) fn kept_unread(bytes: &[u8]) -> bool {
|
||||
/// `blob`, an image [`fileio::raster_image`] read from a file, ready to keep. When `unread` (the
|
||||
/// file is one [`kept_unread`] names), its pixels are decoded once to check that they can be read,
|
||||
/// and a `linked` image's preview is made from that decode ([`ImageBlob::checked_with_proxy`]);
|
||||
/// otherwise a `linked` image gets its preview ([`ImageBlob::with_proxy`]). An error when the
|
||||
/// pixels can't be read.
|
||||
/// otherwise a `linked` image gets its preview ([`ImageBlob::with_proxy`]). The preview keeps the
|
||||
/// clipping path the image keeps ([`fileio::preview_with_clip`]). An error when the pixels can't
|
||||
/// be read.
|
||||
pub(crate) fn readable(blob: ImageBlob, unread: bool, linked: bool) -> Result<ImageBlob> {
|
||||
if !unread {
|
||||
return Ok(if linked { blob.with_proxy() } else { blob });
|
||||
return Ok(if linked { fileio::preview_with_clip(blob.with_proxy()) } else { blob });
|
||||
}
|
||||
blob.checked_with_proxy(linked).ok_or_else(|| EngineError::Other("the image's pixels can't be read".into()))
|
||||
blob.checked_with_proxy(linked).map(fileio::preview_with_clip).ok_or_else(|| EngineError::Other("the image's pixels can't be read".into()))
|
||||
}
|
||||
|
||||
/// [`readable`], and the pixels it decoded are kept in the image store the renderers share
|
||||
@@ -626,6 +627,7 @@ pub(crate) fn readable_and_kept(blob: ImageBlob, unread: bool, linked: bool) ->
|
||||
return readable(blob, unread, linked);
|
||||
}
|
||||
let (blob, pixels) = blob.checked_with_pixels(linked).ok_or_else(|| EngineError::Other("the image's pixels can't be read".into()))?;
|
||||
let blob = fileio::preview_with_clip(blob);
|
||||
if let Some(pixels) = pixels {
|
||||
vectorcraft_render::keep_decoded_image(&blob, pixels);
|
||||
}
|
||||
@@ -792,13 +794,20 @@ fn clip_to(
|
||||
new_xf: Affine,
|
||||
held: Option<(&PathData, FillRule)>,
|
||||
) -> ClipTo {
|
||||
let old = old_clip.filter(|_| held.is_some()).map(|(path, rule)| (path.transformed(old_xf), *rule));
|
||||
let file = img.clip.as_ref().map(|(path, rule)| (path.transformed(new_xf), *rule));
|
||||
placed_clip_to(old.as_ref(), clip, file, held)
|
||||
}
|
||||
|
||||
/// [`clip_to`] with the clipping paths of the old file (`old`) and of the new file (`file`) already
|
||||
/// on the page.
|
||||
fn placed_clip_to(old: Option<&FileClip>, clip: Option<Clip>, file: Option<FileClip>, held: Option<(&PathData, FillRule)>) -> ClipTo {
|
||||
// Whether the clip group holding just the image is the old file's: a clipping path whose fill
|
||||
// rule was changed in the document is not.
|
||||
let file_held = match (old_clip, held) {
|
||||
(Some((old, old_rule)), Some((held, rule))) => rule == *old_rule && same_path(&old.transformed(old_xf), held),
|
||||
let file_held = match (old, held) {
|
||||
(Some((old, old_rule)), Some((held, rule))) => rule == *old_rule && same_path(old, held),
|
||||
_ => false,
|
||||
};
|
||||
let file = img.clip.as_ref().map(|(path, rule)| (path.transformed(new_xf), *rule));
|
||||
if let Some(clip) = clip {
|
||||
let placement = clip_shape(clip);
|
||||
return match file {
|
||||
@@ -1211,14 +1220,44 @@ pub(crate) fn set_image_from_path(d: &mut Document, id: NodeId, path: &str, doc_
|
||||
install(d, &[id], read, Some(Preserve::Bounds), None)
|
||||
}
|
||||
|
||||
/// Distorted image `im` shows the file read for `link` (`img`) and keeps its corners and its
|
||||
/// clipping: the new pixels fill them. Its transform is scaled to the new pixel size, so a reader
|
||||
/// that places it by the transform still gives it its old size.
|
||||
fn refill_distorted(im: &mut ImageObject, link: &LinkInfo, img: &RasterImage) {
|
||||
if (img.width, img.height) != (im.width, im.height) && img.width > 0 && img.height > 0 {
|
||||
im.xf *= Affine::scale_non_uniform(f64::from(im.width) / f64::from(img.width), f64::from(im.height) / f64::from(img.height));
|
||||
/// Distorted image `n` shows the file read for `link` (`img`) and keeps its corners: the new pixels
|
||||
/// fill them. Its transform is scaled to the new pixel size, so a reader that places it by the
|
||||
/// transform still gives it its old size. Its Placement Options do not apply. The result is what
|
||||
/// happens to its clip, as [`clip_to`] decides from the clipping path of the clip group holding
|
||||
/// just it (`held`): the clipping paths of its old file (`old_clip`, in its old pixels) and of the
|
||||
/// new file (`img.clip`, else the path kept in its stored PNG or TIFF, as Unembed writes it:
|
||||
/// [`file_clip`]) are mapped to the page through its corners, anchors and handles alike, as a
|
||||
/// distort maps a path's.
|
||||
fn refill_distorted(n: &mut Node, old_clip: Option<&FileClip>, link: &LinkInfo, img: &RasterImage, held: Option<(&PathData, FillRule)>) -> ClipTo {
|
||||
let old = old_clip.filter(|_| held.is_some()).and_then(|(path, rule)| Some((warped(path, &n.image_map()?)?, *rule)));
|
||||
if let NodeKind::Image(im) = &mut n.kind {
|
||||
if (img.width, img.height) != (im.width, im.height) && img.width > 0 && img.height > 0 {
|
||||
im.xf *= Affine::scale_non_uniform(f64::from(im.width) / f64::from(img.width), f64::from(im.height) / f64::from(img.height));
|
||||
}
|
||||
(im.key, im.width, im.height, im.link) = (img.key.clone(), img.width, img.height, Some(link.clone()));
|
||||
}
|
||||
(im.key, im.width, im.height, im.link) = (img.key.clone(), img.width, img.height, Some(link.clone()));
|
||||
let file = img.clip.clone().or_else(|| file_clip(&img.blob)).and_then(|(path, rule)| Some((warped(&path, &n.image_map()?)?, rule)));
|
||||
placed_clip_to(old.as_ref(), None, file, held)
|
||||
}
|
||||
|
||||
/// `path` with its anchors and handles mapped through `map` as a distort maps a path's points
|
||||
/// (`xform::Projective::apply`): a point on the map's horizon is mapped as if a billionth in front
|
||||
/// of it, and one past it to the far side. `None` when a point maps to no finite page point.
|
||||
fn warped(path: &PathData, map: &Homography) -> Option<PathData> {
|
||||
let [[a, b, c], [d, e, f], [g, h, i]] = map.0;
|
||||
let apply = |p: vectorcraft_geom::Point| {
|
||||
let w = g * p.x + h * p.y + i;
|
||||
let w = if w.abs() < 1e-9 { 1e-9_f64.copysign(w) } else { w };
|
||||
let q = vectorcraft_geom::Point::new((a * p.x + b * p.y + c) / w, (d * p.x + e * p.y + f) / w);
|
||||
q.is_finite().then_some(q)
|
||||
};
|
||||
let mut out = path.clone();
|
||||
for sp in &mut out.subpaths {
|
||||
for anchor in &mut sp.anchors {
|
||||
(anchor.p, anchor.h_in, anchor.h_out) = (apply(anchor.p)?, apply(anchor.h_in)?, apply(anchor.h_out)?);
|
||||
}
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
/// Image objects `ids` (in the layers or outside them) show the file read for `link` (`img`), each
|
||||
@@ -1245,12 +1284,15 @@ fn install(d: &mut Document, ids: &[NodeId], (link, img): FileRead, force: Optio
|
||||
let mut make = |n: &Node, held: Option<(&PathData, FillRule)>| {
|
||||
let mut n = n.clone();
|
||||
let mut clip = ClipTo::Keep;
|
||||
let distorted = n.is_distorted_image();
|
||||
if n.is_distorted_image() {
|
||||
let old_clip = match &n.kind {
|
||||
NodeKind::Image(im) => old.get(&im.key).and_then(|(_, clip)| clip.clone()),
|
||||
_ => None,
|
||||
};
|
||||
let clip = refill_distorted(&mut n, old_clip.as_ref(), &link, &img, held);
|
||||
return (n, clip);
|
||||
}
|
||||
if let NodeKind::Image(im) = &mut n.kind {
|
||||
if distorted {
|
||||
refill_distorted(im, &link, &img);
|
||||
return (n, clip);
|
||||
}
|
||||
let o = PlacementOptions { preserve: force.unwrap_or(im.placement.preserve), ..im.placement };
|
||||
let size = |w: u32, h: u32| (w as f64, h as f64);
|
||||
let (old_pt, old_clip) = match old.get(&im.key) {
|
||||
@@ -1267,10 +1309,13 @@ fn install(d: &mut Document, ids: &[NodeId], (link, img): FileRead, force: Optio
|
||||
}
|
||||
for id in ids {
|
||||
if d.node(*id).is_some_and(Node::is_distorted_image) {
|
||||
if let Some(n) = d.node_mut(*id)
|
||||
&& let NodeKind::Image(im) = &mut n.kind
|
||||
{
|
||||
refill_distorted(im, &link, &img);
|
||||
let old_clip = match d.node(*id).map(|n| &n.kind) {
|
||||
Some(NodeKind::Image(im)) => d.images.get(&im.key).and_then(file_clip),
|
||||
_ => None,
|
||||
};
|
||||
let held = clip_path_of(d, *id).map(|(path, rule)| (path.clone(), rule));
|
||||
if let Some(n) = d.node_mut(*id) {
|
||||
clips.push((*id, refill_distorted(n, old_clip.as_ref(), &link, &img, held.as_ref().map(|(path, rule)| (path, *rule)))));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -1625,7 +1670,7 @@ fn resolve_links(d: &mut Document, base: LinkBase, update: bool, low_res_proxy_e
|
||||
store_image(d, &g.key, blob, true);
|
||||
} else if let Some(b) = d.images.get(&g.key).filter(|b| b.proxy.is_none()) {
|
||||
// Linked before links kept a preview.
|
||||
let b = b.clone().with_proxy();
|
||||
let b = fileio::preview_with_clip(b.clone().with_proxy());
|
||||
d.images.insert(g.key.clone(), b);
|
||||
}
|
||||
// Found away from its path, or read again: the link follows.
|
||||
@@ -2091,9 +2136,6 @@ fn relink(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
_ => None,
|
||||
})
|
||||
};
|
||||
// Whether the images were found as the missing links (nothing selected, a folder given) rather
|
||||
// than named or selected.
|
||||
let mut found_missing = false;
|
||||
let mut ids: Vec<NodeId> = match (&each, ids_param(p, "ids", C)?) {
|
||||
(Some(each), _) => each.iter().flat_map(|(ids, _)| ids.iter().copied()).collect(),
|
||||
(None, Some(ids)) => ids,
|
||||
@@ -2101,7 +2143,6 @@ fn relink(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let selected: Vec<NodeId> = st.selection.objects.iter().copied().filter(|id| image(id).is_some()).collect();
|
||||
match folder_param {
|
||||
Some(_) if selected.is_empty() => {
|
||||
found_missing = true;
|
||||
groups(&st.doc, None).into_iter().filter(|g| probe(g, LinkBase::of(st)).0 == Status::Missing).flat_map(|g| g.ids).collect()
|
||||
}
|
||||
_ => selected,
|
||||
@@ -2114,11 +2155,6 @@ fn relink(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if ids.is_empty() {
|
||||
return Err(bad(C, "select the images to relink, or pass ids"));
|
||||
}
|
||||
// A named or selected distorted image is refused before a folder is searched, whether or not
|
||||
// its file is found there.
|
||||
if !found_missing && let Some(id) = ids.iter().find(|id| stored(&doc, **id).is_some_and(Node::is_distorted_image)) {
|
||||
return Err(super::xform::distorted_image_error(C, *id));
|
||||
}
|
||||
// All Instances: the other stored objects linked to the same files, each once.
|
||||
if scope == Scope::All {
|
||||
let paths: BTreeSet<&str> = ids.iter().filter_map(|id| image(id).flatten()).map(|l| l.path.as_str()).collect();
|
||||
@@ -2163,11 +2199,6 @@ fn relink(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
(None, None, None) => return Err(bad(C, "give path (a file) or folder")),
|
||||
}
|
||||
// A new file's placement options place a plain image: a distorted one is left as it is.
|
||||
let distorted = files.iter().flat_map(|(ids, _)| ids).find(|id| stored(&doc, **id).is_some_and(Node::is_distorted_image));
|
||||
if let Some(id) = distorted {
|
||||
return Err(super::xform::distorted_image_error(C, *id));
|
||||
}
|
||||
// Every file is read and checked before any is copied.
|
||||
let mut checked = vec![];
|
||||
for (ids, path) in files {
|
||||
@@ -2227,8 +2258,10 @@ fn relink(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
}
|
||||
let relinked: Vec<u64> = reads.iter().flat_map(|(ids, _)| ids_json(ids)).collect();
|
||||
let unpreserved = preserve.and_then(|_| unpreserved_note(&doc, &reads));
|
||||
drop(doc);
|
||||
let warnings = spot_swatch_notes(&s.doc()?.doc, reads.iter().map(|(_, read)| read));
|
||||
let mut warnings = spot_swatch_notes(&s.doc()?.doc, reads.iter().map(|(_, read)| read));
|
||||
warnings.extend(unpreserved);
|
||||
if !reads.is_empty() {
|
||||
s.edit("Relink", |d, _| editing_brush_art(d, |d| reads.into_iter().try_for_each(|(ids, read)| install_read(d, &ids, read, preserve, None))))?;
|
||||
}
|
||||
@@ -2251,6 +2284,23 @@ fn relink(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The warning that Relink's `preserve` was not applied to the images of `reads` changed by
|
||||
/// Perspective Distort or Free Distort, which keep their corners, naming them; `None` when there
|
||||
/// are none.
|
||||
fn unpreserved_note(doc: &Document, reads: &[(Vec<NodeId>, Read)]) -> Option<String> {
|
||||
let ids: Vec<String> = reads
|
||||
.iter()
|
||||
.filter(|(_, read)| matches!(read, Read::Image(_)))
|
||||
.flat_map(|(ids, _)| ids)
|
||||
.filter(|id| stored(doc, **id).is_some_and(Node::is_distorted_image))
|
||||
.map(|id| id.0.to_string())
|
||||
.collect();
|
||||
let images = if ids.len() == 1 { "image" } else { "images" };
|
||||
(!ids.is_empty()).then(|| {
|
||||
format!("preserve was not applied to {images} {}: an image changed by Perspective Distort or Free Distort keeps its corners", ids.join(", "))
|
||||
})
|
||||
}
|
||||
|
||||
/// `links.relink {scope: "missingInFolder"}`: the other missing links of `st` (not `given`; only
|
||||
/// images when `images_only`, as copy takes), each added to `files` with the file of its name in
|
||||
/// the folder of the first file there; names not there go to `not_found`.
|
||||
@@ -2630,9 +2680,6 @@ fn embed(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if ids.is_empty() {
|
||||
return Err(bad(C, "select the linked images or placed documents, or pass ids"));
|
||||
}
|
||||
if let Some(id) = ids.iter().find(|id| stored(&doc, **id).is_some_and(Node::is_distorted_image)) {
|
||||
return Err(super::xform::distorted_image_error(C, *id));
|
||||
}
|
||||
// A DCS file's plates print from its file.
|
||||
let separated = |id: &NodeId| match kind(id) {
|
||||
Some(NodeKind::Image(im)) => st.doc.images.get(&im.key).is_some_and(ImageBlob::is_separated),
|
||||
@@ -2761,11 +2808,8 @@ fn unembed(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if im.link.is_some() {
|
||||
return Err(bad(C, format!("image {} is linked already", id.0)));
|
||||
}
|
||||
if n.is_distorted_image() {
|
||||
return Err(super::xform::distorted_image_error(C, id));
|
||||
}
|
||||
let blob = st.doc.images.get(&im.key).filter(|b| !b.is_proxy()).ok_or_else(|| bad(C, "the image's pixels aren't in the document"))?;
|
||||
// As stored (PNG, JPEG, GIF, WebP), unless the path names another format.
|
||||
// As stored (PNG, JPEG, GIF, WebP, or TIFF for an image that keeps CMYK inks), unless the path names another format.
|
||||
let stored = stored_extension(blob);
|
||||
let path = str_param(p, "path");
|
||||
let ext = match path.map(fileio::extension) {
|
||||
@@ -2815,9 +2859,6 @@ fn unembed_to_folder(s: &mut Session, p: &Value, ids: Option<Vec<NodeId>>) -> Re
|
||||
skipped.push(id);
|
||||
continue;
|
||||
}
|
||||
if n.is_distorted_image() {
|
||||
return Err(super::xform::distorted_image_error(C, id));
|
||||
}
|
||||
let blob = st.doc.images.get(&im.key).filter(|b| !b.is_proxy()).ok_or_else(|| bad(C, "the image's pixels aren't in the document"))?;
|
||||
embedded.push((id, n.display_name(), blob));
|
||||
}
|
||||
@@ -3137,4 +3178,23 @@ mod tests {
|
||||
let long = unembed_stem(&"é".repeat(200));
|
||||
assert!(long.len() <= 150 && long.chars().all(|c| c == 'é'), "{}", long.len());
|
||||
}
|
||||
|
||||
/// A clipping path mapped through a distorted image's corners keeps the points that lie on or
|
||||
/// past the map's horizon, each mapped as a distort maps a path's point.
|
||||
#[test]
|
||||
fn points_past_the_horizon_are_mapped_as_a_distort_maps_them() {
|
||||
use vectorcraft_geom::{Anchor, Point, SubPath};
|
||||
// w = 1 + x / 100: the horizon is the line x = -100.
|
||||
let map = Homography([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.01, 0.0, 1.0]]);
|
||||
let (at, handle, on) = (Point::new(0.0, 0.0), Point::new(-200.0, 0.0), Point::new(-100.0, 5.0));
|
||||
assert!(map.apply(handle).is_none() && map.apply(on).is_none());
|
||||
let path = PathData::new(vec![SubPath::new(vec![Anchor::smooth(at, handle), Anchor::corner(on)], false)]);
|
||||
let out = warped(&path, &map).expect("a path");
|
||||
let (first, second) = (out.subpaths[0].anchors[0], out.subpaths[0].anchors[1]);
|
||||
assert_eq!((first.p, first.h_in), (at, Point::new(200.0 / 3.0, 0.0)));
|
||||
// w = -1: the handle maps to the far side.
|
||||
assert_eq!(first.h_out, Point::new(200.0, 0.0));
|
||||
// w = 0 is taken as a billionth.
|
||||
assert!(second.p.is_finite() && (second.p.x.abs() - 1e11).abs() < 1.0 && (second.p.y.abs() - 5e9).abs() < 1.0, "{:?}", second.p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1188,8 +1188,8 @@ pub(crate) fn image_info(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let doc = super::links::with_brush_art(&st.doc);
|
||||
let n = doc.stored_node(id).map(|(n, _)| &**n).ok_or(EngineError::NoNode(id))?;
|
||||
let NodeKind::Image(im) = &n.kind else { return Err(bad(C, format!("object {} is not an image", id.0))) };
|
||||
// Effective resolution, taken at the middle of a distorted image.
|
||||
let ppi = effective_ppi(vectorcraft_doc::image_quad::nearest_affine(n).unwrap_or(im.xf));
|
||||
// Effective resolution at the middle of a distorted image.
|
||||
let xf = vectorcraft_doc::image_quad::nearest_affine(n).unwrap_or(im.xf);
|
||||
let size = n.geometric_bounds().unwrap_or_default();
|
||||
// A linked file outside the read roots of the caller asking now is left unnamed, as in Link Info.
|
||||
let doc_path = super::links::LinkBase::of(st).doc;
|
||||
@@ -1201,7 +1201,7 @@ pub(crate) fn image_info(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
"colorMode": st.doc.images.get(&im.key).map_or("RGB", |b| color_mode(&b.bytes)),
|
||||
"pixelWidth": im.width,
|
||||
"pixelHeight": im.height,
|
||||
"ppi": ppi,
|
||||
"ppi": effective_ppi(xf),
|
||||
"width": size.width(),
|
||||
"height": size.height(),
|
||||
}))
|
||||
|
||||
@@ -89,11 +89,13 @@ fn check(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
continue;
|
||||
};
|
||||
let bounds = doc.node(source).and_then(|n| vectorcraft_render::painted_bounds(&doc, n));
|
||||
// A distorted image is measured at its middle, as Link Info measures it.
|
||||
let xf = doc.node(source).and_then(vectorcraft_doc::image_quad::nearest_affine).unwrap_or(im.xf);
|
||||
let ppi = context
|
||||
.pages
|
||||
.iter()
|
||||
.filter(|(area, _)| bounds.is_some_and(|b| area.intersect(b).area() > 0.0))
|
||||
.map(|(_, to_page)| super::place::effective_ppi(*to_page * im.xf))
|
||||
.map(|(_, to_page)| super::place::effective_ppi(*to_page * xf))
|
||||
.reduce(|[a, b], [c, d]| [a.min(c), b.min(d)]);
|
||||
let Some(ppi) = ppi else {
|
||||
resolution_unchecked += 1;
|
||||
|
||||
@@ -220,6 +220,53 @@ fn update_link_takes_the_files_new_clipping_path() {
|
||||
assert!((after - before / 2.0).abs() < 1e-6, "the clipping path follows the file: {before} → {after}");
|
||||
}
|
||||
|
||||
/// For an image changed by Perspective Distort or Free Distort, Update Links and Relink draw the
|
||||
/// DCS file's new clipping path through the image's corners, and a file without one leaves a plain
|
||||
/// group.
|
||||
#[test]
|
||||
fn update_and_relink_draw_the_files_clipping_path_through_a_distorted_images_corners() {
|
||||
let dir = temp_dir("distorted-clip");
|
||||
let path = write(&dir, "pic.eps", &two_plates());
|
||||
let mut s = session();
|
||||
let r = s.execute("file.place", &json!({ "path": path, "at": [100, 100] })).unwrap();
|
||||
let group = NodeId(r["ids"][0].as_u64().unwrap());
|
||||
let id = image_of(&s, &r["ids"][0]).id;
|
||||
s.execute("select.set", &json!({ "ids": [group.0] })).unwrap();
|
||||
s.execute("object.distort", &json!({ "corners": [[100, 100], [160, 104], [150, 140], [96, 136]] })).unwrap();
|
||||
let node = |s: &Session| s.doc().unwrap().doc.node(id).unwrap().clone();
|
||||
assert!(node(&s).is_distorted_image());
|
||||
let corners = node(&s).image_corners().unwrap();
|
||||
// The clip group's path anchors, and points of the 2 × 2 pixels where the corners put them.
|
||||
let anchors = |s: &Session| {
|
||||
let NodeKind::Group { children, clip: true } = &s.doc().unwrap().doc.node(group).unwrap().kind else { panic!("a clipping group") };
|
||||
let NodeKind::Path { path, clipping: true, .. } = &children[0].kind else { panic!("a clipping path") };
|
||||
path.anchors().map(|(_, _, a)| a.p).collect::<Vec<_>>()
|
||||
};
|
||||
let on_page = |s: &Session, x: f64| {
|
||||
let map = node(s).image_map().unwrap();
|
||||
[(0.0, 0.0), (x, 0.0), (x, 2.0), (0.0, 2.0)].map(|(px, py)| map.apply(vectorcraft_geom::Point::new(px, py)).unwrap())
|
||||
};
|
||||
let matches = |found: &[vectorcraft_geom::Point], want: &[vectorcraft_geom::Point]| {
|
||||
found.len() == want.len() && want.iter().all(|w| found.iter().any(|f| f.distance(*w) < 1e-6))
|
||||
};
|
||||
assert!(matches(&anchors(&s), &on_page(&s, 1.0)), "the left half: {:?} vs {:?}", anchors(&s), on_page(&s, 1.0));
|
||||
// The same file, its composite drawn through the left quarter of the page (same length).
|
||||
let quarter = String::from_utf8(two_plates()).unwrap().replacen("10 0 lineto 10 10 lineto", " 5 0 lineto 5 10 lineto", 1);
|
||||
std::fs::write(&path, quarter.as_bytes()).unwrap();
|
||||
s.execute("links.update", &json!({ "ids": [id.0] })).unwrap();
|
||||
assert!(matches(&anchors(&s), &on_page(&s, 0.5)), "the left quarter: {:?} vs {:?}", anchors(&s), on_page(&s, 0.5));
|
||||
assert_eq!(node(&s).image_corners().unwrap(), corners);
|
||||
// Relink to a file whose composite has no clipping path.
|
||||
let unclipped = String::from_utf8(two_plates()).unwrap().replacen("closepath clip newpath", "closepath newpath ", 1);
|
||||
let other = write(&dir, "other.eps", unclipped.as_bytes());
|
||||
s.execute("links.relink", &json!({ "ids": [id.0], "path": other })).unwrap();
|
||||
match &s.doc().unwrap().doc.node(group).unwrap().kind {
|
||||
NodeKind::Group { children, clip: false } => assert_eq!(children.iter().map(|c| c.id).collect::<Vec<_>>(), [id]),
|
||||
other => panic!("a plain group of the image: {other:?}"),
|
||||
}
|
||||
assert_eq!(node(&s).image_corners().unwrap(), corners);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_link_clips_an_image_whose_file_gained_a_clipping_path() {
|
||||
let dir = temp_dir("update-gained-clip");
|
||||
|
||||
@@ -663,6 +663,213 @@ fn update_links_keeps_a_distorted_images_corners() {
|
||||
scale_matches_ppi(&mut s);
|
||||
}
|
||||
|
||||
/// Relink with scope `all` puts the new file's pixels between the corners of the distorted images
|
||||
/// in symbols too, and scales each one's transform to the new pixel size, so a placement by the
|
||||
/// transform keeps the old size.
|
||||
#[test]
|
||||
fn relink_of_all_instances_keeps_the_corners_of_distorted_images_in_symbols() {
|
||||
let dir = Folder::new("distorted-relink-all");
|
||||
let (photo, other) = (dir.file("photo.png"), dir.file("other.png"));
|
||||
write(&photo, &png(20, 10, RED));
|
||||
write(&other, &png(60, 20, BLUE));
|
||||
let mut s = session();
|
||||
let id = place(&mut s, &photo);
|
||||
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
|
||||
s.execute("object.distort", &json!({"corners": [[150, 100], [250, 110], [260, 200], [140, 190]]})).unwrap();
|
||||
let before = s.doc().unwrap().doc.node(id).unwrap().image_corners().unwrap();
|
||||
// The far corner of the pixels as the transform alone places them.
|
||||
let far = |s: &Session| {
|
||||
let NodeKind::Image(im) = &s.doc().unwrap().doc.node(id).unwrap().kind else { panic!("an image") };
|
||||
im.xf * vectorcraft_geom::Point::new(f64::from(im.width), f64::from(im.height))
|
||||
};
|
||||
let far_before = far(&s);
|
||||
// A distorted copy in a symbol shows the same file.
|
||||
let copy = place(&mut s, &photo);
|
||||
s.execute("select.set", &json!({"ids": [copy.0]})).unwrap();
|
||||
s.execute("object.distort", &json!({"corners": [[10, 10], [60, 15], [58, 50], [5, 45]]})).unwrap();
|
||||
s.execute("symbol.new", &json!({"name": "Mark", "ids": [copy.0]})).unwrap();
|
||||
let in_symbol = |s: &Session| {
|
||||
let mut out = vec![];
|
||||
s.doc().unwrap().doc.symbols[0].art.walk(&mut |n| {
|
||||
if let NodeKind::Image(im) = &n.kind {
|
||||
out.push((n.image_quad(), (im.width, im.height)));
|
||||
}
|
||||
});
|
||||
out
|
||||
};
|
||||
let [(Some(symbol_quad), (20, 10))] = in_symbol(&s)[..] else { panic!("one distorted image in the symbol: {:?}", in_symbol(&s)) };
|
||||
let r = s.execute("links.relink", &json!({"ids": [id.0], "path": other, "scope": "all"})).unwrap();
|
||||
let relinked = r["relinked"].as_array().unwrap();
|
||||
assert!(relinked.len() == 2 && relinked.contains(&json!(id.0)), "the image and the symbol's: {r}");
|
||||
assert!(r.get("warnings").is_none(), "no preserve was given: {r}");
|
||||
let n = s.doc().unwrap().doc.node(id).unwrap().clone();
|
||||
assert_eq!((n.is_distorted_image(), n.image_corners().unwrap()), (true, before));
|
||||
assert_eq!((image(&s, id).width, image(&s, id).height), (60, 20));
|
||||
assert!(far(&s).distance(far_before) < 1e-9, "{:?} vs {far_before:?}", far(&s));
|
||||
assert_eq!(in_symbol(&s), [(Some(symbol_quad), (60, 20))], "the symbol's image keeps its corners");
|
||||
}
|
||||
|
||||
/// Relink with scope `all` puts the new file's pixels between the corners of a distorted image in
|
||||
/// an opacity mask's art.
|
||||
#[test]
|
||||
fn relink_of_all_instances_keeps_the_corners_of_a_distorted_image_in_an_opacity_mask() {
|
||||
let dir = Folder::new("distorted-relink-mask");
|
||||
let (photo, other) = (dir.file("photo.png"), dir.file("other.png"));
|
||||
write(&photo, &png(20, 10, RED));
|
||||
write(&other, &png(60, 20, BLUE));
|
||||
let mut s = session();
|
||||
let id = place(&mut s, &photo);
|
||||
let masked = super::rect(&mut s, 10.0, 10.0, 60.0, 60.0);
|
||||
let mask = place(&mut s, &photo);
|
||||
s.execute("select.set", &json!({"ids": [mask.0]})).unwrap();
|
||||
s.execute("object.distort", &json!({"corners": [[10, 10], [60, 15], [58, 50], [5, 45]]})).unwrap();
|
||||
s.execute("transparency.makeOpacityMask", &json!({"ids": [masked.0, mask.0]})).unwrap();
|
||||
// The image in the art of `masked`'s opacity mask: (id, corners, pixel size).
|
||||
let in_mask = |s: &Session| {
|
||||
let mut out = vec![];
|
||||
s.doc().unwrap().doc.visit_stored(|n, place| {
|
||||
if let NodeKind::Image(im) = &n.kind
|
||||
&& place.mask_of == Some(masked)
|
||||
{
|
||||
out.push((n.id, n.image_quad(), (im.width, im.height)));
|
||||
}
|
||||
});
|
||||
out
|
||||
};
|
||||
let [(mask_id, Some(quad), (20, 10))] = in_mask(&s)[..] else { panic!("one distorted image in the mask: {:?}", in_mask(&s)) };
|
||||
let r = s.execute("links.relink", &json!({"ids": [id.0], "path": other, "scope": "all"})).unwrap();
|
||||
let relinked = r["relinked"].as_array().unwrap();
|
||||
assert!(relinked.len() == 2 && relinked.contains(&json!(mask_id.0)), "the image and the mask's: {r}");
|
||||
assert_eq!(in_mask(&s), [(mask_id, Some(quad), (60, 20))], "the mask's image keeps its corners");
|
||||
}
|
||||
|
||||
/// Relink, Embed and Unembed keep a distorted image's corners, each in one undo step: Relink puts
|
||||
/// the new file's pixels between them whatever `preserve` and the Placement Options say, Embed
|
||||
/// keeps the pixels in the document, and Unembed links the image to the file it writes.
|
||||
#[test]
|
||||
fn relink_embed_and_unembed_keep_a_distorted_images_corners() {
|
||||
let dir = Folder::new("distorted-relink");
|
||||
let (photo, other, written) = (dir.file("photo.png"), dir.file("other.png"), dir.file("written.png"));
|
||||
write(&photo, &png(20, 10, RED));
|
||||
write(&other, &png(60, 20, BLUE));
|
||||
let mut s = session();
|
||||
let id = place(&mut s, &photo);
|
||||
s.execute("links.placementOptions", &json!({"ids": [id.0], "preserve": "fill", "clip": true})).unwrap();
|
||||
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
|
||||
// Around the artboard's center, where `centre_colour` looks.
|
||||
s.execute("object.distort", &json!({"corners": [[150, 100], [250, 110], [260, 200], [140, 190]]})).unwrap();
|
||||
let corners = |s: &Session| s.doc().unwrap().doc.node(id).unwrap().image_corners().unwrap();
|
||||
let before = corners(&s);
|
||||
let distorted = |s: &Session| s.doc().unwrap().doc.node(id).unwrap().is_distorted_image();
|
||||
let clipped = |s: &Session| {
|
||||
let d = &s.doc().unwrap().doc;
|
||||
matches!(d.parent_of(id).and_then(|p| d.node(p)).map(|p| &p.kind), Some(NodeKind::Group { clip: true, .. }))
|
||||
};
|
||||
let undo_len = |s: &Session| s.doc().unwrap().history.undo.len();
|
||||
assert!(near(centre_colour(&s.doc().unwrap().doc), RED));
|
||||
|
||||
let undo = undo_len(&s);
|
||||
let r = s.execute("links.relink", &json!({"ids": [id.0], "path": other, "preserve": "fileDimensions"})).unwrap();
|
||||
// The given preserve is reported as not applied.
|
||||
let warning = format!("preserve was not applied to image {}: an image changed by Perspective Distort or Free Distort keeps its corners", id.0);
|
||||
assert_eq!(r, json!({"relinked": [id.0], "notFound": [], "warnings": [warning]}));
|
||||
assert_eq!(undo_len(&s), undo + 1);
|
||||
assert!(distorted(&s));
|
||||
assert_eq!(corners(&s), before);
|
||||
assert!(!clipped(&s), "not clipped by its Placement Options");
|
||||
let im = image(&s, id);
|
||||
assert_eq!((im.width, im.height), (60, 20));
|
||||
assert_eq!(im.link.as_ref().map(|l| l.path.as_str()), Some(other.as_str()));
|
||||
assert!(near(centre_colour(&s.doc().unwrap().doc), BLUE));
|
||||
|
||||
let r = s.execute("links.embed", &json!({"ids": [id.0]})).unwrap();
|
||||
assert_eq!(r["embedded"], json!([id.0]), "{r}");
|
||||
assert_eq!(undo_len(&s), undo + 2);
|
||||
assert!(distorted(&s));
|
||||
assert_eq!(corners(&s), before);
|
||||
assert!(image(&s, id).link.is_none());
|
||||
assert!(near(centre_colour(&s.doc().unwrap().doc), BLUE));
|
||||
|
||||
let r = s.execute("links.unembed", &json!({"id": id.0, "path": written})).unwrap();
|
||||
assert_eq!(r["id"], json!(id.0), "{r}");
|
||||
assert_eq!(undo_len(&s), undo + 3);
|
||||
assert!(distorted(&s));
|
||||
assert_eq!(corners(&s), before);
|
||||
assert!(!clipped(&s));
|
||||
let im = image(&s, id);
|
||||
assert_eq!((im.width, im.height), (60, 20));
|
||||
assert!(im.link.is_some());
|
||||
assert!(Path::new(&written).exists());
|
||||
assert!(near(centre_colour(&s.doc().unwrap().doc), BLUE));
|
||||
|
||||
// Undo takes each back to the same corners, and the first file's pixels in the end.
|
||||
for _ in 0..3 {
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert!(distorted(&s));
|
||||
assert_eq!(corners(&s), before);
|
||||
}
|
||||
assert_eq!((image(&s, id).width, image(&s, id).height), (20, 10));
|
||||
assert!(near(centre_colour(&s.doc().unwrap().doc), RED));
|
||||
}
|
||||
|
||||
/// Unembed into a folder keeps a distorted image's corners, in one undo step.
|
||||
#[test]
|
||||
fn unembed_to_a_folder_keeps_a_distorted_images_corners() {
|
||||
let dir = Folder::new("distorted-unembed-folder");
|
||||
let (photo, out) = (dir.file("photo.png"), dir.file("out"));
|
||||
std::fs::create_dir_all(&out).unwrap();
|
||||
write(&photo, &png(20, 10, RED));
|
||||
let mut s = session();
|
||||
let id = place(&mut s, &photo);
|
||||
s.execute("links.embed", &json!({"ids": [id.0]})).unwrap();
|
||||
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
|
||||
s.execute("object.distort", &json!({"corners": [[150, 100], [250, 110], [260, 200], [140, 190]]})).unwrap();
|
||||
let corners = |s: &Session| s.doc().unwrap().doc.node(id).unwrap().image_corners().unwrap();
|
||||
let before = corners(&s);
|
||||
let undo = s.doc().unwrap().history.undo.len();
|
||||
let r = s.execute("links.unembed", &json!({"ids": [id.0], "folder": out})).unwrap();
|
||||
assert_eq!(r["unembedded"][0]["id"], json!(id.0), "{r}");
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1);
|
||||
assert!(s.doc().unwrap().doc.node(id).unwrap().is_distorted_image());
|
||||
assert_eq!(corners(&s), before);
|
||||
assert!(image(&s, id).link.is_some());
|
||||
assert!(near(centre_colour(&s.doc().unwrap().doc), RED));
|
||||
}
|
||||
|
||||
/// Embed reads the file of a distorted image that shows its saved preview and keeps the file's
|
||||
/// pixels in the document between the image's corners, in one undo step.
|
||||
#[test]
|
||||
fn embed_reads_a_distorted_images_file_between_its_corners() {
|
||||
let dir = Folder::new("distorted-embed-preview");
|
||||
let photo = dir.file("photo.png");
|
||||
// Large enough that the document saves a smaller preview of it.
|
||||
write(&photo, &png(600, 300, RED));
|
||||
let mut s = session();
|
||||
let id = place(&mut s, &photo);
|
||||
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
|
||||
s.execute("object.distort", &json!({"corners": [[150, 100], [250, 110], [260, 200], [140, 190]]})).unwrap();
|
||||
let corners = |s: &Session| s.doc().unwrap().doc.node(id).unwrap().image_corners().unwrap();
|
||||
let before = corners(&s);
|
||||
let doc_path = dir.file("poster.vectorcraft");
|
||||
save(&mut s, &doc_path);
|
||||
std::fs::remove_file(&photo).unwrap();
|
||||
open(&mut s, &doc_path);
|
||||
assert!(s.doc().unwrap().doc.images[&image(&s, id).key].is_proxy(), "the preview stands in");
|
||||
assert!(s.doc().unwrap().doc.node(id).unwrap().is_distorted_image());
|
||||
write(&photo, &png(400, 200, BLUE));
|
||||
let undo = s.doc().unwrap().history.undo.len();
|
||||
let r = s.execute("links.embed", &json!({"ids": [id.0]})).unwrap();
|
||||
assert_eq!(r, json!({"embedded": [id.0], "missing": []}));
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1);
|
||||
let n = s.doc().unwrap().doc.node(id).unwrap().clone();
|
||||
assert!(n.is_distorted_image());
|
||||
assert_eq!(n.image_corners().unwrap(), before);
|
||||
let im = image(&s, id);
|
||||
assert_eq!((im.width, im.height, im.link.is_none()), (400, 200, true));
|
||||
assert!(!s.doc().unwrap().doc.images[&im.key].is_proxy(), "the file's pixels are in the document");
|
||||
assert!(near(centre_colour(&s.doc().unwrap().doc), BLUE));
|
||||
}
|
||||
|
||||
/// Update Links reads a changed file again for the images inside symbols, patterns and opacity
|
||||
/// masks too: those showing the same content as an image in the layers, and those no object in the
|
||||
/// layers shows. Each takes the file's place as its own Placement Options say, in one undo step,
|
||||
|
||||
@@ -879,13 +879,6 @@ fn distort_refuses_a_folded_image_and_crop_and_trace_refuse_a_distorted_one() {
|
||||
for (cmd, params) in [
|
||||
("object.cropImage", json!({})),
|
||||
("imageTrace.make", json!({})),
|
||||
("links.relink", json!({"path": "/nowhere/pic.png"})),
|
||||
// Refused before the folder is searched, so a file missing there does not hide it.
|
||||
("links.relink", json!({"folder": "/nowhere"})),
|
||||
("links.embed", json!({"ids": [img.0]})),
|
||||
("links.unembed", json!({})),
|
||||
// Refused before any file is written.
|
||||
("links.unembed", json!({"folder": "/nowhere"})),
|
||||
("object.createObjectMosaic", json!({})),
|
||||
("object.mesh.create", json!({})),
|
||||
(
|
||||
|
||||
@@ -112,6 +112,26 @@ fn preflight_resolution_follows_placed_size_and_both_axes() {
|
||||
assert!(codes(&screen).is_empty(), "{screen}");
|
||||
}
|
||||
|
||||
/// A distorted image's resolution is measured at its middle, as Image Info measures it.
|
||||
#[test]
|
||||
fn preflight_resolution_of_a_distorted_image_is_image_infos() {
|
||||
let dir = Folder::new("preflight-resolution-distorted");
|
||||
let path = dir.file("picture.png");
|
||||
std::fs::write(&path, png(100, 100, [200, 50, 10])).unwrap();
|
||||
let mut s = new();
|
||||
let id = s.execute("file.place", &json!({ "path": path, "link": false, "at": [200, 200] })).unwrap()["ids"][0].clone();
|
||||
s.execute("select.set", &json!({ "ids": [id] })).unwrap();
|
||||
s.execute("object.setBounds", &json!({ "width": 24, "height": 24 })).unwrap();
|
||||
assert!(codes(&s.execute("document.preflight", &json!({ "minPpi": 200 })).unwrap()).is_empty());
|
||||
// The top stays 24 pt wide; the bottom is 120 pt wide.
|
||||
s.execute("object.distort", &json!({ "corners": [[188, 188], [212, 188], [260, 212], [140, 212]] })).unwrap();
|
||||
assert!(s.doc().unwrap().doc.node(NodeId(id.as_u64().unwrap())).unwrap().is_distorted_image());
|
||||
let info = s.execute("image.info", &json!({ "id": id })).unwrap();
|
||||
let r = s.execute("document.preflight", &json!({ "minPpi": 200 })).unwrap();
|
||||
let f = r["findings"].as_array().unwrap().iter().find(|f| f["code"] == "lowResolution").expect("a low resolution finding");
|
||||
assert_eq!(f["effectivePpi"], info["ppi"], "{info}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preflight_resolution_accepts_the_exact_threshold_but_rejects_a_real_shortfall() {
|
||||
let dir = Folder::new("preflight-resolution-boundary");
|
||||
|
||||
@@ -9309,6 +9309,57 @@ fn a_masked_copy_nested_too_deep_for_its_mask_keeps_all_of_its_pixels() {
|
||||
assert!(whole >= 2, "the first copy and a copy whose mask is left out: {sizes:?}");
|
||||
}
|
||||
|
||||
/// A distorted image in the art of an opacity mask written at the deepest level a mask takes is
|
||||
/// written as its pieces, as an undistorted image there is written whole: the mask keeps its art.
|
||||
#[test]
|
||||
fn a_distorted_image_in_a_mask_at_the_nesting_limit_keeps_its_pixels() {
|
||||
// GUARDS: the distorted image was written there as an empty group, so the mask hid the object.
|
||||
let masks = |distorted: bool| {
|
||||
let mut doc = Document::new(200.0, 100.0);
|
||||
let layer = doc.layers[0].id;
|
||||
let mut masked = speckled_photo(&mut doc);
|
||||
let mut art = speckled_photo(&mut doc);
|
||||
if distorted {
|
||||
let q = [(40.0, 10.0), (100.0, 10.0), (148.0, 138.0), (20.0, 138.0)].map(|(x, y)| vectorcraft_geom::Point::new(x, y));
|
||||
art.set_image_corners(q).unwrap();
|
||||
}
|
||||
masked.extras_mut().mask = Some(Box::new(OpacityMask { art: Arc::new(art), clip: false, invert: false, disabled: false, linked: true }));
|
||||
doc.symbols.push(Symbol { dynamic: false, name: "S0".into(), art: Arc::new(masked) });
|
||||
// Each isolated instance is written as its art, a level deeper: the masked object's mask
|
||||
// art is at the limit.
|
||||
for i in 1..writer::MAX_NEST - 1 {
|
||||
let mut inner = instance(&mut doc, &format!("S{}", i - 1), Affine::IDENTITY);
|
||||
inner.isolate = true;
|
||||
doc.symbols.push(Symbol { dynamic: false, name: format!("S{i}"), art: Arc::new(inner) });
|
||||
}
|
||||
let mut outer = instance(&mut doc, &format!("S{}", writer::MAX_NEST - 2), Affine::IDENTITY);
|
||||
outer.isolate = true;
|
||||
doc.insert(Some(layer), usize::MAX, outer).unwrap();
|
||||
let out = export_ai_editing(&doc, &opts()).unwrap();
|
||||
assert!(!out.warnings.iter().any(|w| w == writer::DEEP_MASKS), "{:?}", out.warnings);
|
||||
// Each mask read back, by whether its art holds an image.
|
||||
let back = read_back(&doc);
|
||||
let mut found = vec![];
|
||||
let mut look = |n: &Node| {
|
||||
if let Some(m) = n.extras().mask.as_ref() {
|
||||
let mut image = false;
|
||||
m.art.walk(&mut |c| image |= matches!(c.kind, NodeKind::Image(_)));
|
||||
found.push(image);
|
||||
}
|
||||
};
|
||||
for l in &back.layers {
|
||||
l.walk(&mut look);
|
||||
}
|
||||
for s in &back.symbols {
|
||||
s.art.walk(&mut look);
|
||||
}
|
||||
found
|
||||
};
|
||||
let (plain, distorted) = (masks(false), masks(true));
|
||||
assert!(!plain.is_empty() && plain.iter().all(|i| *i), "{plain:?}");
|
||||
assert_eq!(distorted, plain);
|
||||
}
|
||||
|
||||
/// [`warped_photo`] linked to `/Users/someone/Job/art/photo.png`, in folder `art` next to the
|
||||
/// document's.
|
||||
fn linked_warped_photo(doc: &mut Document, effects: Vec<vectorcraft_doc::Effect>) -> Node {
|
||||
|
||||
@@ -974,8 +974,9 @@ impl<'a> Writer<'a> {
|
||||
self.warn(w);
|
||||
}
|
||||
let moved = bounds && self.wrap_on_bounds(n, state);
|
||||
// A gradient mesh's drawn look is paths, which hold nothing: it is written at any depth.
|
||||
if self.nest < MAX_NEST || matches!(n.kind, NodeKind::Mesh(_)) {
|
||||
// A gradient mesh's drawn look is paths, and a distorted image's is clipped copies of its
|
||||
// image, which hold nothing: they are written at any depth.
|
||||
if self.nest < MAX_NEST || matches!(n.kind, NodeKind::Mesh(_)) || n.is_distorted_image() {
|
||||
let g = vectorcraft_effects::expand_live_deep(Some(self.doc), n);
|
||||
self.nest += 1;
|
||||
self.drawn += 1;
|
||||
|
||||
@@ -196,6 +196,32 @@ fn a_distorted_image_is_written_with_its_corners_on_its_quad() {
|
||||
assert!(quad_clips >= 1, "no clipping path on the quad");
|
||||
}
|
||||
|
||||
/// A distorted image's own fill that Convert to Shape gives a shape is written with it.
|
||||
#[test]
|
||||
fn a_distorted_image_keeps_its_own_shaped_fill() {
|
||||
use vectorcraft_doc::{AppearanceItem, Effect, FillLayer, color::Color, color::Paint};
|
||||
let mut d = doc(encoded(colour(), ImageFormat::Png), "image/png");
|
||||
let id = d.layers[0].children().unwrap()[0].id;
|
||||
let q = [(40.0, 10.0), (60.0, 10.0), (90.0, 90.0), (10.0, 90.0)].map(|(x, y)| Point::new(x, y));
|
||||
let n = d.node_mut(id).unwrap();
|
||||
n.set_image_corners(q).unwrap();
|
||||
let mut fill = FillLayer::new(Paint::solid(Color::rgb(0.0, 1.0, 0.0)));
|
||||
fill.effects = vec![Effect { id: "convertToShape.rectangle".into(), params: json!({"relative": true, "extraW": 0, "extraH": 0}), visible: true }];
|
||||
n.appearance.items.push(AppearanceItem::Fill(fill));
|
||||
let bytes = export_with_report(&d, &PdfOptions::default()).unwrap().bytes;
|
||||
let back = crate::import(&bytes).unwrap();
|
||||
let (mut green, mut pieces) = (false, 0);
|
||||
back.walk(|n| match &n.kind {
|
||||
NodeKind::Image(_) => pieces += 1,
|
||||
NodeKind::Path { .. } => {
|
||||
green |= n.appearance.fill().and_then(|f| f.paint.color()).is_some_and(|c| c.to_rgb()[1] > 0.9 && c.to_rgb()[0] < 0.1)
|
||||
}
|
||||
_ => {}
|
||||
});
|
||||
assert!(pieces > 2, "{pieces}");
|
||||
assert!(green, "the fill is written");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn jpeg_zip_and_automatic_compression() {
|
||||
let png = doc(encoded(colour(), ImageFormat::Png), "image/png");
|
||||
|
||||
+16
-10
@@ -7583,16 +7583,22 @@ or breaks these rules, opens with the image placed by its transform. A drag is o
|
||||
the corners where they are records none. Image info (`image.info`) gives a distorted image's resolution at its middle, and Link
|
||||
Info (`links.info`) gives its scale and rotation there.
|
||||
|
||||
Crop Image (`object.cropImage`), Image Trace (`imageTrace.make`, `imageTrace.makeAndExpand`), Relink (`links.relink`),
|
||||
Embed (`links.embed`), Unembed (`links.unembed`), Create Object Mosaic (`object.createObjectMosaic`) and Place with
|
||||
Replace (`file.place` with `replace`) of anything but a text file refuse a distorted image with an error that names the
|
||||
distortion; Place with Replace does not refuse a clipping group that holds a distorted image of a DCS file's plates. Relink and Unembed refuse a named or selected distorted image before they search a folder or write a file.
|
||||
Create Gradient Mesh (`object.mesh.create`) converts the other objects it is given and lists each distorted image it
|
||||
leaves as it is in `skipped`, with its `id` and the error as `reason`; with nothing else to convert, it returns that
|
||||
error. Update Links (`links.update`) puts a changed file's pixels between a distorted
|
||||
image's corners, without applying its Placement Options. 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.
|
||||
Crop Image (`object.cropImage`), Image Trace (`imageTrace.make`, `imageTrace.makeAndExpand`), Create Object Mosaic
|
||||
(`object.createObjectMosaic`) and Place with Replace (`file.place` with `replace`) of anything but a text file refuse a
|
||||
distorted image with an error that names the distortion; Place with Replace does not refuse a clipping group that holds
|
||||
a distorted image of a DCS file's plates. Create Gradient Mesh (`object.mesh.create`) converts the other objects it is
|
||||
given and lists each distorted image it leaves as it is in `skipped`, with its `id` and the error as `reason`; with
|
||||
nothing else to convert, it returns that error. Update Links (`links.update`) and Relink
|
||||
(`links.relink`) put the file's pixels between a distorted image's corners, without applying its Placement Options or
|
||||
Relink's `preserve`. When `preserve` is given, Relink adds a `warnings` entry naming those images; without it, Relink
|
||||
adds none for them. 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, 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]]}}}
|
||||
|
||||
+2
-1
@@ -684,7 +684,8 @@ every attribute:
|
||||
`"unknown"`, read from the image itself. An image whose corners Perspective Distort or Free Distort moved to a shape
|
||||
that is not a parallelogram also has `corners`, its pixel rectangle's corners on the page (top left, top right,
|
||||
bottom right, bottom left), and its `transform` is then the affine placement nearest them, the one that matches the
|
||||
perspective at the middle of its pixels. An embedded image whose pixels take at most 1 MiB in base64 (443 × 443
|
||||
perspective at the middle of its pixels. Corners that make a parallelogram are described by `transform` alone. An
|
||||
embedded image whose pixels take at most 1 MiB in base64 (443 × 443
|
||||
pixels fit) has them in `pixelsBase64`: straight RGBA, 8 bits a channel, row by row from the top, and
|
||||
`pixelsOmitted: false`. A CMYK image's pixels are its inks through the working CMYK profile, as sRGB. The pixels of
|
||||
all the images in one input take at most 16 MiB in base64, and an image the host starts to decode takes its size
|
||||
|
||||
@@ -1195,7 +1195,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- After a rotation the Scale and Reflect tools, the Scale and Reflect dialogs, `object.scale`, `object.reflect` with a named axis and the Transform and Properties panels' flips act along the selection's turned bounding box until Reset Bounding Box: the horizontal and vertical scale stretch along its own width and height, and the vertical and horizontal reflection axes are its own. The Reflect tool's default axis and its Shift steps start from the box's axes, and an axis drawn with the tool is the line drawn on the page. `basis: "page"` keeps the page's axes (VectorCraft's own rules; `bboxrotate::scale_and_reflect_follow_the_turned_box`, tools `xform::transform::tests::scale_and_reflect_drags_follow_a_turned_bounding_box`).
|
||||
- The Reflect tool sets an axis with two clicks: a click sets the first point (and the reference point), and a second click reflects the selection across the line through both points as one undo step; Alt/Option on the second click reflects a copy, and a drag after the first click draws the axis from it ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-objects/arrange-objects/reflect-or-flip-objects.html)). A dashed line runs from the first point to the pointer until the second click. VectorCraft's own rules: an Alt-click opens the dialog and sets no axis; a second click whose snapped point is within 3 screen pixels of the first point's snapped point does nothing and the axis keeps waiting; Shift does not constrain a plain second click; Escape, Enter, a changed selection, an edit made outside the tool or another tool drops the waiting axis. A double-click arrives as two clicks: its first click is the second point, so a double-click away from the first point reflects the selection, and the double-click then opens the dialog with no axis waiting (tools `xform::transform::tests::a_second_reflect_click_reflects_across_the_line_through_both_points` and the four tests after it; engine `xform::two_reflect_clicks_reflect_across_their_line_as_one_undo_step`).
|
||||
- Perspective Distort and Free Distort (`object.distort`) turn each warped object's bounding box as the warp turns the object at its own center, the objects inside groups, compound paths and clip groups and the art of linked opacity masks included, so the next Selection or Free Transform drag uses the tilted box; Object › Transform › Reset Bounding Box squares it again, and corners left where they are add no undo step (VectorCraft's own rule; `bboxrotate::distort_turns_an_upright_box_with_the_warp_at_its_center`, `distort_turns_each_member_and_linked_mask_by_its_own_warp`, `mirrored_and_collapsing_distorts_keep_valid_angles`, `distort_angles_undo_redo_and_reopen_together`, `xform::unchanged_distort_records_no_history`).
|
||||
- Perspective Distort and Free Distort (`object.distort`) move an image's four corners exactly onto the handles when the image is distorted alone; with other objects the handles stand for the whole selection, and the image's corners follow the same warp without necessarily landing on them. The image's pixels are drawn in perspective between its corners on the canvas, in print and in every export that holds images, as a mesh of affine image pieces (DXF and WMF write the nearest parallelogram and warn, as the `.ai` writers do for an image nested 8 deep in opacity masks, symbols, live objects and pattern tiles, or in a legacy `.ai` in symbols and live objects, not counting ordinary groups and layers, and leave out an image nested deeper; HP-GL plots leave images out); the native file saves the corners; bounds, clicks, blends, the Eyedropper, Outline view, the Color Theme Picker and Weed Box and Lines follow them; Image info and Link Info measure the image at its middle; and corners that would fold the image over, fall on one line, cross the warp's horizon or lie too close together for a perspective map are refused. Crop Image, Image Trace, Relink, Embed, Unembed, Create Object Mosaic, Create Gradient Mesh and Place with Replace refuse a distorted image (Place with Replace refuses only when the object it measures is the distorted image, so it does not refuse when the placed file is text or the replaced object is a DCS file's plates); Update Links puts a changed file's pixels between its corners; Rasterize makes a plain image of it. All of this is VectorCraft's own rule (doc `image_quad::tests`, `blend::tests::steps_between_distorted_images_have_corners_between_theirs`; engine `xform::distort_puts_an_images_corners_on_the_handles`, `distort_moves_an_image_and_a_path_as_one`, `distort_refuses_a_folded_image_and_crop_and_trace_refuse_a_distorted_one`, `distort_names_the_horizon_and_an_unchanged_distort_of_a_distorted_image_records_nothing`, `distort_of_a_blend_holding_an_image_is_not_refused`, `free_transform_distort_drag_on_an_image_is_one_undo_step`, `mask_on_a_distorted_image_follows_its_corners`, `a_transform_effect_moves_a_distorted_images_corners`, `a_transform_after_a_warp_moves_a_distorted_image_once`, `baked_raster_effect_pixels_replace_a_distortion`, `rasterize_draws_a_distorted_image_between_its_corners`, `image_info_measures_a_distorted_image_at_its_middle`, `a_distorted_image_saves_and_reads_back`, `links::update_links_keeps_a_distorted_images_corners`, `recolor::theme_picker_reads_a_distorted_image_where_it_is_drawn`, `addons::cutting::weed::tests::a_distorted_image_is_measured_by_the_frame_through_its_corners`; render `outline_mode_draws_a_distorted_images_frame_through_its_corners`, `meshwarp::outline_mode_paints_a_distorted_images_pixels_once_where_its_pieces_overlap`, `meshwarp::the_canvas_cuts_a_distorted_images_mesh_for_the_zoom`, `objectfx::a_distorted_image_is_opaque_between_its_corners_and_its_shadow_follows_them`, `objectfx::a_distorted_image_is_opaque_inside_its_corners_at_every_zoom`; svg `warp_pieces::a_distorted_image_is_written_between_its_corners`; pdf `compression::a_distorted_image_is_written_with_its_corners_on_its_quad`; eps `a_distorted_image_is_written_with_its_corners_on_its_quad`, `ai_editing::tests::a_distorted_image_nested_as_deep_as_the_limit_is_written_as_its_nearest_placement`, `legacy_ai::tests::a_distorted_image_nested_as_deep_as_the_limit_is_written_as_its_nearest_placement`; cad `a_distorted_image_is_written_as_its_nearest_parallelogram_with_a_warning`; metafile `a_distorted_image_is_its_mesh_with_clips_and_its_nearest_parallelogram_without`; tools `xform::eyedropper::tests::clicking_an_image_samples_its_pixels`; plugins `objects::tests::a_distorted_image_comes_with_its_corners`; ui-egui `i18n::tests::distorted_image_messages_are_in_complete_catalogs`).
|
||||
- Perspective Distort and Free Distort (`object.distort`) move an image's four corners exactly onto the handles when the image is distorted alone; with other objects the handles stand for the whole selection, and the image's corners follow the same warp without necessarily landing on them. The image's pixels are drawn in perspective between its corners on the canvas, in print and in every export that holds images, as a mesh of affine image pieces (DXF and WMF write the nearest parallelogram and warn, as the `.ai` writers do for an image nested 8 deep in opacity masks, symbols, live objects and pattern tiles, or in a legacy `.ai` in symbols and live objects, not counting ordinary groups and layers, and leave out an image nested deeper; HP-GL plots leave images out); the native file saves the corners; bounds, clicks, blends, the Eyedropper, Outline view, the Color Theme Picker and Weed Box and Lines follow them; Image info and Link Info measure the image at its middle; and corners that would fold the image over, fall on one line, cross the warp's horizon or lie too close together for a perspective map are refused. Crop Image, Image Trace, Create Object Mosaic, Create Gradient Mesh and Place with Replace refuse a distorted image (Place with Replace refuses only when the object it measures is the distorted image, so it does not refuse when the placed file is text or the replaced object is a DCS file's plates); Update Links and Relink put the file's pixels between its corners, with the file's clipping path drawn through them, and Embed and Unembed keep them; Rasterize makes a plain image of it. All of this is VectorCraft's own rule (doc `image_quad::tests`, `blend::tests::steps_between_distorted_images_have_corners_between_theirs`; engine `xform::distort_puts_an_images_corners_on_the_handles`, `distort_moves_an_image_and_a_path_as_one`, `distort_refuses_a_folded_image_and_crop_and_trace_refuse_a_distorted_one`, `distort_names_the_horizon_and_an_unchanged_distort_of_a_distorted_image_records_nothing`, `distort_of_a_blend_holding_an_image_is_not_refused`, `free_transform_distort_drag_on_an_image_is_one_undo_step`, `mask_on_a_distorted_image_follows_its_corners`, `a_transform_effect_moves_a_distorted_images_corners`, `a_transform_after_a_warp_moves_a_distorted_image_once`, `baked_raster_effect_pixels_replace_a_distortion`, `rasterize_draws_a_distorted_image_between_its_corners`, `image_info_measures_a_distorted_image_at_its_middle`, `a_distorted_image_saves_and_reads_back`, `links::update_links_keeps_a_distorted_images_corners`, `links::relink_embed_and_unembed_keep_a_distorted_images_corners`, `links::unembed_to_a_folder_keeps_a_distorted_images_corners`, `links::embed_reads_a_distorted_images_file_between_its_corners`, `links::relink_of_all_instances_keeps_the_corners_of_distorted_images_in_symbols`, `cmd::fileio::tests_psdread::relink_follows_the_clipping_path_of_a_distorted_psd`, `cmd::fileio::tests_psdread::unembed_keeps_the_clipping_path_of_a_distorted_psd`, `cmd::links::tests::points_past_the_horizon_are_mapped_as_a_distort_maps_them`, `recolor::theme_picker_reads_a_distorted_image_where_it_is_drawn`, `addons::cutting::weed::tests::a_distorted_image_is_measured_by_the_frame_through_its_corners`; render `outline_mode_draws_a_distorted_images_frame_through_its_corners`, `meshwarp::outline_mode_paints_a_distorted_images_pixels_once_where_its_pieces_overlap`, `meshwarp::the_canvas_cuts_a_distorted_images_mesh_for_the_zoom`, `objectfx::a_distorted_image_is_opaque_between_its_corners_and_its_shadow_follows_them`, `objectfx::a_distorted_image_is_opaque_inside_its_corners_at_every_zoom`; svg `warp_pieces::a_distorted_image_is_written_between_its_corners`; pdf `compression::a_distorted_image_is_written_with_its_corners_on_its_quad`; eps `a_distorted_image_is_written_with_its_corners_on_its_quad`, `ai_editing::tests::a_distorted_image_nested_as_deep_as_the_limit_is_written_as_its_nearest_placement`, `legacy_ai::tests::a_distorted_image_nested_as_deep_as_the_limit_is_written_as_its_nearest_placement`; cad `a_distorted_image_is_written_as_its_nearest_parallelogram_with_a_warning`; metafile `a_distorted_image_is_its_mesh_with_clips_and_its_nearest_parallelogram_without`; tools `xform::eyedropper::tests::clicking_an_image_samples_its_pixels`; plugins `objects::tests::a_distorted_image_comes_with_its_corners`; ui-egui `i18n::tests::distorted_image_messages_are_in_complete_catalogs`).
|
||||
- The Free Transform widget's Constrain works in Free Distort as well as in Free Transform ([the help page](https://helpx.adobe.com/illustrator/using/tool-techniques/free-transform-tool.html)). With Constrain on, or Shift held, a corner dragged in Free Distort moves only along the line through the opposite corner, in the box's own proportions, and the other three corners stay in place; on a turned box the line runs through the box's own corners. The line is VectorCraft's own rule. Cmd/Ctrl+Alt+Shift on a corner still drags in Perspective Distort, where Constrain stays unavailable (tools `xform::free::tests::free_distort_corner_keeps_to_its_diagonal_with_shift_or_constrain`, `shift_pressed_during_a_free_distort_drag_constrains_it`, `a_turned_box_is_constrained_along_its_own_diagonal`, `along_diagonal_of_a_degenerate_box`; engine `xform::free_transform_constrained_distort_keeps_the_corner_on_its_diagonal`; ui-egui `free_transform::tests::the_widget_sets_the_mode_and_a_corner_drag_then_distorts`).
|
||||
- With Smart Guides › Transform Tools on, a Free Transform shear (Cmd/Ctrl on a side handle) shows its angle next to the pointer, as the Shear tool does, and a handle drag that turns from a scale into a shear and back shows only the current operation's value ([the help page](https://helpx.adobe.com/illustrator/desktop/measure-and-align/grids-and-guides/smart-guides-options.html)). The angle's sign and its one decimal place are VectorCraft's own rule, the same as the Shear tool's label (tools `xform::free::tests::shear_drag_shows_its_angle_with_transform_tools_guides`, `a_handle_drag_that_changes_operation_relabels_it`).
|
||||
- Native macOS menu bar, vector tool cursors, a command palette (Help › Search Commands…), middle-button panning with any tool. Native menus explicitly end tracking on command selection, outside window presses and Escape; menu updates wait until tracking ends, and a dismissing press never starts a canvas gesture (M14.8).
|
||||
|
||||
Reference in New Issue
Block a user