Merge pull request #1804 from AyberkA0/fix/1679-pencil-keeps-appearance

Fix #1679: a filled pencil path keeps a stroke of None
This commit is contained in:
BFlat 2026-10-14 04:25:57 +07:00 committed by GitHub
commit 951bf42714
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View File

@ -615,7 +615,10 @@ fn freehand(s: &mut Session, p: &Value) -> Result<Value> {
}
let sp = fit_freehand(&pts, tol, closed);
let fill = if bool_or(p, "fill", false) { s.paint.fill.clone() } else { Paint::None };
let mut look = s.new_art_look(fill, stroke_paint(s), s.paint.stroke_width.max(0.1));
// A pencil path with a fill keeps a stroke of None (#1679); only one that would show nothing
// gets black. A brush is its stroke.
let stroke = if brush || fill.is_none() { stroke_paint(s) } else { s.paint.stroke.clone() };
let mut look = s.new_art_look(fill, stroke, s.paint.stroke_width.max(0.1));
if let Some(st) = look.appearance.stroke_mut() {
st.pressure = pressure;
}

View File

@ -1235,3 +1235,21 @@ fn pen_with_alt_converts_the_anchors_of_a_path_in_a_selected_group() {
assert_eq!(paths(&s).len(), 1, "{wrap}: no new path");
}
}
/// #1679: a filled pencil path keeps a stroke of None; an unfilled one with no stroke gets black,
/// or it would show nothing.
#[test]
fn a_filled_pencil_path_keeps_no_stroke() {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
s.execute("select.none", &json!({})).unwrap();
s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap();
s.execute("paint.setStroke", &json!({"none": true})).unwrap();
let pts = json!([[10, 10], [60, 20], [90, 80], [20, 90]]);
let id = NodeId(s.execute("path.freehand", &json!({"points": pts, "fill": true})).unwrap()["id"].as_u64().unwrap());
let n = s.doc().unwrap().doc.node(id).unwrap().clone();
assert!(n.appearance.stroke_paint().is_none(), "{:?}", n.appearance);
assert!(!n.appearance.fill_paint().is_none());
let id = NodeId(s.execute("path.freehand", &json!({"points": pts})).unwrap()["id"].as_u64().unwrap());
assert!(!s.doc().unwrap().doc.node(id).unwrap().appearance.stroke_paint().is_none());
}