Stroke options on a group with its own stroke edit that stroke

stroke.set without an item always went to the painted leaves, so a join
set on a group whose stroke is its own (a row in the group's stack)
left that stroke alone and gave every member without a stroke a new
black 1 pt one: on a PDF map, every glyph path got an outline. A
selected group or layer with a stroke row of its own now edits that
row, as the Stroke panel does with the group targeted; other targets
reach their leaves as before. A stroke row made for options alone
(cap, join, miter limit, dashes, alignment) has no paint, so nothing
becomes visible; a weight, an arrowhead or a profile still gives the
black stroke.

Fixes #6739
This commit is contained in:
Hamza
2026-11-12 12:01:40 +05:00
parent 5eefe7d1c5
commit 280ca031b5
2 changed files with 69 additions and 3 deletions
+26 -2
View File
@@ -206,11 +206,31 @@ fn no_targets(ids: &[vectorcraft_doc::NodeId], p: &Value) -> bool {
ids.is_empty() && p.get("ids").is_none() && p.get("id").is_none()
}
/// The objects `stroke.set` edits with no `item`: a selected group or layer with a stroke row of
/// its own edits that row, as the Stroke panel does with the group targeted (#6739); the other
/// targets reach their painted leaves, as before.
fn own_stroke_or_leaves(s: &Session, p: &Value) -> Result<Vec<vectorcraft_doc::NodeId>> {
let picked = super::targets(s, p)?;
let d = &s.doc()?.doc;
let own = |id: &vectorcraft_doc::NodeId| {
d.node(*id).is_some_and(|n| {
matches!(n.kind, NodeKind::Group { .. } | NodeKind::Layer { .. }) && !n.is_compound_shape() && n.appearance.stroke().is_some()
})
};
let (mut out, rest): (Vec<_>, Vec<_>) = picked.into_iter().partition(own);
for id in super::leaf_targets(s, &rest)? {
if !out.contains(&id) {
out.push(id);
}
}
Ok(out)
}
fn stroke_set(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "stroke.set";
let change = StrokeChange::parse(p, C)?;
let item = item_target(s, p, C)?.of_kind(s, false);
let mut ids = item.targets(s, p)?;
let mut ids = if item == ItemTarget::Top { own_stroke_or_leaves(s, p)? } else { item.targets(s, p)? };
let new_art = no_targets(&ids, p);
if item == ItemTarget::Top {
// Images and symbol instances take no stroke from the panel.
@@ -261,7 +281,11 @@ fn stroke_set(s: &mut Session, p: &Value) -> Result<Value> {
return Ok(());
}
if index.is_none() && n.appearance.stroke().is_none() {
n.appearance.set_stroke(Paint::solid(Color::BLACK));
// Options alone (cap, join, miter limit, dashes, alignment) don't make a stroke
// visible: the row made for them has no paint. A weight, an arrowhead or a profile
// still gives the object the black stroke the panel draws (#6739).
let visible = change.weight.is_some() || sa.is_some() || ea.is_some() || profile.is_some();
n.appearance.set_stroke(if visible { Paint::solid(Color::BLACK) } else { Paint::None });
}
if let Some(st) = n.appearance.stroke_at_mut(index) {
set(st);
+43 -1
View File
@@ -3,7 +3,7 @@
use serde_json::{Value, json};
use vectorcraft_color::{BlendMode, Color, GradientKind, Paint};
use vectorcraft_doc::{AppearanceItem, FillLayer, Node};
use vectorcraft_doc::{AppearanceItem, FillLayer, LineJoin, Node};
use crate::*;
@@ -185,6 +185,48 @@ fn group_rows_are_the_groups_own_stack() {
assert_eq!(fill_paint(&node(&s, b), 0).color().unwrap().to_hex(), "#00ff00");
}
/// #6739: `stroke.set` without an item on a group with a stroke row of its own edits that row;
/// its members, which have no stroke (as paths a PDF import brings in), are left alone instead of
/// each getting a black 1 pt stroke. Options alone never make a stroke visible: a row created for
/// a join has no paint, while a weight still gives the usual black stroke.
#[test]
fn stroke_options_on_a_group_with_its_own_stroke_edit_that_stroke() {
let mut s = session();
let (a, b) = (rect(&mut s, 100.0), rect(&mut s, 250.0));
for id in [a, b] {
run(&mut s, "appearance.removeItem", json!({"ids": [id.0], "index": 1}));
assert!(node(&s, id).appearance.stroke().is_none(), "the member has no stroke row");
}
let g = NodeId(run(&mut s, "object.group", json!({"ids": [a.0, b.0]}))["id"].as_u64().unwrap());
run(&mut s, "appearance.addStroke", json!({"ids": [g.0]}));
run(&mut s, "appearance.setItem", json!({"ids": [g.0], "index": 0, "color": "#ffffff", "weight": 2}));
let r = run(&mut s, "stroke.set", json!({"ids": [g.0], "join": "round"}));
assert_eq!(r["objects"], 1, "{r}");
let gs = node(&s, g).appearance.stroke().unwrap().clone();
assert_eq!((gs.join, gs.width, gs.paint.color().map(|c| c.to_hex())), (LineJoin::Round, 2.0, Some("#ffffff".to_string())));
for id in [a, b] {
assert!(node(&s, id).appearance.stroke().is_none(), "a member keeps no stroke");
}
// A group without a stroke of its own still reaches its members; for a join alone the row
// made on each has no paint, so nothing becomes visible.
let (c, d) = (rect(&mut s, 400.0), rect(&mut s, 550.0));
for id in [c, d] {
run(&mut s, "appearance.removeItem", json!({"ids": [id.0], "index": 1}));
}
let h = NodeId(run(&mut s, "object.group", json!({"ids": [c.0, d.0]}))["id"].as_u64().unwrap());
run(&mut s, "stroke.set", json!({"ids": [h.0], "join": "bevel"}));
for id in [c, d] {
let st = node(&s, id).appearance.stroke().cloned().expect("a stroke row for the join");
assert_eq!((st.paint, st.join), (Paint::None, LineJoin::Bevel), "no paint for a join alone");
}
// A weight is a visible stroke: an object without one gets the black stroke, as before.
let e = rect(&mut s, 700.0);
run(&mut s, "appearance.removeItem", json!({"ids": [e.0], "index": 1}));
run(&mut s, "stroke.set", json!({"ids": [e.0], "weight": 3}));
let st = node(&s, e).appearance.stroke().cloned().unwrap();
assert_eq!((st.paint, st.width), (Paint::solid(Color::BLACK), 3.0));
}
#[test]
fn text_items_take_item_paint() {
let mut s = session();