Merge pull request #5439 from Taha-Mahmoodi/fix/outline-stroke-context-menu

Fix #5267: Outline Stroke is in the canvas context menu
This commit is contained in:
FredApps
2026-11-27 23:28:10 +01:00
committed by GitHub
8 changed files with 284 additions and 6 deletions
+6 -2
View File
@@ -960,8 +960,12 @@ fn shared_selection(selection: vectorcraft_doc::Selection, like: Option<&crate::
/// instance as it is. Copy copies the instance whole ([`copy_cut_targets`]).
pub(crate) fn selected_roots(s: &Session) -> Result<Vec<NodeId>> {
refuse_symbol_part(s)?;
let st = s.doc()?;
Ok(roots_of(&st.doc, st.selection.in_paint_order(&st.doc)))
Ok(selection_roots(s.doc()?))
}
/// [`selected_roots`] of one document's selection.
pub(crate) fn selection_roots(st: &crate::DocState) -> Vec<NodeId> {
roots_of(&st.doc, st.selection.in_paint_order(&st.doc))
}
/// [`super::brushsym::part_only`] while an object of a dynamic symbol instance's art is selected:
+54 -1
View File
@@ -13,7 +13,7 @@ use vectorcraft_geom::{FillRule, PathData, SubPath};
use vectorcraft_pathops as po;
use vectorcraft_pathops::{BoolOp, PathfinderOp};
use super::edit::selected_roots;
use super::edit::{selected_roots, selection_roots};
use super::expand::{fill_shape, reshaped, seeded};
use super::{
CommandSpec, EngineError, Result, Session, always, bad, check_switches, checked_ids_or_selection, cmd, has_doc, has_selected_path, has_selection,
@@ -1147,6 +1147,59 @@ pub(crate) fn outlinable(st: &StrokeLayer) -> bool {
st.visible && !st.paint.is_none() && st.width > 0.0
}
/// Whether any segment can paint a butt-capped stroke. Check only used control points:
/// coincident endpoints can still describe a curve, but unused open-end handles cannot.
fn may_paint_butt_stroke(n: &Node) -> bool {
match &n.kind {
NodeKind::Path { path, .. } => path.subpaths.iter().any(|sp| {
(0..sp.segment_count()).any(|i| {
let c = sp.segment(i);
c.p0 != c.p3 || c.p0 != c.p1 || c.p0 != c.p2
})
}),
NodeKind::Compound { children, .. } => children.iter().any(|c| may_paint_butt_stroke(c)),
_ => false,
}
}
/// Does Outline Stroke have a stroke to turn into art under `n`, outside the dimension subtrees
/// the command will keep? Guides, clipping paths and type are not outlined.
fn has_outlinable_stroke(n: &Node, kept: &[NodeId]) -> bool {
if kept.contains(&n.id) {
return false;
}
match &n.kind {
NodeKind::Path { guide: true, .. } | NodeKind::Path { clipping: true, .. } => false,
NodeKind::Path { .. } | NodeKind::Compound { .. } => {
let geometry = std::cell::LazyCell::new(|| may_paint_butt_stroke(n));
n.appearance.items.iter().any(|i| {
let AppearanceItem::Stroke(st) = i else { return false };
// Brushes, arrowheads, profiles and geometry effects can make a point paint.
outlinable(st)
&& (st.cap != vectorcraft_doc::LineCap::Butt
|| st.brush.is_some()
|| st.start_arrow.is_some()
|| st.end_arrow.is_some()
|| st.profile.is_some()
|| vectorcraft_render::effects::has_geometry(&n.appearance.effects)
|| vectorcraft_render::effects::has_geometry(&st.effects)
|| *geometry)
})
}
NodeKind::Group { children, .. } | NodeKind::Layer { children, .. } => children.iter().any(|c| has_outlinable_stroke(c, kept)),
_ => false,
}
}
/// Does `object.path.outlineStroke` have a stroke to outline in `st`'s selection? It acts on the
/// selection's roots (a compound path's member stands for its compound, which holds the
/// appearance), excluding the linked dimensions that the command lifts while outlining their art.
pub fn can_outline_stroke(st: &crate::DocState) -> bool {
let roots = selection_roots(st);
let kept = super::dimension::with_their_art(&st.doc, &roots);
roots.into_iter().filter_map(|id| st.doc.node(id)).any(|n| has_outlinable_stroke(n, &kept))
}
/// `n` with `opacity` and `blend` applied: set on it when it has none of its own, else on a
/// group around it.
pub(crate) fn with_transparency(d: &mut Document, mut n: Node, opacity: f32, blend: BlendMode) -> Node {
+1 -1
View File
@@ -33,7 +33,7 @@ pub use cmd::flare::flare_settings;
pub use cmd::gradient::{GradientEditPaints, StopOwner};
pub use cmd::graph::{GraphTypeSubject, calculated_axes as graph_calculated_axes, graph_type_subject};
pub use cmd::params::{check_keys, check_params};
pub use cmd::pathops::auto_simplify_level;
pub use cmd::pathops::{auto_simplify_level, can_outline_stroke};
pub use cmd::rasterfx::{export_pdf, flatten_raster_effects};
pub use cmd::select::{path_fingerprint, storable_selection, stored_path_params, stored_path_step};
pub use cmd::textwrap::TEXT_WRAP_OFFSET_RANGE;
+4
View File
@@ -88,6 +88,10 @@ pub fn context_items(app: &VectorcraftApp) -> Vec<Node> {
if paths {
v.extend([c("Join", "path.join"), c("Average…", "path.average")]);
}
// Outline Stroke turns strokes into filled art: offered when the command has a stroke to outline in its roots.
if vectorcraft_engine::can_outline_stroke(st) {
v.push(c("Outline Stroke", "object.path.outlineStroke"));
}
if !st.selection.anchors.is_empty() {
v.extend([c("Remove Anchor Points", "path.removeAnchors"), c("Cut Path at Selected Anchor Points", "path.cutAtAnchors")]);
}
+208
View File
@@ -627,6 +627,214 @@ fn every_context_label_is_a_menu_string() {
}
}
/// A canvas in the same fixture and command lifecycle as a window.
struct CanvasMenu {
app: std::rc::Rc<std::cell::RefCell<VectorcraftApp>>,
fixture: craft::ui::testing::Fixture,
}
impl CanvasMenu {
fn new(app: VectorcraftApp) -> Self {
let app = std::rc::Rc::new(std::cell::RefCell::new(app));
let shown = std::rc::Rc::clone(&app);
let mut fixture = craft::ui::testing::Fixture::new(move |ui| canvas::show(&mut shown.borrow_mut(), ui));
fixture.room(vec2(800.0, 600.0));
app.borrow_mut().ui_ctx = Some(fixture.ctx().clone());
let mut canvas = Self { app, fixture };
canvas.frame(vec![]);
canvas
}
fn frame(&mut self, events: Vec<Event>) {
crate::testing::fixture_input(&mut self.app.borrow_mut(), &mut self.fixture);
self.fixture.frame(events);
crate::testing::fixture_input(&mut self.app.borrow_mut(), &mut self.fixture);
}
fn right_click(&mut self, x: f64, y: f64) {
let p = screen(&self.app.borrow(), x, y);
self.frame(vec![Event::PointerMoved(p)]);
self.frame(vec![press(p, PointerButton::Secondary, true)]);
self.frame(vec![press(p, PointerButton::Secondary, false)]);
self.frame(vec![]);
assert!(self.app.borrow().ui.context_menu_at.is_some(), "the menu opened");
}
fn outline_item(&self) -> Option<craft::ui::testing::Target> {
let app = self.app.borrow();
let entry = menus::menu_entries(&app).into_iter().find(|e| e.command.as_deref() == Some("object.path.outlineStroke")).unwrap();
let label = menus::shown_label(&app, entry.command.as_deref().unwrap(), &entry.params, &entry.label);
let tree = self.fixture.tree();
self.fixture.by_role(craft::ui::contract::Role::MENU_ITEM).into_iter().find(|item| tree.name_of(item.node) == Some(label.as_str()))
}
fn click_outline(&mut self) {
let item = self.outline_item().expect("the rendered outline item is present");
assert!(!self.fixture.tree().is_disabled_key(item.node), "the rendered outline item is enabled");
self.fixture.click(&item);
crate::testing::fixture_input(&mut self.app.borrow_mut(), &mut self.fixture);
self.frame(vec![]);
}
fn escape(&mut self) {
self.frame(vec![Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }]);
}
}
/// #5267: a right-click on a stroked object offers Outline Stroke, which runs
/// `object.path.outlineStroke` (the Object › Path item) and leaves filled art; an object with no
/// stroke to outline has no such item.
#[test]
fn the_canvas_context_menu_offers_outline_stroke_for_a_stroked_selection() {
use vectorcraft_doc::AppearanceItem;
let mut app = app();
let id = rect(&mut app, 50.0, 50.0);
// Stroked: a visible stroke of some weight.
app.run("stroke.set", json!({"weight": 6})).unwrap();
let strokes = |app: &VectorcraftApp| {
let st = app.session.active().unwrap();
let n = st.doc.node(st.selection.objects[0]).unwrap();
n.appearance.items.iter().filter(|i| matches!(i, AppearanceItem::Stroke(s) if s.visible && !s.paint.is_none() && s.width > 0.0)).count()
};
assert!(strokes(&app) > 0, "the rectangle starts with a stroke");
app.run("select.none", json!({})).unwrap();
let mut canvas = CanvasMenu::new(app);
canvas.right_click(100.0, 100.0);
canvas.click_outline();
{
let app = canvas.app.borrow();
let st = app.session.active().unwrap();
assert!(st.doc.node(id).is_none(), "the stroked rectangle was replaced by its outline");
assert_eq!(strokes(&app), 0, "the outline is filled art with no stroke left");
}
// The outline has no stroke any more: nothing to outline, so no item.
canvas.right_click(100.0, 100.0);
assert!(canvas.outline_item().is_none(), "no stroke, no rendered outline item");
}
#[test]
fn outline_stroke_menu_ignores_a_point_with_a_nonpainting_cap() {
for (cap, closed) in [("butt", false), ("round", false), ("square", false), ("butt", true), ("round", true), ("square", true)] {
let mut app = app();
let point = NodeId(
app.run("path.create", json!({"closed": closed, "anchors": [{"x": 250, "y": 200}, {"x": 250, "y": 200}]})).unwrap()["id"]
.as_u64()
.unwrap(),
);
app.run("paint.setFill", json!({"none": true})).unwrap();
app.run("paint.setStroke", json!({"color": "#000000"})).unwrap();
app.run("stroke.set", json!({"weight": 8, "cap": cap})).unwrap();
let visible = rect(&mut app, 50.0, 50.0);
app.run("paint.setFill", json!({"color": "#ff8010"})).unwrap();
app.run("paint.setStroke", json!({"none": true})).unwrap();
app.run("select.set", json!({"ids": [point.0, visible.0]})).unwrap();
let selected = app.session.active().unwrap().selection.objects.clone();
let mut canvas = CanvasMenu::new(app);
canvas.right_click(100.0, 100.0);
assert_eq!(canvas.app.borrow().session.active().unwrap().selection.objects, selected);
if cap == "butt" {
assert!(canvas.outline_item().is_none(), "the point paints nothing with a butt cap");
} else {
canvas.click_outline();
let app = canvas.app.borrow();
let st = app.session.active().unwrap();
assert!(st.doc.node(point).is_none(), "{cap} cap was outlined");
assert!(st.doc.node(visible).is_some(), "the fill-only object is unchanged");
let outlined = st.selection.objects.iter().find(|&&id| id != visible).and_then(|&id| st.doc.node(id)).expect("selected outline art");
assert!(
outlined.appearance.items.iter().any(|i| matches!(i, vectorcraft_doc::AppearanceItem::Fill(f) if f.visible && !f.paint.is_none())),
"{cap} cap becomes filled art"
);
let bounds = outlined.geometric_bounds().expect("the cap outline has geometry");
assert!(bounds.width() > 0.0 && bounds.height() > 0.0, "{cap} cap paints an area");
}
}
}
/// A compound path of two rectangles, filled and stroked with `weight`, isolated, with a member
/// right-clicked. The member stays selected and has no appearance of its own: the compound holds
/// the paint.
fn right_click_member_of_compound(weight: f64) -> (CanvasMenu, NodeId) {
let mut app = app();
let (a, b) = (rect(&mut app, 50.0, 50.0), rect(&mut app, 200.0, 50.0));
app.run("select.set", json!({"ids": [a.0, b.0]})).unwrap();
app.run("object.compoundPath.make", json!({})).unwrap();
let compound = app.session.active().unwrap().selection.objects[0];
// Filled, so that a click inside a member hits it whether or not the compound has a stroke.
app.run("paint.setFill", json!({"color": "#ff8010"})).unwrap();
app.run("stroke.set", json!({"weight": weight})).unwrap();
app.run("object.isolate", json!({"id": compound.0})).unwrap();
let member = app.session.active().unwrap().doc.node(compound).and_then(|n| n.children().and_then(|c| c.first()).map(|m| m.id)).unwrap();
app.run("select.set", json!({"ids": [member.0]})).unwrap();
let mut canvas = CanvasMenu::new(app);
canvas.right_click(100.0, 100.0);
{
let app = canvas.app.borrow();
let st = app.session.active().unwrap();
assert_eq!(st.selection.objects, [member], "the right-click leaves the member selected");
assert!(st.doc.node(member).is_some_and(|m| m.appearance.items.is_empty()), "a member has no appearance of its own");
}
(canvas, compound)
}
/// With a member of an isolated compound path selected (a right-click inside the isolated compound
/// leaves a member selected), the member's own appearance is empty: the compound holds the paint.
/// `object.path.outlineStroke` promotes the member to its compound, so the menu offers Outline
/// Stroke exactly when the compound has a stroke to outline.
#[test]
fn outline_stroke_is_offered_for_a_member_of_a_stroked_compound_path() {
// No stroke on the compound path: nothing to outline.
let (canvas, _) = right_click_member_of_compound(0.0);
assert!(canvas.outline_item().is_none(), "no stroke, no rendered outline item");
// Stroked: the item is offered for the member, and the command outlines the compound.
let (mut canvas, compound) = right_click_member_of_compound(6.0);
canvas.click_outline();
assert!(canvas.app.borrow().session.active().unwrap().doc.node(compound).is_none(), "the stroked compound path was replaced by its outline");
}
#[test]
fn outline_stroke_ignores_a_linked_dimensions_lines_when_its_source_is_selected() {
for grouped in [false, true] {
let mut app = app();
let source = rect(&mut app, 50.0, 50.0);
app.run("paint.setFill", json!({"color": "#ff8010"})).unwrap();
app.run("paint.setStroke", json!({"none": true})).unwrap();
let dimension =
NodeId(
app.run("dimension.create", json!({"source": {"kind": "segment", "edge": {"node": source.0, "subpath": 0, "segment": 0}}})).unwrap()
["id"]
.as_u64()
.unwrap(),
);
app.run("select.set", json!({"ids": [source.0, dimension.0]})).unwrap();
if grouped {
app.run("object.group", json!({})).unwrap();
}
let selected = app.session.active().unwrap().selection.objects.clone();
let mut canvas = CanvasMenu::new(app);
canvas.right_click(100.0, 125.0);
assert_eq!(canvas.app.borrow().session.active().unwrap().selection.objects, selected, "grouped: {grouped}");
assert!(canvas.outline_item().is_none(), "only the protected dimension has strokes");
canvas.escape();
let dimension_art = {
let mut app = canvas.app.borrow_mut();
app.run("paint.setStroke", json!({"ids": [source.0], "color": "#000000"})).unwrap();
app.run("stroke.set", json!({"ids": [source.0], "weight": 6})).unwrap();
app.session.active().unwrap().doc.node(dimension).unwrap().children().unwrap().to_vec()
};
canvas.right_click(100.0, 125.0);
assert_eq!(canvas.app.borrow().session.active().unwrap().selection.objects, selected, "grouped: {grouped}");
canvas.click_outline();
let app = canvas.app.borrow();
let st = app.session.active().unwrap();
assert!(st.doc.node(source).is_none(), "the source was replaced by filled outlines");
assert_eq!(st.doc.node(dimension).unwrap().children().unwrap(), dimension_art.as_slice(), "the dimension keeps its own art");
}
}
/// Point type holding `t` at (20, 60), with Auto Spell Check on.
fn spelled(app: &mut VectorcraftApp, t: &str) -> NodeId {
let id = NodeId(app.run("text.create", json!({"x": 20, "y": 60, "text": t, "size": 24})).unwrap()["id"].as_u64().unwrap());
+3
View File
@@ -7,6 +7,8 @@
> Selection update (2026-11-11): path and compound-path interiors follow enabled non-None fill rows, including lower fills beneath a top None row (#6625). Hidden-only interiors miss; zero-opacity fills remain selectable. Cap/join follow-up (2026-11-12): hidden-fill and no-fill stroke hits must respect cap and join geometry; focused cap/join CPU regressions passed. Scores and estimates unchanged.
> Blend redraw update (#5179; previously: Keyboard Shortcuts: user-bindable Switch Selection Tools (#7645), with no default key; scores and estimates unchanged): renderer bounds include spine-placed keys and steps; both focused CPU regressions pass. Scores and estimates unchanged.
> Outline Stroke is available in the canvas context menu when the selection has an outlinable stroke (#5267). Scores and estimates unchanged.
> **File-font hardening status (2026-11-12, #4569):** G8 implementation and synthetic regressions added; compilation and runtime proof pending. Scores and estimates unchanged.
@@ -1058,6 +1060,7 @@ trap, and the defaults (0.25 pt, 100%, 40%) are VectorCraft's own, the pages giv
| 2026-11-07 | minor | G4: the Glyphs panel's Alternates for Current Selection applies the OpenType feature that draws a variant to that letter alone (`salt=2`; the style commands take `tag=N`; runs that differ only in their features shape as one piece of text), so an Arabic word stays joined, and Show › Entire Font lists the unencoded glyphs (#5514). Estimate unchanged. |
| 2026-11-12 | minor | G11: numeric fields keep the caret when a focus click is released more than 1 pt from its press; a tap within 1 pt still selects the whole value (#6659, follow-up to #1326); short-drag and jitter-tap regressions in `tests/numfields.rs`; estimates unchanged. |
| 2026-11-03 | minor | An imported document's own title (an SVG's root `<title>`, a PDF's XMP `dc:title` else its Info `Title`) goes into File Info only; the document's name stays the file's name (#3626); no scored gap or estimate reassessed. |
| 2026-11-03 | minor | The canvas context menu offers Outline Stroke for a stroked selection (#5267); no entry closed, estimates unchanged. |
| 2026-11-11 | minor | Eyedropper copies effective character dimensions between transformed text objects (#6404); scores and estimates unchanged. |
| 2026-11-11 | minor | Ordinary Save to a location refusing writes offers Save As (#6146); cancellation preserves the original path and modified state; automation receives READ_ONLY_LOCATION. Scores and estimates unchanged. Validation pending. |
| 2026-11-11 | minor | G5: built-in Energy Beams brush library (Laser Bolt, Plasma Arc, Charge Wave, Spark Trail); Missing trimmed; estimate 5–15 → 4–14 h; MCP Brush libraries list Energy Beams. |
File diff suppressed because one or more lines are too long
+4 -1
View File
File diff suppressed because one or more lines are too long