mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 12:03:31 +00:00
Crop Image: Apply leaves out a linked image's own resolution above 300 ppi
A turned linked image whose own resolution is above the 300 ppi it can be cropped to is cropped as before, without ppi, instead of at 300 ppi.
This commit is contained in:
@@ -848,7 +848,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.cropImage",
|
||||
"Crop Image",
|
||||
"",
|
||||
"{} show a crop box on the selected image (tool `cropImage`): it starts on the part over the image's artboard; drag its handles or inside it, then Enter or the Control bar's Apply crops the image to it (object.cropImage {rect, ppi?}: ppi when a resolution that changes the image's pixels is set, and for a turned or skewed image its own when none is), Escape or Cancel leaves it as it is, both back to the Selection tool. tool.setOption {key: \"rect\", value: [x, y, width, height]} sets the box; {key: \"ppi\", value: 1 to 2400 and at most the selected image's own resolution (300 for a linked image), or null for the image's own} the cropped image's resolution; {key: \"reference\", value: 0 to 8, left to right and top to bottom; 4, the center, by default} the point the Control bar's X and Y name and its W and H resize about; {key: \"linked\", value: true or false (default false)} whether W and H keep the box's proportions. → {tool}; a tool that cannot be chosen returns the error",
|
||||
"{} show a crop box on the selected image (tool `cropImage`): it starts on the part over the image's artboard; drag its handles or inside it, then Enter or the Control bar's Apply crops the image to it (object.cropImage {rect, ppi?}: ppi when a resolution that changes the image's pixels is set, and for a turned or skewed image its own when none is and it can be cropped to it), Escape or Cancel leaves it as it is, both back to the Selection tool. tool.setOption {key: \"rect\", value: [x, y, width, height]} sets the box; {key: \"ppi\", value: 1 to 2400 and at most the selected image's own resolution (300 for a linked image), or null for the image's own} the cropped image's resolution; {key: \"reference\", value: 0 to 8, left to right and top to bottom; 4, the center, by default} the point the Control bar's X and Y name and its W and H resize about; {key: \"linked\", value: true or false (default false)} whether W and H keep the box's proportions. → {tool}; a tool that cannot be chosen returns the error",
|
||||
),
|
||||
("effect.applyLast", "Apply Last Effect", "Cmd+Shift+E", "{}"),
|
||||
(
|
||||
|
||||
@@ -220,8 +220,8 @@ impl CropImageTool {
|
||||
let [_, b, c, _, _, _] = im.xf.as_coeffs();
|
||||
b.abs() > 1e-9 || c.abs() > 1e-9
|
||||
});
|
||||
let own = |im: &ImageObject| Some(image_ppi(im).0).filter(|v| (1.0..=2400.0).contains(v));
|
||||
let send = resample.or_else(|| drawn.and_then(|im| ppi.or_else(|| own(im))).map(|v| v.min(max)));
|
||||
let own = |im: &ImageObject| Some(image_ppi(im).0).filter(|v| (1.0..=2400.0).contains(v) && *v <= max + 1e-6);
|
||||
let send = resample.or_else(|| drawn.and_then(|im| ppi.map(|v| v.min(max)).or_else(|| own(im))));
|
||||
if !same(r, image) || resample.is_some() || (drawn.is_some() && ppi.is_some()) {
|
||||
let mut p = json!({ "rect": [r.x0, r.y0, r.width(), r.height()] });
|
||||
if let Some(v) = send {
|
||||
@@ -716,6 +716,17 @@ mod tests {
|
||||
t.set_option("ppi", &json!(36));
|
||||
assert!(ppi(&enter(&mut t, &cx)).is_some_and(|v| (v - 36.0).abs() < 1e-9));
|
||||
assert!(!enter(&mut t, &cx).iter().any(|a| matches!(a, Action::Exec(..))));
|
||||
// A linked image's own resolution above what it can be cropped to is not sent in its place.
|
||||
let Some(NodeKind::Image(im)) = d.node(id).map(|n| n.kind.clone()) else { panic!("an image") };
|
||||
let mut linked = d.clone();
|
||||
if let Some(NodeKind::Image(l)) = linked.node_mut(id).map(|n| &mut n.kind) {
|
||||
l.link = Some("photo.png".into());
|
||||
l.xf = im.xf * Affine::scale(0.1);
|
||||
}
|
||||
// 0.2 pt a pixel: 360 ppi, above the 300 a linked image is cropped to.
|
||||
let cx = crate::testutil::cx(&linked, &s, &p);
|
||||
t.set_option("rect", &json!([105, 128, 4, 4]));
|
||||
assert_eq!(ppi(&enter(&mut t, &cx)), None);
|
||||
}
|
||||
|
||||
/// A crop that fails leaves the tool chosen (the switch to the Selection tool is not made), so
|
||||
|
||||
@@ -849,7 +849,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.cropImage",
|
||||
"Crop Image",
|
||||
"",
|
||||
"{} show a crop box on the selected image (tool `cropImage`): it starts on the part over the image's artboard; drag its handles or inside it, then Enter or the Control bar's Apply crops the image to it (object.cropImage {rect, ppi?}: ppi when a resolution that changes the image's pixels is set, and for a turned or skewed image its own when none is), Escape or Cancel leaves it as it is, both back to the Selection tool. tool.setOption {key: \"rect\", value: [x, y, width, height]} sets the box; {key: \"ppi\", value: 1 to 2400 and at most the selected image's own resolution (300 for a linked image), or null for the image's own} the cropped image's resolution; {key: \"reference\", value: 0 to 8, left to right and top to bottom; 4, the center, by default} the point the Control bar's X and Y name and its W and H resize about; {key: \"linked\", value: true or false (default false)} whether W and H keep the box's proportions. → {tool}; a tool that cannot be chosen returns the error",
|
||||
"{} show a crop box on the selected image (tool `cropImage`): it starts on the part over the image's artboard; drag its handles or inside it, then Enter or the Control bar's Apply crops the image to it (object.cropImage {rect, ppi?}: ppi when a resolution that changes the image's pixels is set, and for a turned or skewed image its own when none is and it can be cropped to it), Escape or Cancel leaves it as it is, both back to the Selection tool. tool.setOption {key: \"rect\", value: [x, y, width, height]} sets the box; {key: \"ppi\", value: 1 to 2400 and at most the selected image's own resolution (300 for a linked image), or null for the image's own} the cropped image's resolution; {key: \"reference\", value: 0 to 8, left to right and top to bottom; 4, the center, by default} the point the Control bar's X and Y name and its W and H resize about; {key: \"linked\", value: true or false (default false)} whether W and H keep the box's proportions. → {tool}; a tool that cannot be chosen returns the error",
|
||||
),
|
||||
("effect.applyLast", "Apply Last Effect", "Cmd+Shift+E", "{}"),
|
||||
(
|
||||
|
||||
+1
-1
@@ -1924,7 +1924,7 @@ and the image keeps the size of the crop box. A `rect` over the whole image with
|
||||
An image scaled differently across and down is resampled on both sides, so its pixels come out square at `ppi`.
|
||||
A turned or skewed image is drawn at the `ppi` given, even its own, and over the whole box around it as well; without
|
||||
`ppi` it is drawn at the density of that box. The Crop Image tool's Apply sends such an image's own resolution when
|
||||
no other is set, and crops it over the whole box only when a resolution is chosen.
|
||||
no other is set and the image can be cropped to it, and crops it over the whole box only when a resolution is chosen.
|
||||
The most it takes is the image's own resolution (along the denser side of its pixel grid, however it is turned), or
|
||||
300 ppi for a linked image; above that it is refused with `ppi can't be more than {max} for this image`. A value
|
||||
outside 1 to 2400 is refused with `ppi must be between 1 and 2400`, and a value that is not a positive number with
|
||||
|
||||
Reference in New Issue
Block a user