diff --git a/crates/ui-egui/src/panels/gradient.rs b/crates/ui-egui/src/panels/gradient.rs index 8f9d83a4b1..dab46642a2 100644 --- a/crates/ui-egui/src/panels/gradient.rs +++ b/crates/ui-egui/src/panels/gradient.rs @@ -489,8 +489,10 @@ enum PresetKey { /// The Presets picker: the preset gradients by library (theme), then the saved ones; a choice /// applies to the gradient behind the active proxy, keeping its placement -/// (`gradient.presets.apply`; a solid or no paint becomes the gradient). The picker shows the -/// preset the gradient is, if any. +/// (`gradient.presets.apply`; a solid or no paint becomes the gradient), as the panel's other +/// controls do: an active Appearance row takes the preset only when that row is a fill row with the +/// Fill proxy in front, or a stroke row with the Stroke proxy in front. +/// The picker shows the preset the gradient is, if any. fn presets_picker(app: &mut VectorcraftApp, ui: &mut Ui, g: Option<&GradientPaint>) { let shown = g.and_then(|g| app.session.gradient_preset_name(&g.gradient)).map(PresetKey::Preset); let enabled = crate::menus::enabled(app, "gradient.presets.apply"); @@ -502,7 +504,7 @@ fn presets_picker(app: &mut VectorcraftApp, ui: &mut Ui, g: Option<&GradientPain picked = PresetPicker::new(tl!("Presets"), Bind::given(shown.clone()), &source, Bind::kept()).show(ui).picked; }); if let Some(PresetKey::Preset(name)) = picked { - app.run("gradient.presets.apply", json!({ "name": name })).ok(); + app.run("gradient.presets.apply", json!({ "name": name, "stroke": !app.session.fill_active })).ok(); } } diff --git a/crates/ui-egui/src/panels/gradient/tests.rs b/crates/ui-egui/src/panels/gradient/tests.rs index 4324e20f49..16f99658bc 100644 --- a/crates/ui-egui/src/panels/gradient/tests.rs +++ b/crates/ui-egui/src/panels/gradient/tests.rs @@ -335,3 +335,82 @@ fn escape_ends_the_stop_eyedropper_and_returns_to_the_gradient_tool() { assert_eq!(current(&app), paint, "the stop keeps its color"); assert_eq!(app.session.active().unwrap().selection.objects, selected, "the selection stays"); } + +/// The paints of the selected object's appearance rows, in stack order. +fn row_paints(app: &VectorcraftApp) -> Vec { + let st = app.session.active().unwrap(); + let node = st.doc.node(st.selection.subjects()[0]).unwrap(); + node.appearance.items.iter().map(|i| i.paint().clone()).collect() +} + +/// The indices of the selected object's fill (`fill`) or stroke rows. +fn rows_of_kind(app: &VectorcraftApp, fill: bool) -> Vec { + let st = app.session.active().unwrap(); + let node = st.doc.node(st.selection.subjects()[0]).unwrap(); + node.appearance.items.iter().enumerate().filter(|(_, i)| i.is_fill() == fill).map(|(n, _)| n).collect() +} + +/// A selected rectangle with a gradient fill and a gradient stroke. +fn gradient_fill_and_stroke() -> VectorcraftApp { + let mut app = app(json!({"gradient": {}})); + app.run("paint.setStroke", json!({"gradient": {}, "focus": false})).unwrap(); + app +} + +/// With appearance row `active` active and the Fill (`front_fill`) or Stroke proxy in front, +/// chooses Soft Spectrum from the Presets picker and checks that row `target` takes the preset +/// while every other row keeps its paint. +fn assert_preset_goes_to(mut app: VectorcraftApp, active: usize, front_fill: bool, target: usize) { + let soft = app.session.gradient_preset("Soft Spectrum").unwrap().gradient.stops; + app.run("appearance.setActiveItem", json!({ "index": active })).unwrap(); + app.session.fill_active = front_fill; + let before = row_paints(&app); + let mut rig = Rig::new(app); + assert_eq!(rig.app().session.appearance_item(), Some(active), "the row stays active"); + rig.click("Presets"); + rig.click("Soft Spectrum"); + let after = row_paints(&rig.app()); + assert_eq!(after.len(), before.len()); + for (n, (was, now)) in before.iter().zip(&after).enumerate() { + if n == target { + assert!(matches!(now, Paint::Gradient(g) if g.gradient.stops == soft), "row {n} takes the preset: {now:?}"); + } else { + assert_eq!(now, was, "row {n} keeps its paint"); + } + } +} + +/// With a fill row active and the Stroke proxy in front, the Presets picker applies the preset to +/// the stroke. +#[test] +fn the_presets_menu_applies_to_the_stroke_in_front_over_an_active_fill_row() { + let app = gradient_fill_and_stroke(); + let (fill_row, stroke_row) = (rows_of_kind(&app, true)[0], rows_of_kind(&app, false)[0]); + assert_preset_goes_to(app, fill_row, false, stroke_row); +} + +/// With a stroke row active and the Fill proxy in front, the Presets picker applies the preset to +/// the fill. +#[test] +fn the_presets_menu_applies_to_the_fill_in_front_over_an_active_stroke_row() { + let app = gradient_fill_and_stroke(); + let (fill_row, stroke_row) = (rows_of_kind(&app, true)[0], rows_of_kind(&app, false)[0]); + assert_preset_goes_to(app, stroke_row, true, fill_row); +} + +/// With the proxy of the active row's kind in front, the Presets picker applies the preset to the +/// active row, not to the topmost row of that kind. +#[test] +fn the_presets_menu_applies_to_the_active_row_of_the_kind_in_front() { + for fill in [true, false] { + let mut app = gradient_fill_and_stroke(); + app.run(if fill { "appearance.addFill" } else { "appearance.addStroke" }, json!({})).unwrap(); + // Without an active row a solid goes to the topmost row of the kind; the other stays a gradient. + app.run(if fill { "paint.setFill" } else { "paint.setStroke" }, json!({"color": "#ff0000", "focus": false})).unwrap(); + let paints = row_paints(&app); + let rows = rows_of_kind(&app, fill); + assert_eq!(rows.len(), 2); + let lower = rows.into_iter().find(|&n| matches!(paints[n], Paint::Gradient(_))).expect("a gradient row under the solid one"); + assert_preset_goes_to(app, lower, fill, lower); + } +} diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 9c2b0a284d..faa089d8ab 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2101,6 +2101,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur Escape ends that eyedropper's pick, and Brush Options' Key Color pick, without sampling and returns to the tool that started it; the stop keeps its color, and Brush Options stays open with its Key Color until a new Escape cancels it (#8024, [Modify gradients, archived user guide](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=264)). Cmd/Ctrl-click on the Gradient panel's Gradient Fill box or on the Tools panel's Gradient button resets the gradient of the active Fill or Stroke to the linear White, Black gradient, as one undo step ([Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html)). With a gradient stop or a freeform gradient point selected, Alt-clicking a color swatch in the Swatches panel recolors it instead of the inactive Fill or Stroke. + The Gradient panel's Presets menu applies the chosen preset to the fill or stroke behind the proxy in front, as the panel's other controls do. The help page describes a Fill or Stroke control on the Gradient panel that toggles whether the fill or the stroke is being edited ([Gradient panel options](https://web.archive.org/web/20251006210616/https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-gradients/gradient-tool-and-panel.html)). As VectorCraft's own rule, an active Appearance panel row takes the preset only when it is a fill row and the Fill proxy is in front, or a stroke row and the Stroke proxy is in front (`panels::gradient` tests `the_presets_menu_applies_to_the_stroke_in_front_over_an_active_fill_row`, `the_presets_menu_applies_to_the_fill_in_front_over_an_active_stroke_row` and `the_presets_menu_applies_to_the_active_row_of_the_kind_in_front`). In the Gradient tool's freeform Lines mode, moving the pointer out of the object and back ends the line being drawn, and the next click on the object starts a new line from the point it adds. The help page describes this way of starting another line segment in the same object ([Create freeform gradient in lines mode](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=262)). As VectorCraft's own rules, the line ends as soon as the pointer, with no button held, moves off the object's own art, its fill, stroke or glyphs (other art lying over the object still counts as inside), and Escape and a click off the art still end it as before (`xform::freeform::tests::leaving_the_object_ends_the_line`). - **Freeform gradient colors in their own model:** Object ▸ Expand and Object ▸ Create Gradient Mesh (`object.mesh.create`) mix a freeform gradient's points in the color model they share: points of C50 M20 Y0 K10 give mesh points of C50 M20 Y0 K10, and RGB points keep their values in a working RGB space other than sRGB. The canvas, the gradient chips and the SVG, PDF, EPS and EMF writers mix the points in that model too. PDF and EPS write a gradient whose points are all CMYK, or all Gray in a CMYK file, as a CMYK image, which PDF's Output settings convert as they convert any CMYK image. Points in different models mix in display RGB (on the canvas in a CMYK document that shows transparency, as the inks of each point), and a CMYK document stores the result of Expand as CMYK through the color settings. Points colored along CMYK stops (`paint.editGradient {stops}`, or a CMYK gradient switched to freeform) are CMYK, and so are a point `paint.freeform.splitLine` adds between CMYK points and a point `paint.freeform.addPoint` adds without `color` to CMYK points. Public reference: [Gradients](https://web.archive.org/web/20250714042311/https://helpx.adobe.com/illustrator/using/gradients.html) and [Meshes](https://web.archive.org/web/20250812201019/https://helpx.adobe.com/illustrator/using/meshes.html), which do not state how colors in different models mix; the rule is VectorCraft's own. - **Strokes:** one stroke-geometry module shared by the canvas, SVG, PDF and Outline Stroke; dotted lines (zero-length dashes draw dots or squares); arrowheads with hollow outlines, tip-on-end or extend-past-end alignment and one opacity for line and head. SVG and PDF export arrowheads, width profiles, brushes and aligned strokes exactly as the canvas draws them; Outline Stroke and the live Outline Stroke effect outline every stroke item as drawn (dashes, heads, profiles, alignment); dashes can be fitted to corners and path ends; width profiles carry through dashes, and their corners take the join. The Stroke panel edits type's character strokes, follows the stroke units (its weight presets are round values in that unit: `0.25 mm`, `0.0625 in`, `1 px`, #426; fields show four decimals in mm, cm and inches, three in points), shows mixed values blank and opens from the Control bar. A width profile library, thirty-one more arrowheads (among them Line Arrow: two arms of the head's weight (stroke weight × arrowhead scale, at least 0.25 pt: the line's weight at 100 % for lines of 0.25 pt or more) at right angles, cut square, #5421), and Width Point Edit with multi-select and discontinuous points. Visual bounds and clicks cover the whole painted stroke. Scale Strokes & Effects, Scale Corners and Use Preview Bounds work everywhere, and new art inherits stroke options, a graphic style or the whole last appearance. A width profile's sides run as a smooth C1 curve between the width points (a monotone cubic Hermite, Fritsch–Carlson, with each end's own span slope and flat either side of a step), sampled adaptively along the path (two samples per profile segment, refined until the line between samples stays within the outline tolerance, and reusing a segment's own flattened points only where they already follow the curve) so straight runs draw it too; added samples offset along the source curve's exact tangent, not the flattened chord, so high zoom follows the true width; the sampled edges are fitted with G1 cubics within the flattening tolerance (0.01 pt) rather than one cubic per flatten step, so a profiled outline draws the same shape as a uniform one and exports stay close to its path data; a point reshapes the curve as far as its neighbours' neighbours (their slopes depend on it), and coincident points still step.