Symbols: clicks reach an image's shape grown by an instance fill effect

An image in a symbol's art whose own fill or stroke paints a shape
(Convert to Shape, Outline Object) takes the instance's fill and stroke
geometry effects on the canvas, but hit testing and the cull box measured
only the paths in the art, so a click on the grown shape missed the
instance. The painted shapes of an instance's art now include those of
its images, as for an image on its own.
This commit is contained in:
dotCooCoo
2026-11-13 19:07:59 -08:00
parent f7229c018b
commit 58f41ca719
2 changed files with 31 additions and 1 deletions
+3 -1
View File
@@ -445,7 +445,8 @@ fn push_painted(doc: Option<&Document>, c: &Node, out: &mut Vec<(BezPath, FillRu
/// its active fill and stroke ([`has_item_geometry`]): the paths of the art [`reshape`] makes of it,
/// each with its own geometry effects and those of each fill and stroke applied
/// ([`crate::bake_type_appearance`], [`push_painted`]), the paths that the own fills and strokes of
/// the groups and layers in the art paint ([`crate::evaluate_container`]), and the instances in that
/// the groups and layers in the art paint ([`crate::evaluate_container`]), the shapes that the own
/// fills and strokes of the images in the art paint ([`image_paint`]), and the instances in that
/// art that took those effects, in turn. Hidden objects, clipping paths, guides and the members of
/// clip groups add nothing, and neither does an instance more than
/// [`vectorcraft_doc::depth::MAX_DEPTH`] deep or whose symbol's art would take the objects measured
@@ -477,6 +478,7 @@ fn painted_in(doc: Option<&Document>, n: &Node, depth: usize, budget: &mut u64,
None => push_painted(doc, n, out),
},
NodeKind::Path { .. } => {}
NodeKind::Image(_) => out.extend(image_paint(doc, n)),
NodeKind::SymbolInstance { .. } => instance_paint(doc, n, depth + 1, budget, out),
_ if n.clips() => {}
_ => {
+28
View File
@@ -387,6 +387,34 @@ fn a_fill_effect_reshapes_the_fill_of_a_group_in_the_art() {
assert!(differing(&before, &after, 8) < 200, "expanding changed {} pixels", differing(&before, &after, 8));
}
/// An image in the symbol's art whose fill Convert to Shape gives a shape: the instance's fill
/// effect grows what that fill paints, and a click there selects the instance.
#[test]
fn a_click_on_the_grown_fill_of_an_image_in_the_art_selects_the_instance() {
let mut s = session();
let mut png = vec![];
image::RgbaImage::from_pixel(30, 30, image::Rgba([255, 0, 0, 255]))
.write_to(&mut std::io::Cursor::new(&mut png), image::ImageFormat::Png)
.unwrap();
// The frame runs from 85 to 115; the fill's shape is 9 pt larger on each side.
let r = run(&mut s, "file.place", json!({"name": "red.png", "dataBase64": vectorcraft_format::base64_encode(&png), "at": [100, 100]}));
let im = NodeId(r["ids"][0].as_u64().unwrap());
run(&mut s, "select.set", json!({"ids": [im.0]}));
run(&mut s, "appearance.addFill", json!({}));
run(&mut s, "paint.setFill", json!({"color": "#0000ff", "item": 0}));
run(&mut s, "effect.apply", json!({"effect": "convertToShape.rectangle", "item": 0}));
let id = NodeId(run(&mut s, "symbol.new", json!({"name": "Image"}))["id"].as_u64().unwrap());
run(&mut s, "appearance.addFill", json!({"ids": [id.0]}));
let row = node(&s, id).appearance.items.len() - 1;
run(&mut s, "appearance.setItem", json!({"ids": [id.0], "index": row, "none": true}));
let opt = vectorcraft_doc::hit::HitOptions { tol: 1.0, ..Default::default() };
assert_eq!(hit_at(&s, 70.0, opt), None);
offset_row(&mut s, id, row, 10.0);
assert!(near(render(&s).pixel(70, 100), BLUE), "the image's fill grows by the offset: {:?}", render(&s).pixel(70, 100));
assert_eq!(hit_at(&s, 70.0, opt), Some(id), "a click on the image's grown fill");
assert_eq!(hit_at(&s, 60.0, opt), None, "a click past the grown fill");
}
/// Of several fills, only the topmost one's effects reach the art, and only while it is visible.
#[test]
fn only_the_topmost_visible_instance_fill_reshapes_the_art() {