mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 21:27:00 +00:00
Merge main into fix/erase-region-params-refused
This commit is contained in:
@@ -89,6 +89,45 @@ fn export_3d_object_refuses_objects_without_a_3d_effect_and_bad_formats() {
|
||||
assert_eq!(r["added"], 1);
|
||||
}
|
||||
|
||||
/// Without `ids`, the selected objects without a 3D effect, a group whose 3D effect is on its fill
|
||||
/// (it draws nothing to export) and a 3D object inside another selected one are left out; a
|
||||
/// selection with none left is refused.
|
||||
#[test]
|
||||
fn export_3d_object_leaves_flat_objects_in_the_selection_out() {
|
||||
let mut s = session();
|
||||
let plain = run(&mut s, "shape.rectangle", json!({"x": 10.0, "y": 100.0, "width": 40.0, "height": 30.0}))["id"].as_u64().unwrap();
|
||||
let filled = run(&mut s, "shape.rectangle", json!({"x": 10.0, "y": 200.0, "width": 40.0, "height": 30.0}))["id"].as_u64().unwrap();
|
||||
run(&mut s, "select.set", json!({"ids": [filled]}));
|
||||
let group = run(&mut s, "object.group", json!({}))["id"].as_u64().unwrap();
|
||||
run(&mut s, "select.set", json!({"ids": [group]}));
|
||||
run(&mut s, "appearance.addFill", json!({}));
|
||||
run(&mut s, "effect.apply", json!({"effect": "threeD.extrude"}));
|
||||
// `effect.apply` puts a group's 3D effect on the group itself; a file can hold one on its fill.
|
||||
s.edit("fill", |d, _| {
|
||||
let n = d.node_mut(vectorcraft_doc::NodeId(group)).unwrap();
|
||||
let fx = n.appearance.effects.remove(0);
|
||||
n.appearance.items[0].effects_mut().push(fx);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
run(&mut s, "select.set", json!({"ids": [plain, group]}));
|
||||
let before = undo_len(&s);
|
||||
assert!(s.execute("assets.add3D", &json!({})).is_err(), "no object with a 3D effect to export");
|
||||
assert_eq!(undo_len(&s), before);
|
||||
let inner = extruded(&mut s, 100.0, "Inner");
|
||||
let other = run(&mut s, "shape.rectangle", json!({"x": 200.0, "y": 10.0, "width": 40.0, "height": 30.0}))["id"].as_u64().unwrap();
|
||||
run(&mut s, "select.set", json!({"ids": [inner, other]}));
|
||||
let outer = run(&mut s, "object.group", json!({}))["id"].as_u64().unwrap();
|
||||
run(&mut s, "select.set", json!({"ids": [outer]}));
|
||||
run(&mut s, "effect.apply", json!({"effect": "threeD.extrude"}));
|
||||
run(&mut s, "select.set", json!({"ids": [plain, group, inner, outer]}));
|
||||
let r = run(&mut s, "assets.add3D", json!({}));
|
||||
assert_eq!(r["added"], 1, "{r}");
|
||||
let nodes: Vec<Value> = run(&mut s, "assets.list", json!({}))["assets"].as_array().unwrap().iter().map(|a| a["nodes"].clone()).collect();
|
||||
assert_eq!(nodes, [json!([outer])]);
|
||||
assert!(s.execute("assets.add3D", &json!({"ids": [plain, outer]})).is_err(), "ids are still refused");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_format_is_set_per_asset_and_only_a_change_is_an_undo_step() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -5847,9 +5847,10 @@ fn add_image(s: &mut Session, r: &vectorcraft_trace::Raster, xf: Affine) -> Node
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// The traced paths of an Image Trace object: its children but the image and the seam fills.
|
||||
/// The traced paths of an Image Trace object: its children but the image and the seam fills'
|
||||
/// clip group (a trace makes no other clip group).
|
||||
fn traced_paths(n: &Node) -> Vec<Arc<Node>> {
|
||||
n.children().unwrap().iter().filter(|c| !matches!(c.kind, NodeKind::Image(_)) && c.name.as_deref() != Some("Seam Fills")).cloned().collect()
|
||||
n.children().unwrap().iter().filter(|c| !matches!(c.kind, NodeKind::Image(_) | NodeKind::Group { clip: true, .. })).cloned().collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -6550,7 +6551,12 @@ fn image_trace_abutting_seam_fills_sit_under_the_paths() {
|
||||
assert!(matches!(kids[0].kind, NodeKind::Image(_)));
|
||||
let group = seams(&n).unwrap();
|
||||
assert!(Arc::ptr_eq(&group, &kids[1]), "the seam fills come under the paths");
|
||||
let strokes = group.children().unwrap();
|
||||
assert!(matches!(group.kind, NodeKind::Group { clip: true, .. }), "{group:?}");
|
||||
// The two paths cover the image, so the strokes are clipped to its box.
|
||||
let (clip, strokes) = group.children().unwrap().split_first().unwrap();
|
||||
assert!(matches!(clip.kind, NodeKind::Path { clipping: true, .. }), "{clip:?}");
|
||||
let cb = outline(clip).0.bounds().unwrap();
|
||||
assert!([cb.x0, cb.y0, cb.x1 - 80.0, cb.y1 - 40.0].iter().all(|v| v.abs() < 1e-9), "{cb:?}");
|
||||
assert_eq!(strokes.len(), 1);
|
||||
assert_eq!(strokes[0].appearance.fill_paint(), Paint::None);
|
||||
let AppearanceItem::Stroke(layer) = &strokes[0].appearance.items[0] else { panic!("{:?}", strokes[0].appearance) };
|
||||
@@ -6568,6 +6574,14 @@ fn image_trace_abutting_seam_fills_sit_under_the_paths() {
|
||||
assert_eq!(names.len(), 3, "{names:?}");
|
||||
assert_eq!(names[0], "Edges", "{names:?}");
|
||||
assert_eq!(n.children().unwrap()[0].id, group.id);
|
||||
// Above a path, the seam fills' group is refused by name, not as an Auto Grouping group.
|
||||
let (mut s, _, r) = made("abutting", "imageTrace.make", false);
|
||||
let g = NodeId(r["id"].as_u64().unwrap());
|
||||
let kids = node(&s, g).children().unwrap().clone();
|
||||
s.execute("object.arrange.bringToFront", &json!({"ids": [kids[1].id.0]})).unwrap();
|
||||
assert_eq!(node(&s, g).children().unwrap().last().map(|c| c.id), Some(kids[1].id));
|
||||
let e = s.execute("imageTrace.expand", &json!({"id": g.0, "byColor": true})).unwrap_err().to_string();
|
||||
assert!(e.contains("seam fills") && !e.contains("Auto Grouping"), "{e}");
|
||||
let (mut s, img, _) = made("abutting", "imageTrace.make", false);
|
||||
assert_eq!(ids(&s.execute("imageTrace.release", &json!({})).unwrap()), vec![img]);
|
||||
// Make and Expand by color too.
|
||||
@@ -6577,13 +6591,126 @@ fn image_trace_abutting_seam_fills_sit_under_the_paths() {
|
||||
// Overlapping paths are stacked: no seam fills.
|
||||
let (s, _, r) = made("overlapping", "imageTrace.make", false);
|
||||
assert!(seams(&node(&s, NodeId(r["id"].as_u64().unwrap()))).is_none());
|
||||
// An image stretched 3× across and squeezed to half height: 1.5 pixels at the larger scale.
|
||||
}
|
||||
|
||||
/// With white left out, the seam fills are clipped to the image's box within the traced paths'
|
||||
/// box, so the expanded trace measures as its paths do, also on a turned image.
|
||||
#[test]
|
||||
fn image_trace_seam_fills_stay_within_the_traced_paths_box() {
|
||||
let seams = |n: &Node| n.children().unwrap().iter().find(|c| c.name.as_deref() == Some("Seam Fills")).cloned();
|
||||
let band = vectorcraft_trace::Raster::from_fn(24, 16, |x, y| match ((4..12).contains(&y), x < 12) {
|
||||
(false, _) => [255; 4],
|
||||
(true, true) => [200, 30, 30, 255],
|
||||
(true, false) => [30, 30, 200, 255],
|
||||
});
|
||||
for xf in [Affine::IDENTITY, Affine::translate((100.0, 100.0)) * Affine::rotate(0.5)] {
|
||||
let mut s = session();
|
||||
add_image(&mut s, &band, xf);
|
||||
let r = s
|
||||
.execute(
|
||||
"imageTrace.makeAndExpand",
|
||||
&json!({"params": {"mode": "color", "palette": "limited", "colors": 3, "method": "abutting", "ignoreWhite": true}}),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(r["paths"], 2, "{r}");
|
||||
let n = node(&s, NodeId(r["id"].as_u64().unwrap()));
|
||||
let group = seams(&n).unwrap();
|
||||
let clip = &group.children().unwrap()[0];
|
||||
assert!(matches!(clip.kind, NodeKind::Path { clipping: true, .. }), "{clip:?}");
|
||||
let cb = outline(clip).0.bounds().unwrap();
|
||||
let paths = n.children().unwrap()[1..].iter().filter_map(|c| c.geometric_bounds()).reduce(|a, b| a.union(b)).unwrap();
|
||||
assert_eq!(n.geometric_bounds(), Some(paths), "{xf:?}");
|
||||
assert!(cb.x0 >= paths.x0 - 1e-9 && cb.y0 >= paths.y0 - 1e-9 && cb.x1 <= paths.x1 + 1e-9 && cb.y1 <= paths.y1 + 1e-9, "{xf:?}: {cb:?}");
|
||||
if xf == Affine::IDENTITY {
|
||||
assert!([cb.x0, cb.y0 - 4.0, cb.x1 - 24.0, cb.y1 - 12.0].iter().all(|v| v.abs() < 1e-9), "{cb:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// On an image stretched more one way than another, the seam fills are the strokes' outlines in
|
||||
/// image pixels, filled: on an image stretched 20× across, the one along a horizontal edge covers
|
||||
/// 0.75 image pixels on each side of it, as on an image scaled alike both ways, and does not reach
|
||||
/// across the transparent rows above the edge.
|
||||
#[test]
|
||||
fn image_trace_seam_fills_on_a_stretched_image_stay_near_their_edge() {
|
||||
// Red beside blue, the edge between them anti-aliased, on an image stretched 3× across and
|
||||
// squeezed to half height: the outline is 1.5 pixels (4.5 points) across the vertical edge.
|
||||
let art = vectorcraft_trace::Raster::from_fn(40, 20, |x, _| {
|
||||
let share = (16.4 - f64::from(x)).clamp(0.0, 1.0);
|
||||
let mix = |a: f64, b: f64| (a * share + b * (1.0 - share)).round() as u8;
|
||||
[mix(200.0, 30.0), mix(40.0, 90.0), mix(50.0, 200.0), 255]
|
||||
});
|
||||
let mut s = session();
|
||||
add_image(&mut s, &art, Affine::scale_non_uniform(3.0, 0.5));
|
||||
let r = s.execute("imageTrace.make", &json!({"params": {"mode": "color", "palette": "limited", "colors": 2, "method": "abutting"}})).unwrap();
|
||||
let group = seams(&node(&s, NodeId(r["id"].as_u64().unwrap()))).unwrap();
|
||||
let AppearanceItem::Stroke(layer) = &group.children().unwrap()[0].appearance.items[0] else { panic!("{group:?}") };
|
||||
assert!((layer.width - 4.5).abs() < 1e-9, "{}", layer.width);
|
||||
let n = node(&s, NodeId(r["id"].as_u64().unwrap()));
|
||||
let kids = n.children().unwrap();
|
||||
assert_eq!(kids[1].name.as_deref(), Some("Seam Fills"));
|
||||
let fill = &kids[1].children().unwrap()[1];
|
||||
assert_eq!(fill.appearance.stroke_paint(), Paint::None, "{:?}", fill.appearance);
|
||||
assert_eq!(fill.appearance.fill_paint(), kids[2].appearance.fill_paint(), "the lower path's color");
|
||||
let bb = outline(fill).0.bounds().unwrap();
|
||||
assert!((bb.width() - 4.5).abs() < 0.05 && bb.y0.abs() < 1e-6 && (bb.y1 - 10.0).abs() < 1e-6, "{bb:?}");
|
||||
// Rows 0 to 5 transparent, 5 to 10 red, 10 to 20 blue.
|
||||
let art = vectorcraft_trace::Raster::from_fn(40, 20, |_, y| match y {
|
||||
0..5 => [0, 0, 0, 0],
|
||||
5..10 => [200, 30, 30, 255],
|
||||
_ => [30, 30, 200, 255],
|
||||
});
|
||||
let mut s = session();
|
||||
add_image(&mut s, &art, Affine::scale_non_uniform(20.0, 1.0));
|
||||
let r = s.execute("imageTrace.make", &json!({"params": {"mode": "color", "palette": "limited", "colors": 2, "method": "abutting"}})).unwrap();
|
||||
let n = node(&s, NodeId(r["id"].as_u64().unwrap()));
|
||||
let group = n.children().unwrap().iter().find(|c| c.name.as_deref() == Some("Seam Fills")).cloned().unwrap();
|
||||
let (_, members) = group.children().unwrap().split_first().unwrap();
|
||||
assert!(!members.is_empty(), "{group:?}");
|
||||
for m in members {
|
||||
// What the member covers: its outline, grown by half its stroke's width.
|
||||
let half = m.appearance.items.iter().fold(0.0_f64, |w, it| match it {
|
||||
AppearanceItem::Stroke(l) => w.max(l.width / 2.0),
|
||||
_ => w,
|
||||
});
|
||||
let bb = outline(m).0.bounds().unwrap();
|
||||
let (y0, y1) = (bb.y0 - half, bb.y1 + half);
|
||||
assert!(y0 > 9.25 - 1e-6 && y1 < 10.75 + 1e-6, "covers y {y0} to {y1}: {m:?}");
|
||||
}
|
||||
// Renamed, the group of filled outlines is still the seam fills: Expand by color keeps it under
|
||||
// every color's group.
|
||||
s.execute("layer.setProps", &json!({"id": group.id.0, "name": "Edges"})).unwrap();
|
||||
s.execute("imageTrace.expand", &json!({"id": n.id.0, "byColor": true})).unwrap();
|
||||
assert_eq!(node(&s, n.id).children().unwrap()[0].id, group.id);
|
||||
}
|
||||
|
||||
/// A trace made before the seam fills were clipped holds them in a group without a clip: Expand by
|
||||
/// color keeps that group under every color's group too, named or renamed.
|
||||
#[test]
|
||||
fn image_trace_expand_by_color_keeps_unclipped_seam_fills() {
|
||||
let art = vectorcraft_trace::Raster::from_fn(40, 20, |x, _| {
|
||||
let share = (16.4 - f64::from(x)).clamp(0.0, 1.0);
|
||||
let mix = |a: f64, b: f64| (a * share + b * (1.0 - share)).round() as u8;
|
||||
[mix(200.0, 30.0), mix(40.0, 90.0), mix(50.0, 200.0), 255]
|
||||
});
|
||||
for name in [Some("Seam Fills"), None] {
|
||||
let mut s = session();
|
||||
add_image(&mut s, &art, Affine::scale(2.0));
|
||||
let r = s.execute("imageTrace.make", &json!({"params": {"mode": "color", "palette": "limited", "colors": 2, "method": "abutting"}})).unwrap();
|
||||
let g = NodeId(r["id"].as_u64().unwrap());
|
||||
// The seam fills as such a trace holds them: the strokes alone, in a plain group.
|
||||
let seams = node(&s, g).children().unwrap()[1].clone();
|
||||
let NodeKind::Group { clip: true, children } = &seams.kind else { panic!("{seams:?}") };
|
||||
let mut legacy = Node::group(seams.id, children[1..].to_vec());
|
||||
legacy.name = name.map(Into::into);
|
||||
s.edit("legacy", |d, _| {
|
||||
let NodeKind::Group { children, .. } = &mut d.node_mut(g).unwrap().kind else { panic!("trace group") };
|
||||
children[1] = Arc::new(legacy);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
s.execute("imageTrace.expand", &json!({"id": g.0, "byColor": true})).unwrap();
|
||||
let kids = node(&s, g).children().unwrap().clone();
|
||||
assert_eq!(kids.len(), 3, "{name:?}: {kids:?}");
|
||||
assert_eq!(kids[0].id, seams.id, "{name:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Expand by color: each color's paths in a group of their own, named by the color, the groups
|
||||
@@ -7646,6 +7773,51 @@ fn image_trace_views_draw_on_screen_only_and_expand_to_the_result() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Outline views draw the traced paths' outlines and leave out an Abutting trace's seam fills
|
||||
/// (their clipping box and strokes, or on a stretched image the strokes' filled outlines), renamed
|
||||
/// too.
|
||||
#[test]
|
||||
fn image_trace_outline_view_leaves_out_the_seam_fills() {
|
||||
// Red beside blue in the middle of a transparent 60 × 40 image, placed at 50, 50 and scaled 2×,
|
||||
// or 2× across and 2.5× down.
|
||||
let art = vectorcraft_trace::Raster::from_fn(60, 40, |x, y| match ((10..50).contains(&x) && (10..30).contains(&y), x < 30) {
|
||||
(false, _) => [0, 0, 0, 0],
|
||||
(true, true) => [200, 30, 30, 255],
|
||||
(true, false) => [30, 30, 200, 255],
|
||||
});
|
||||
for (scale, stretched) in [(Affine::scale(2.0), false), (Affine::scale_non_uniform(2.0, 2.5), true)] {
|
||||
let mut s = session();
|
||||
add_image(&mut s, &art, Affine::translate((50.0, 50.0)) * scale);
|
||||
let r = s.execute("imageTrace.make", &json!({"params": {"mode": "color", "palette": "limited", "colors": 2, "method": "abutting"}})).unwrap();
|
||||
let g = NodeId(r["id"].as_u64().unwrap());
|
||||
let seams =
|
||||
node(&s, g).children().unwrap().iter().find(|c| matches!(c.kind, NodeKind::Group { clip: true, .. })).cloned().expect("seam fills");
|
||||
// Strokes, or on the stretched image their outlines, filled.
|
||||
let members = &seams.children().unwrap()[1..];
|
||||
assert!(!members.is_empty());
|
||||
for m in members {
|
||||
let (fill, stroke) = (m.appearance.fill_paint(), m.appearance.stroke_paint());
|
||||
assert_eq!((fill != Paint::None, stroke != Paint::None), (stretched, !stretched), "{scale:?}: {fill:?}, {stroke:?}");
|
||||
}
|
||||
s.execute("imageTrace.setView", &json!({"id": g.0, "view": "outlines"})).unwrap();
|
||||
let screen = render_doc(&s, true);
|
||||
// The image's top edge (y = 50), away from the art: nothing drawn.
|
||||
for x in [60, 110, 160] {
|
||||
assert!(screen.pixel(x, 50)[0] > 245 && screen.pixel(x, 51)[0] > 245, "{scale:?}, x = {x}: {:?}", screen.pixel(x, 50));
|
||||
}
|
||||
// The art's left edge (x = 70) is outlined.
|
||||
assert!((68..=72).any(|x| screen.pixel(x, 90)[0] < 128), "{scale:?}");
|
||||
// Beside the red and blue paths' shared edge (x = 110), inside the seam band (1.5 units
|
||||
// each side on the stretched image) but off the traced outlines (x = 109 and 110): nothing.
|
||||
for x in [108, 111] {
|
||||
assert!(screen.pixel(x, 100)[0] > 245, "{scale:?}, x = {x}: {:?}", screen.pixel(x, 100));
|
||||
}
|
||||
// Renamed, the group is still left out: the view draws as it did.
|
||||
s.execute("layer.setProps", &json!({"id": seams.id.0, "name": "Edges"})).unwrap();
|
||||
assert!(render_doc(&s, true).pixels == screen.pixels, "{scale:?}: renamed seam fills drawn");
|
||||
}
|
||||
}
|
||||
|
||||
/// #569: merging the regions of a rosette of unfilled ellipses (each off the centre, petals
|
||||
/// overlapping) merges every region the drags touch into one shape whose outline is only the
|
||||
/// merged area's border: no edge between merged regions stays in, as a stray line or a spur.
|
||||
|
||||
@@ -512,3 +512,21 @@ fn keep_plain_text_preference_drops_pasted_formatting() {
|
||||
assert_eq!(paste_copied_range(false), 40.0, "Keep Formatting");
|
||||
assert_eq!(paste_copied_range(true), 10.0, "Keep Plain Text");
|
||||
}
|
||||
|
||||
/// #7975: pasted plain text is new type, filled as [Normal Character Style] is, not with the
|
||||
/// current fill.
|
||||
#[test]
|
||||
fn pasted_plain_text_takes_the_normal_character_style_fill() {
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
let mut s = session();
|
||||
run(&mut s, "paint.setFill", json!({"color": "#ff0000"}));
|
||||
run(&mut s, "clipboard.importText", json!({"text": "Plain"}));
|
||||
run(&mut s, "edit.paste", json!({"center": [200, 150]}));
|
||||
assert_eq!(text_of(&pasted(&s)[0]).runs[0].style.fill, Paint::solid(Color::BLACK));
|
||||
let blue = Paint::solid(Color::rgb(0.0, 0.0, 1.0));
|
||||
let attrs = crate::cmd::textstyles::char_attrs(&vectorcraft_doc::CharStyle { fill: blue.clone(), ..Default::default() });
|
||||
run(&mut s, "charStyle.setAttrs", json!({"name": "[Normal Character Style]", "attrs": {"fill": attrs["fill"]}}));
|
||||
run(&mut s, "clipboard.importText", json!({"text": "Plain"}));
|
||||
run(&mut s, "edit.paste", json!({"center": [200, 150]}));
|
||||
assert_eq!(text_of(&pasted(&s)[0]).runs[0].style.fill, blue);
|
||||
}
|
||||
|
||||
@@ -677,16 +677,16 @@ fn the_eraser_tip_varies_with_its_modes() {
|
||||
assert!((upright - 195.0).abs() < 0.3, "the upright tip left {upright} pt of the line");
|
||||
let level_tip = left_of_line(json!([]));
|
||||
assert!((level_tip - 180.0).abs() < 0.3, "the level tip left {level_tip} pt of the line");
|
||||
// A 1500 pt tip on Tilt erases 1500 pt across with a mouse, as it does on Fixed.
|
||||
// A 1000 pt tip on Tilt erases 1000 pt across with a mouse, as it does on Fixed.
|
||||
let mut s = session();
|
||||
rect(&mut s, 0.0, 0.0, 4000.0, 4000.0);
|
||||
let big = json!({"points": [[1000, 2000], [3000, 2000]], "size": 1500, "sizeMode": "tilt", "sizeVariation": 10});
|
||||
let big = json!({"points": [[1000, 2000], [3000, 2000]], "size": 1000, "sizeMode": "tilt", "sizeVariation": 10});
|
||||
s.execute("path.eraseRegion", &big).unwrap();
|
||||
let filled =
|
||||
|x: f64, y: f64| paths(&s).iter().any(|(_, pd)| vectorcraft_geom::hit::fill_contains(&pd.to_bezpath(), FillRule::NonZero, Point::new(x, y)));
|
||||
assert_eq!((filled(2000.0, 2740.0), filled(2000.0, 2760.0)), (false, true), "a 1500 pt tip");
|
||||
assert_eq!((filled(2000.0, 2490.0), filled(2000.0, 2510.0)), (false, true), "a 1000 pt tip");
|
||||
// A Size Variation kept while Size is Fixed leaves the size alone.
|
||||
let kept = with(&on_rotation, json!({"sizeMode": "fixed", "sizeVariation": 1000000}));
|
||||
let kept = with(&on_rotation, json!({"sizeMode": "fixed", "sizeVariation": 1000}));
|
||||
assert_eq!(erased(kept, json!([]), &probes), [true, false], "Size on Fixed with a Variation");
|
||||
let mut s = session();
|
||||
let id = rect(&mut s, 0.0, 0.0, 100.0, 100.0);
|
||||
@@ -2949,6 +2949,116 @@ fn drawing_commands_refuse_a_point_or_pressure_given_as_text() {
|
||||
s.execute("path.eraseRegion", &sized).unwrap();
|
||||
}
|
||||
|
||||
/// The drawing tools' commands refuse a pen pressure outside 0 to 1, a tiltX or tiltY outside -90
|
||||
/// to 90 and a rotation outside 0 to 360, naming the key, and a point array of more than six
|
||||
/// numbers, naming the point; the document, the selection and the undo history stay as they were.
|
||||
/// The ends of each range, null, one tilt axis alone and a mouse point `[x, y]` still draw.
|
||||
#[test]
|
||||
fn pen_values_outside_their_ranges_are_refused() {
|
||||
let mut s = session();
|
||||
let id = rect(&mut s, 100.0, 100.0, 100.0, 100.0);
|
||||
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
|
||||
let good = [json!([90, 150]), json!([150, 150]), json!([210, 150])];
|
||||
let cmds = [
|
||||
"path.freehand",
|
||||
"brush.freehand",
|
||||
"path.knife",
|
||||
"path.eraseRegion",
|
||||
"path.eraseSegments",
|
||||
"path.smoothRegion",
|
||||
"path.joinScrub",
|
||||
"path.blob",
|
||||
];
|
||||
let pressure = "`pressure` must be from 0 to 1";
|
||||
let tilt_x = "`tiltX` must be from -90 to 90";
|
||||
let tilt_y = "`tiltY` must be from -90 to 90";
|
||||
let rotation = "`rotation` must be from 0 to 360";
|
||||
let entries = "`points[3]` must be an array of at most 6 entries";
|
||||
for cmd in cmds {
|
||||
for (bad, want) in [
|
||||
(json!([150, 150, -0.01]), pressure),
|
||||
(json!([150, 150, 1.5]), pressure),
|
||||
(json!({"x": 150, "y": 150, "pressure": 1e300}), pressure),
|
||||
(json!([150, 150, 0.5, -90.5]), tilt_x),
|
||||
(json!([150, 150, 0.5, 91, 0]), tilt_x),
|
||||
(json!({"x": 150, "y": 150, "tiltX": -1e300}), tilt_x),
|
||||
(json!([150, 150, null, 0, -1e300]), tilt_y),
|
||||
(json!({"x": 150, "y": 150, "tiltY": 90.01}), tilt_y),
|
||||
(json!([150, 150, null, null, null, -1]), rotation),
|
||||
(json!({"x": 150, "y": 150, "rotation": 360.5}), rotation),
|
||||
(json!([150, 150, null, null, null, 720]), rotation),
|
||||
(json!([150, 150, 0.5, 0, 0, 0, 1]), entries),
|
||||
(json!([150, 150, null, null, null, null, null]), entries),
|
||||
] {
|
||||
let points: Vec<_> = good.iter().cloned().chain([bad]).collect();
|
||||
let sel = s.doc().unwrap().selection.clone();
|
||||
refuses_with(&mut s, cmd, &json!({"points": points}), want);
|
||||
assert_eq!(s.doc().unwrap().selection, sel, "{cmd} {points:?} changed the selection");
|
||||
}
|
||||
}
|
||||
for (row, cmd) in ["path.freehand", "brush.freehand", "path.blob", "path.eraseRegion"].into_iter().enumerate() {
|
||||
let y = 300.0 + 50.0 * row as f64;
|
||||
let points = json!([
|
||||
[100, y, 0, -90, 90, 0],
|
||||
[150, y, 1, 90, -90, 360],
|
||||
[200, y, 0.5, null, 30],
|
||||
{"x": 250, "y": y, "tiltX": -45, "pressure": null},
|
||||
[300, y],
|
||||
{"x": 350, "y": y, "rotation": 359.99},
|
||||
]);
|
||||
s.execute(cmd, &json!({"points": points})).unwrap_or_else(|e| panic!("{cmd}: {e}"));
|
||||
let mouse = json!([[100, y + 20.0], [200, y + 20.0], [300, y + 25.0]]);
|
||||
s.execute(cmd, &json!({"points": mouse})).unwrap_or_else(|e| panic!("{cmd} with mouse points: {e}"));
|
||||
}
|
||||
}
|
||||
|
||||
/// `path.blob` and `path.eraseRegion` refuse a `size` outside 0.1 to 1000 pt and a `sizeVariation`
|
||||
/// outside 0 to 1000 pt, in every `sizeMode` each takes and with it left out, and a `sizeVariation`
|
||||
/// that is not a number with Fixed too; nothing changes. The ends of each range and null still draw.
|
||||
#[test]
|
||||
fn blob_and_eraser_size_and_variation_outside_their_ranges_are_refused() {
|
||||
let mut s = session();
|
||||
let id = rect(&mut s, 100.0, 100.0, 100.0, 100.0);
|
||||
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
|
||||
let stroke = json!({"points": [[90, 150, 0.2, 30, 0, 45], [150, 150, 0.6, 0, 30, 90], [210, 150, 1, -30, 0, 180]]});
|
||||
let size = "`size` must be from 0.1 to 1000";
|
||||
let variation = "`sizeVariation` must be from 0 to 1000";
|
||||
let blob_modes = [json!(null), json!("fixed"), json!("pressure")];
|
||||
let eraser_modes = [json!(null), json!("fixed"), json!("random"), json!("pressure"), json!("tilt"), json!("bearing"), json!("rotation")];
|
||||
// The Eraser keeps its own message for a negative Size Variation.
|
||||
for (cmd, modes, negative) in
|
||||
[("path.blob", &blob_modes[..], variation), ("path.eraseRegion", &eraser_modes[..], "sizeVariation must be 0 or more")]
|
||||
{
|
||||
for x in [json!(0.09), json!(0), json!(-1), json!(1000.5), json!(1e300)] {
|
||||
let sel = s.doc().unwrap().selection.clone();
|
||||
refuses_with(&mut s, cmd, &with(&stroke, json!({"size": x})), size);
|
||||
assert_eq!(s.doc().unwrap().selection, sel, "{cmd} size {x} changed the selection");
|
||||
}
|
||||
for mode in modes {
|
||||
for (x, want) in [(json!(-0.5), negative), (json!(1000.01), variation), (json!(1e300), variation)] {
|
||||
let sel = s.doc().unwrap().selection.clone();
|
||||
refuses_with(&mut s, cmd, &with(&stroke, json!({"sizeMode": mode, "sizeVariation": x})), want);
|
||||
assert_eq!(s.doc().unwrap().selection, sel, "{cmd} {mode} sizeVariation {x} changed the selection");
|
||||
}
|
||||
let text = json!({"sizeMode": mode, "sizeVariation": "8"});
|
||||
refuses_with(&mut s, cmd, &with(&stroke, text), "`sizeVariation` must be a number, not \"8\"");
|
||||
}
|
||||
}
|
||||
for (row, (cmd, modes)) in [("path.blob", &blob_modes[..]), ("path.eraseRegion", &eraser_modes[..])].into_iter().enumerate() {
|
||||
let y = 300.0 + 100.0 * row as f64;
|
||||
let at = |p: serde_json::Value| with(&json!({"points": [[100, y, 0.2, 30, 0, 0], [200, y, 0.6, 0, 30, 90], [300, y, 1, -30, 0, 360]]}), p);
|
||||
for extra in [json!({"size": 0.1}), json!({"size": 1000}), json!({"size": null, "sizeVariation": null, "sizeMode": null})] {
|
||||
s.execute(cmd, &at(extra.clone())).unwrap_or_else(|e| panic!("{cmd} {extra}: {e}"));
|
||||
}
|
||||
for mode in modes {
|
||||
for x in [0, 1000] {
|
||||
let extra = json!({"sizeMode": mode, "sizeVariation": x});
|
||||
s.execute(cmd, &at(extra.clone())).unwrap_or_else(|e| panic!("{cmd} {extra}: {e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The Eraser, Path Eraser, Smooth, Join and Blob Brush commands refuse a size, angle, roundness,
|
||||
/// width, radius, fidelity or tolerance given as text or as another value that is not a number, and change
|
||||
/// nothing; null is read as the key left out.
|
||||
|
||||
@@ -2117,6 +2117,35 @@ fn confined_clipboard_svg_refuses_a_linked_image_file_outside_the_read_roots() {
|
||||
assert!(svg.contains(&format!("xlink:href=\"{photo}\"")), "{svg}");
|
||||
}
|
||||
|
||||
/// `clipboard.flavours` and the session's flavors leave out the SVG, and its markup as text, that
|
||||
/// `clipboard.exportSvg` withholds from a confined caller; the PNG is still listed. The SVG is listed
|
||||
/// while its image's pixels are held, and for a caller with no read roots.
|
||||
#[test]
|
||||
fn confined_clipboard_flavours_leave_out_a_withheld_svg() {
|
||||
use crate::file_access::{AutomationRoots, confine};
|
||||
|
||||
let away = Folder::new("clip-flavours-away");
|
||||
let home = Folder::new("clip-flavours-home");
|
||||
let photo = away.file("photo.png");
|
||||
write(&photo, &png(60, 30, RED));
|
||||
let mut s = session();
|
||||
let a = place(&mut s, &photo);
|
||||
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
|
||||
s.execute("edit.copy", &json!({})).unwrap();
|
||||
let roots = AutomationRoots::new(&[home.0.as_path()], &[home.0.as_path()]).unwrap();
|
||||
let (text, svg, png) = ("text/plain", "image/svg+xml", "image/png");
|
||||
let listed = |s: &mut Session| confine(roots.as_ref(), || s.execute("clipboard.flavours", &json!({}))).unwrap()["flavours"].clone();
|
||||
assert_eq!(listed(&mut s), json!([text, svg, png]));
|
||||
|
||||
without_pixels(&mut s, a);
|
||||
s.execute("edit.copy", &json!({})).unwrap();
|
||||
assert_eq!(listed(&mut s), json!([png]));
|
||||
let made = confine(roots.as_ref(), || s.clipboard_flavours());
|
||||
assert!(made.iter().all(|f| f.mime != svg && f.mime != text), "{:?}", made.iter().map(|f| f.mime).collect::<Vec<_>>());
|
||||
assert_eq!(confine(roots.as_ref(), || s.clipboard_flavour_types()), [png]);
|
||||
assert_eq!(s.execute("clipboard.flavours", &json!({})).unwrap()["flavours"], json!([text, svg, png]));
|
||||
}
|
||||
|
||||
/// A confined caller's SVG with Preserve Editing Capabilities is refused while the stored brush
|
||||
/// library holds an entry that does not read as a brush, or is not a list: the native document
|
||||
/// carries it as it is, and its links cannot be checked. Without Preserve Editing the SVG is written.
|
||||
|
||||
@@ -278,6 +278,35 @@ fn each_copys_shadow_expands_as_the_canvas_draws_it() {
|
||||
assert_eq!(diff, 0, "{diff} pixels differ");
|
||||
}
|
||||
|
||||
/// Each copy of type's Transform effect draws the drop shadow listed before the effect under
|
||||
/// itself, scaled with it, and Expand Appearance keeps those shadows: the type's copy, scaled 200 %
|
||||
/// and moved 80 pt down, has its shadow 40 pt to the right of its letters rather than the type's
|
||||
/// own 20 pt.
|
||||
#[test]
|
||||
fn each_copys_shadow_on_type_expands_as_the_canvas_draws_it() {
|
||||
let mut s = session();
|
||||
let t = run(&mut s, "text.create", json!({"x": 20, "y": 60, "text": "I", "size": 40}))["id"].as_u64().unwrap();
|
||||
run(&mut s, "select.set", json!({"ids": [t]}));
|
||||
run(&mut s, "paint.setFill", json!({"color": "#ff0000"}));
|
||||
let shadow = json!({"x": 20, "y": 0, "blur": 0, "opacity": 100, "mode": "normal", "color": "#00ff00"});
|
||||
run(&mut s, "effect.apply", json!({"effect": "stylize.dropShadow", "params": shadow}));
|
||||
run(&mut s, "effect.apply", json!({"effect": "distort.transform", "params": {"scaleH": 200, "scaleV": 200, "moveV": 80, "copies": 1}}));
|
||||
let before = render(&s);
|
||||
if !(0..100u32).any(|y| (0..200u32).any(|x| before.pixel(x, y) == [255, 0, 0, 255])) {
|
||||
eprintln!("skipped: built without a font that draws the type");
|
||||
return;
|
||||
}
|
||||
// The rightmost red pixel of the copy, below the type, and 38 pt right of it the copy's shadow.
|
||||
let red =
|
||||
(100..200u32).flat_map(|y| (0..200u32).map(move |x| (x, y))).filter(|&(x, y)| before.pixel(x, y) == [255, 0, 0, 255]).max_by_key(|p| p.0);
|
||||
let (x, y) = red.expect("the copy");
|
||||
assert_eq!(before.pixel(x + 38, y), [0, 255, 0, 255], "the copy's shadow, 40 pt to the right of ({x}, {y})");
|
||||
run(&mut s, "effect.expandAppearance", json!({}));
|
||||
let after = render(&s);
|
||||
let diff = differing(&before, &after, 64);
|
||||
assert_eq!(diff, 0, "{diff} pixels differ");
|
||||
}
|
||||
|
||||
/// A group's Transform effect runs after its member's own Offset Path in Expand Appearance as on
|
||||
/// the canvas: the 100 pt square offset to 120 pt and scaled by half expands 60 pt wide.
|
||||
#[test]
|
||||
|
||||
@@ -276,3 +276,61 @@ fn overprint_black_covers_type_gradients_spots_and_groups() {
|
||||
s.execute("edit.colors.overprintBlack", &json!({"includeCmyBlacks": true, "includeSpotBlacks": true})).unwrap();
|
||||
assert!(fill(&s, g) && fill(&s, spot));
|
||||
}
|
||||
|
||||
/// The plate `plate` of `doc`, drawn as Separations Preview draws one plate, as one gray value per
|
||||
/// pixel (0 full ink, 255 none).
|
||||
fn plate(doc: &Document, plate: &str) -> Vec<u8> {
|
||||
let mut r = Renderer::new();
|
||||
r.threads = 0;
|
||||
let seps = vectorcraft_render::proof::ProofSetup { separations: Some(vec![plate.into()]), ..Default::default() };
|
||||
let opts = RenderOptions { background: Some([255, 255, 255, 255]), proof: Some(seps), ..Default::default() };
|
||||
let image = r.render(doc, 100, 100, Affine::IDENTITY, &opts);
|
||||
(0..100 * 100).map(|i| image.pixel(i % 100, i / 100)[0]).collect()
|
||||
}
|
||||
|
||||
/// 3D (Classic) with the shading color Black Overprint puts the shading on the black plate, shows
|
||||
/// it as the cyan darkened, and writes it to PDF as overprinting fills.
|
||||
#[test]
|
||||
fn classic_3d_black_overprint_shades_on_the_black_plate() {
|
||||
let doc = |params: Value| {
|
||||
let mut s = session();
|
||||
rect(&mut s, [30.0, 30.0, 40.0, 40.0], cyan_ink(), None, 0.0);
|
||||
s.execute("effect.apply", &json!({"effect": "threeD.classicExtrude", "item": null, "params": params})).unwrap();
|
||||
s
|
||||
};
|
||||
let over = doc(json!({"surface": "diffuse", "depth": 20, "shadingColor": "blackOverprint"}));
|
||||
let flat = doc(json!({"surface": "none", "depth": 20, "shadingColor": "blackOverprint"}));
|
||||
let black = doc(json!({"surface": "diffuse", "depth": 20}));
|
||||
let (over_doc, flat_doc) = (&over.doc().unwrap().doc, &flat.doc().unwrap().doc);
|
||||
let inked = |p: &[u8]| p.iter().filter(|v| **v < 250).count();
|
||||
assert!(inked(&plate(over_doc, "Cyan")) > 1000, "the solid is drawn");
|
||||
assert!(inked(&plate(over_doc, "Black")) > 100, "the shading is on the black plate");
|
||||
assert_eq!(inked(&plate(flat_doc, "Black")), 0, "No Shading adds no black");
|
||||
// On screen a shaded face is the cyan darkened, not gray: the black multiplies the cyan.
|
||||
let image = |d: &Document| {
|
||||
let mut r = Renderer::new();
|
||||
r.threads = 0;
|
||||
let opts = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() };
|
||||
r.render(d, 100, 100, Affine::IDENTITY, &opts)
|
||||
};
|
||||
let (shaded, unshaded) = (image(over_doc), image(flat_doc));
|
||||
let mut darker = 0;
|
||||
for (x, y) in (0..100u32).flat_map(|y| (0..100u32).map(move |x| (x, y))) {
|
||||
let (s, u) = (shaded.pixel(x, y), unshaded.pixel(x, y));
|
||||
// Inside the solid (no white mixed in at an antialiased edge) where the shading darkens it.
|
||||
if u[0] < 30 && (s[1] as i32) + 20 < u[1] as i32 {
|
||||
darker += 1;
|
||||
assert!(s[2] as i32 > s[0] as i32 + 20, "a shaded face keeps its cyan at ({x}, {y}): {s:?}");
|
||||
}
|
||||
}
|
||||
assert!(darker > 100, "the faces turned from the light are darker");
|
||||
|
||||
let pdf_overprints = |s: &mut Session| {
|
||||
let v = s.execute("document.exportPdf", &json!({"compression": {"compressText": false}, "preserveEditing": false})).unwrap();
|
||||
let bytes = vectorcraft_format::base64_decode(v["dataBase64"].as_str().unwrap()).unwrap();
|
||||
String::from_utf8_lossy(&bytes).matches("/OP true/op true/OPM 1").count()
|
||||
};
|
||||
let (mut over, mut black) = (over, black);
|
||||
assert!(pdf_overprints(&mut over) > 0, "the black is written overprinting");
|
||||
assert_eq!(pdf_overprints(&mut black), 0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Clicks, hovers and marquees with the selection tools leave out the area that raster effects
|
||||
//! (drop shadows, glows, blurs) paint beyond an object: there they reach the object under the
|
||||
//! effect, or nothing.
|
||||
//! effect, or nothing. Clicks and marquees take art where its geometry effects draw it.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_doc::NodeId;
|
||||
@@ -391,3 +391,107 @@ fn group_selection_hover_over_a_drop_shadow_marks_nothing() {
|
||||
}
|
||||
assert_eq!(press(&mut s, "groupSelection", (110.0, 50.0), (110.0, 50.0), Mods::default()), [b]);
|
||||
}
|
||||
|
||||
/// A rectangle that a Transform effect moves 100 pt to the right is selected by a click and by a
|
||||
/// marquee where it is drawn, and not at its own place, which it no longer paints. The same holds
|
||||
/// for a group whose own Transform effect moves it.
|
||||
#[test]
|
||||
fn a_click_and_a_marquee_select_art_where_its_transform_effect_draws_it() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 20.0, 20.0, 40.0, 40.0, "#ff0000");
|
||||
run(&mut s, "effect.apply", json!({"effect": "distort.transform", "ids": [a.0], "params": {"moveH": 100}, "item": null}));
|
||||
assert_eq!(pixel(&s, 140, 40), [255, 0, 0, 255], "drawn where it moved");
|
||||
assert_eq!(pixel(&s, 40, 40), WHITE, "not drawn at its own place");
|
||||
run(&mut s, "select.none", json!({}));
|
||||
assert!(click(&mut s, 40.0, 40.0).is_empty());
|
||||
assert_eq!(click(&mut s, 140.0, 40.0), [a]);
|
||||
assert_eq!(press(&mut s, "selection", (110.0, 10.0), (130.0, 30.0), Mods::default()), [a], "a marquee across its drawn corner");
|
||||
run(&mut s, "select.none", json!({}));
|
||||
assert!(press(&mut s, "selection", (10.0, 10.0), (30.0, 30.0), Mods::default()).is_empty(), "a marquee across its own corner");
|
||||
|
||||
let mut s = session();
|
||||
let b = rect(&mut s, 20.0, 120.0, 40.0, 40.0, "#0000ff");
|
||||
run(&mut s, "select.set", json!({"ids": [b.0]}));
|
||||
let g = id_of(&run(&mut s, "object.group", json!({})));
|
||||
run(&mut s, "effect.apply", json!({"effect": "distort.transform", "ids": [g.0], "params": {"moveH": 100}, "item": null}));
|
||||
assert_eq!(pixel(&s, 140, 140), BLUE, "the group drawn where it moved");
|
||||
run(&mut s, "select.none", json!({}));
|
||||
assert!(click(&mut s, 40.0, 140.0).is_empty());
|
||||
assert_eq!(click(&mut s, 140.0, 140.0), [g]);
|
||||
assert_eq!(press(&mut s, "selection", (110.0, 110.0), (130.0, 130.0), Mods::default()), [g]);
|
||||
run(&mut s, "select.none", json!({}));
|
||||
assert!(press(&mut s, "selection", (10.0, 110.0), (30.0, 130.0), Mods::default()).is_empty());
|
||||
}
|
||||
|
||||
/// A group's own fill paints its member's shape before the member's own Transform effect moves the
|
||||
/// member: a click there selects the group, and a click on the moved member selects it too. A
|
||||
/// Direct Selection marquee takes the group there and the member where it moved.
|
||||
#[test]
|
||||
fn a_click_selects_a_group_where_its_own_fill_paints_a_moved_member() {
|
||||
let mut s = session();
|
||||
let b = rect(&mut s, 20.0, 120.0, 40.0, 40.0, "#0000ff");
|
||||
run(&mut s, "select.set", json!({"ids": [b.0]}));
|
||||
let g = id_of(&run(&mut s, "object.group", json!({})));
|
||||
run(&mut s, "appearance.addFill", json!({}));
|
||||
run(&mut s, "appearance.setActiveItem", json!({"index": 0}));
|
||||
run(&mut s, "paint.setFill", json!({"color": "#ff0000"}));
|
||||
run(&mut s, "effect.apply", json!({"effect": "distort.transform", "ids": [b.0], "params": {"moveH": 100}, "item": null}));
|
||||
assert_eq!(pixel(&s, 40, 140), [255, 0, 0, 255], "the group's fill at the member's own place");
|
||||
assert_eq!(pixel(&s, 140, 140), BLUE, "the member where it moved");
|
||||
run(&mut s, "select.none", json!({}));
|
||||
assert_eq!(click(&mut s, 40.0, 140.0), [g]);
|
||||
run(&mut s, "select.none", json!({}));
|
||||
assert_eq!(click(&mut s, 140.0, 140.0), [g]);
|
||||
// A marquee across the edge of the group's fill takes the group, and one across the moved
|
||||
// member's edge takes the member.
|
||||
let doc = &s.doc().unwrap().doc;
|
||||
assert_eq!(vectorcraft_doc::hit::marquee(doc, Rect::new(10.0, 130.0, 30.0, 150.0), None, true), [g]);
|
||||
assert_eq!(vectorcraft_doc::hit::marquee(doc, Rect::new(110.0, 130.0, 130.0, 150.0), None, true), [b]);
|
||||
}
|
||||
|
||||
/// An inner group's own fill paints its member's shape before the member's own Transform effect
|
||||
/// moves the member, and so does an outer group's own fill around it: a Direct Selection marquee
|
||||
/// across the edge of those fills takes both groups, and one across the moved member takes it.
|
||||
#[test]
|
||||
fn a_marquee_takes_an_inner_groups_own_fill_inside_a_painted_group() {
|
||||
let mut s = session();
|
||||
let b = rect(&mut s, 20.0, 120.0, 40.0, 40.0, "#0000ff");
|
||||
run(&mut s, "select.set", json!({"ids": [b.0]}));
|
||||
let g = id_of(&run(&mut s, "object.group", json!({})));
|
||||
run(&mut s, "appearance.addFill", json!({}));
|
||||
run(&mut s, "appearance.setActiveItem", json!({"index": 0}));
|
||||
run(&mut s, "paint.setFill", json!({"color": "#ff0000"}));
|
||||
run(&mut s, "effect.apply", json!({"effect": "distort.transform", "ids": [b.0], "params": {"moveV": -100}, "item": null}));
|
||||
run(&mut s, "select.set", json!({"ids": [g.0]}));
|
||||
let o = id_of(&run(&mut s, "object.group", json!({})));
|
||||
run(&mut s, "appearance.addFill", json!({}));
|
||||
run(&mut s, "appearance.setActiveItem", json!({"index": 0}));
|
||||
run(&mut s, "paint.setFill", json!({"color": "#00ff00"}));
|
||||
assert_eq!(pixel(&s, 40, 140), [0, 255, 0, 255], "the outer group's fill at the member's own place");
|
||||
assert_eq!(pixel(&s, 40, 40), BLUE, "the member where it moved");
|
||||
let doc = &s.doc().unwrap().doc;
|
||||
assert_eq!(vectorcraft_doc::hit::marquee(doc, Rect::new(10.0, 130.0, 30.0, 150.0), None, true), [o, g]);
|
||||
assert_eq!(vectorcraft_doc::hit::marquee(doc, Rect::new(10.0, 30.0, 30.0, 50.0), None, true), [b]);
|
||||
}
|
||||
|
||||
/// A group's own fill paints its member's shape before the member's own Transform effect moves
|
||||
/// the member, and so does its layer's own fill around it: a Direct Selection marquee across the
|
||||
/// edge of the group's fill takes the group, and one across the moved member takes it.
|
||||
#[test]
|
||||
fn a_marquee_takes_a_groups_own_fill_inside_a_painted_layer() {
|
||||
let mut s = session();
|
||||
let b = rect(&mut s, 20.0, 120.0, 40.0, 40.0, "#0000ff");
|
||||
run(&mut s, "select.set", json!({"ids": [b.0]}));
|
||||
let g = id_of(&run(&mut s, "object.group", json!({})));
|
||||
run(&mut s, "appearance.addFill", json!({}));
|
||||
run(&mut s, "appearance.setActiveItem", json!({"index": 0}));
|
||||
run(&mut s, "paint.setFill", json!({"color": "#ff0000"}));
|
||||
run(&mut s, "effect.apply", json!({"effect": "distort.transform", "ids": [b.0], "params": {"moveV": -100}, "item": null}));
|
||||
let l = s.doc().unwrap().doc.layers[0].id;
|
||||
run(&mut s, "appearance.addFill", json!({"ids": [l.0]}));
|
||||
assert!(!s.doc().unwrap().doc.layers[0].appearance.items.is_empty(), "the layer has a fill of its own");
|
||||
assert_eq!(pixel(&s, 40, 40), BLUE, "the member where it moved");
|
||||
let doc = &s.doc().unwrap().doc;
|
||||
assert_eq!(vectorcraft_doc::hit::marquee(doc, Rect::new(10.0, 130.0, 30.0, 150.0), None, true), [g]);
|
||||
assert_eq!(vectorcraft_doc::hit::marquee(doc, Rect::new(10.0, 30.0, 30.0, 50.0), None, true), [b]);
|
||||
}
|
||||
|
||||
@@ -262,8 +262,8 @@ fn document_color_mode_converts_effect_colors() {
|
||||
assert_eq!((object(&s), style(&s)), before);
|
||||
}
|
||||
|
||||
/// Document Color Mode converts the series paints and label styles a graph keeps, so a graph drawn
|
||||
/// again after the switch paints its series and labels in the new mode.
|
||||
/// Document Color Mode converts the series paints, label styles and line rows a graph keeps, so a
|
||||
/// graph drawn again after the switch paints its series, labels and lines in the new mode.
|
||||
#[test]
|
||||
fn document_color_mode_converts_the_paints_a_graph_keeps() {
|
||||
let mut s = session();
|
||||
@@ -284,22 +284,26 @@ fn document_color_mode_converts_the_paints_a_graph_keeps() {
|
||||
}
|
||||
// A fill row on the label, which the graph keeps with the label's rows.
|
||||
run(&mut s, "appearance.addFill", json!({"ids": [label.0]}));
|
||||
// A stroke on an axis line, which the graph keeps for its axis lines and tick marks.
|
||||
let line = part(&s, "Axes").children().unwrap().iter().find(|c| matches!(c.kind, vectorcraft_doc::NodeKind::Path { .. })).unwrap().id;
|
||||
run(&mut s, "paint.setStroke", json!({"color": "#ff0000", "ids": [line.0]}));
|
||||
let kept = |s: &Session| -> Vec<Color> {
|
||||
let g = doc(s).node(id).unwrap().extras().graph.as_deref().unwrap().clone();
|
||||
let rows = [&g.label_styles.values_rows, &g.label_styles.categories_rows, &g.label_styles.legend_rows];
|
||||
let rows: Vec<Color> = rows.into_iter().flatten().filter_map(|r| r.paint.fill.as_ref()?.color()).collect();
|
||||
let lines = g.label_styles.axis_rows.iter().filter_map(|r| r.paint.stroke.as_ref()?.color());
|
||||
let labels = [g.label_styles.values, g.label_styles.categories, g.label_styles.legend];
|
||||
let labels = labels.into_iter().flatten().map(|st| st.fill.color().unwrap());
|
||||
g.series_paints.iter().filter_map(|p| p.fill.as_ref()?.color()).chain(labels).chain(rows).collect()
|
||||
g.series_paints.iter().filter_map(|p| p.fill.as_ref()?.color()).chain(labels).chain(rows).chain(lines).collect()
|
||||
};
|
||||
let before = kept(&s);
|
||||
assert_eq!(before, [Color::rgb(1.0, 0.0, 0.0); 3]);
|
||||
assert_eq!(before, [Color::rgb(1.0, 0.0, 0.0); 4]);
|
||||
let undo = s.doc().unwrap().history.undo.len();
|
||||
|
||||
run(&mut s, "file.documentColorMode", json!({"mode": "cmyk"}));
|
||||
let cmyk = first_fill(doc(&s).node(red).unwrap());
|
||||
assert!(matches!(cmyk, Color::Cmyk { .. }), "{cmyk:?}");
|
||||
assert_eq!(kept(&s), [cmyk; 3]);
|
||||
assert_eq!(kept(&s), [cmyk; 4]);
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1);
|
||||
// Drawn again from new data, the series keeps the converted color.
|
||||
run(&mut s, "graph.setData", json!({"id": id.0, "rows": [[2, 3], [4, 5]]}));
|
||||
|
||||
@@ -4027,3 +4027,35 @@ fn apply_fill_to_stroke_with_characters_selected_changes_only_them() {
|
||||
let labels = undo_labels(&s);
|
||||
assert_eq!((labels.len(), labels.last().map(String::as_str)), (steps + 1, Some("Apply Fill to Stroke")));
|
||||
}
|
||||
|
||||
/// Redefines `[Normal Character Style]` with `fill` (`charStyle.setAttrs`).
|
||||
fn set_normal_fill(s: &mut Session, fill: vectorcraft_color::Paint) {
|
||||
let attrs = crate::cmd::textstyles::char_attrs(&CharStyle { fill, ..CharStyle::default() });
|
||||
s.execute("charStyle.setAttrs", &json!({"name": "[Normal Character Style]", "attrs": {"fill": attrs["fill"]}})).unwrap();
|
||||
}
|
||||
|
||||
/// #7975: type the Type tool starts is filled as [Normal Character Style] is, black unless it was
|
||||
/// redefined, not with the current fill a shape left behind.
|
||||
#[test]
|
||||
fn new_type_takes_the_normal_character_style_fill_not_the_current_fill() {
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
let mut s = session();
|
||||
let v = ViewInfo::default();
|
||||
s.execute("shape.rectangle", &json!({"x": 20, "y": 20, "width": 60, "height": 60})).unwrap();
|
||||
s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap();
|
||||
s.execute("select.set", &json!({"ids": []})).unwrap();
|
||||
assert_eq!(s.paint.fill, Paint::solid(Color::rgb(1.0, 0.0, 0.0)), "the current fill is red");
|
||||
s.select_tool("type", v).unwrap();
|
||||
click(&mut s, 200.0, 200.0);
|
||||
s.tool_text("Black", v).unwrap();
|
||||
let id = s.doc().unwrap().selection.objects[0];
|
||||
assert_eq!(obj(&s, id).runs[0].style.fill, Paint::solid(Color::BLACK));
|
||||
// A redefined [Normal Character Style] gives new type its fill.
|
||||
let blue = Paint::solid(Color::rgb(0.0, 0.0, 1.0));
|
||||
set_normal_fill(&mut s, blue.clone());
|
||||
let made = s.execute("text.create", &json!({"x": 100, "y": 300, "text": "Blue"})).unwrap();
|
||||
assert_eq!(obj(&s, NodeId(made["id"].as_u64().unwrap())).runs[0].style.fill, blue);
|
||||
// A color given to the command still wins.
|
||||
let made = s.execute("text.create", &json!({"x": 100, "y": 400, "text": "Green", "color": "#00ff00"})).unwrap();
|
||||
assert_eq!(obj(&s, NodeId(made["id"].as_u64().unwrap())).runs[0].style.fill, Paint::solid(Color::rgb(0.0, 1.0, 0.0)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user