From ccc263e49e628ab8e26ccf6a86011ea8c76feb17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hartmut=20N=C3=B6renberg?= Date: Sat, 7 Nov 2026 07:22:59 +0100 Subject: [PATCH] fix(paint): Pressure for Size starts off, as the reference does BrushSettings::default() turned Pressure for Size on, so a fresh brush - and the brush Reset Tool hands back, which is that default plus Photoshop's 10 % smoothing - reported pressureSize: true from brush.get and drew the options bar's "Always use pressure for size" button highlighted, while the reference application leaves both pressure toggles off after Reset Tool. Neither is on now. The toggle itself is untouched: it still switches both ways, Shape Dynamics' Pen Pressure control is unaffected, and path.stroke's Simulate Pressure still tapers a brush that follows pen pressure. A brush JSON that omits pressureSize now reads as off, as the reference's default is. Two engine tests took their expectation from the old default and set pressureSize explicitly instead: cmd::brush_cmds::tests::stroke_backwards_compatible and cmd::vector_cmds::tests::stroke_path_simulate_pressure_tapers_both_ends. The new crates/engine/src/brush_pressure_size_default_tests.rs covers the default, brush.get on a fresh session, an omitted field, switching the toggle, and that a pressure ramp with the default brush paints like pressureSize: false. Fixes #11809 --- .../src/brush_pressure_size_default_tests.rs | 87 +++++++++++++++++++ crates/engine/src/cmd/brush_cmds/tests.rs | 5 +- crates/engine/src/cmd/vector_cmds/tests.rs | 3 + crates/engine/src/lib.rs | 2 + crates/paint/src/brush.rs | 3 +- crates/ui-egui/src/panels/brush_preview.rs | 4 +- 6 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 crates/engine/src/brush_pressure_size_default_tests.rs diff --git a/crates/engine/src/brush_pressure_size_default_tests.rs b/crates/engine/src/brush_pressure_size_default_tests.rs new file mode 100644 index 0000000000..c09fe26313 --- /dev/null +++ b/crates/engine/src/brush_pressure_size_default_tests.rs @@ -0,0 +1,87 @@ +//! Pressure for Size starts off (#11809). The reference application leaves both pressure toggles +//! in the options bar unhighlighted after Reset Tool, so a fresh brush has neither on — and the +//! brush Reset Tool hands back is `BrushSettings::default()` plus smoothing +//! (`crates/ui-egui/src/canvas/paint_mouse.rs::fresh_brush`), so the default is what the tool +//! reset reports through `brush.get`. The options bar's two `circle-dot` buttons are drawn from +//! these same two fields (`crates/ui-egui/src/panels/options_bar.rs`), so off here means drawn +//! off there. + +use crate::Session; +use photocraft_paint::brush::BrushSettings; +use serde_json::{Value, json}; + +/// The brush a fresh session starts with: neither pressure toggle on. +#[test] +fn the_default_brush_has_neither_pressure_toggle_on() { + let b = BrushSettings::default(); + assert!(!b.pressure_size, "Pressure for Size is off by default, as the reference leaves it after Reset Tool (#11809)"); + assert!(!b.pressure_opacity, "Pressure for Opacity stays off"); +} + +/// What `brush.get` answers on a fresh session, which is what the options bar reads to draw the +/// two toggles. +#[test] +fn brush_get_reports_both_pressure_toggles_off() { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); + let got = s.execute("brush.get", json!({})).unwrap(); + assert_eq!(got["pressureSize"], json!(false), "brush.get reports Pressure for Size off (#11809)"); + assert_eq!(got["pressureOpacity"], json!(false), "brush.get reports Pressure for Opacity off"); + // The session's own starting brush is the default brush at Photoshop's 10 % smoothing — the + // same brush Reset Tool hands back — so only the smoothing differs. + assert_eq!( + s.tools.brush, + BrushSettings { smoothing: photocraft_paint::brush::Smoothing { amount: 0.1, ..Default::default() }, ..BrushSettings::default() } + ); +} + +/// A brush that does not name the field — a preset saved before #11809, an older recorded +/// command — takes the off default rather than the old on one. +#[test] +fn a_brush_that_omits_the_field_takes_the_off_default() { + let b: BrushSettings = serde_json::from_value(json!({"size": 30.0, "hardness": 1.0})).unwrap(); + assert!(!b.pressure_size, "an omitted pressureSize reads as off (#11809)"); + assert!(!b.pressure_opacity, "an omitted pressureOpacity reads as off"); + assert_eq!(b.size, 30.0, "the fields that are there still apply"); +} + +/// Switching it on still works: `tools.setBrush` writes the field `brush.get` reads back, and the +/// same field the options-bar button is drawn from. +#[test] +fn pressure_for_size_still_switches_on_and_off() { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); + s.execute("tools.setBrush", json!({"brush": {"pressureSize": true}})).unwrap(); + assert!(s.tools.brush.pressure_size, "the toggle still turns on"); + assert_eq!(s.execute("brush.get", json!({})).unwrap()["pressureSize"], json!(true)); + s.execute("tools.setBrush", json!({"brush": {"pressureSize": false}})).unwrap(); + assert!(!s.tools.brush.pressure_size, "and off again"); + assert!(!s.tools.brush.pressure_opacity, "it never touches Pressure for Opacity"); +} + +/// One stroke of a pressure ramp (0.3 → 0.65 → 1.0) across a new empty layer with `brush`: the +/// layer's pixels and what the stroke covers. +fn ramp(brush: Value) -> (Vec, photocraft_geom::Rect) { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 80, "height": 40})).unwrap(); + s.execute("layer.new.layer", json!({})).unwrap(); + s.execute("paint.stroke", json!({"points": [[20.0, 20.0, 0.3], [40.0, 20.0, 0.65], [60.0, 20.0, 1.0]], "size": 24.0, "color": "#ff0000", "brush": brush})) + .unwrap(); + let st = s.active().unwrap(); + let surf = st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap(); + (surf.read_region(st.doc.bounds()), surf.content_bounds()) +} + +/// Done when 2: a pen stroke with varying pressure and the default brush keeps a constant size, +/// so it paints exactly what the same stroke with Pressure for Size turned off does — and +/// something else with it turned on, which is what makes this say anything. +#[test] +fn a_default_brush_stroke_keeps_its_size_under_a_pressure_ramp() { + let (off, off_box) = ramp(json!({"spacing": 0.25, "pressureSize": false})); + let (on, on_box) = ramp(json!({"spacing": 0.25, "pressureSize": true})); + let (dflt, dflt_box) = ramp(json!({"spacing": 0.25})); + assert_ne!(on, off, "the ramp alone does not change the stroke: Pressure for Size has to"); + assert_eq!(dflt, off, "the default brush paints like Pressure for Size off (#11809)"); + assert_eq!(dflt_box, off_box, "and reaches as far under the whole ramp"); + assert_ne!(dflt_box, on_box, "the turned-on brush still tapers the stroke's ends"); +} diff --git a/crates/engine/src/cmd/brush_cmds/tests.rs b/crates/engine/src/cmd/brush_cmds/tests.rs index c29d4c3146..f72a0e207b 100644 --- a/crates/engine/src/cmd/brush_cmds/tests.rs +++ b/crates/engine/src/cmd/brush_cmds/tests.rs @@ -26,8 +26,9 @@ fn stroke_backwards_compatible() { assert_eq!(r["damage"].as_array().unwrap().len(), 4); assert_eq!(rgba(&s, 30, 20), [0.0, 0.0, 1.0, 1.0]); assert_eq!(rgba(&s, 30, 30)[3], 0.0); - // [x, y, pressure] with the default pressure-size brush: light pressure → thinner line. - s.execute("paint.stroke", json!({"points": [[4, 5, 0.2], [60, 5, 0.2]], "size": 10})).unwrap(); + // [x, y, pressure] with Pressure for Size on: light pressure → a thinner line. The default + // brush has it off since #11809, so this stroke asks for it. + s.execute("paint.stroke", json!({"points": [[4, 5, 0.2], [60, 5, 0.2]], "size": 10, "brush": {"pressureSize": true}})).unwrap(); assert!(rgba(&s, 30, 5)[3] > 0.9 && rgba(&s, 30, 8)[3] < 0.01); } diff --git a/crates/engine/src/cmd/vector_cmds/tests.rs b/crates/engine/src/cmd/vector_cmds/tests.rs index 47394823d6..5a44943345 100644 --- a/crates/engine/src/cmd/vector_cmds/tests.rs +++ b/crates/engine/src/cmd/vector_cmds/tests.rs @@ -653,6 +653,9 @@ fn stroke_path_simulate_pressure_tapers_both_ends() { let coverage = |simulate: bool, x: i32| -> usize { let mut s = session(200, 60, 8); s.execute("layer.new.layer", json!({})).unwrap(); + // Simulate Pressure tapers a brush that follows pen pressure; the default brush stopped + // doing that on its own (#11809). + s.execute("tools.setBrush", json!({"brush": {"pressureSize": true}})).unwrap(); s.execute("path.set", json!({"path": {"subpaths": [{"closed": false, "knots": [[20, 30], [180, 30]]}]}})).unwrap(); let p = json!({"tool": "brush", "size": 20, "hardness": 1.0, "color": "#000000", "opacity": 100, "simulatePressure": simulate}); s.execute("path.stroke", p).unwrap(); diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 468efec851..b66eaa15dd 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -332,6 +332,8 @@ pub struct Session { pub damage_misses: usize, } +#[cfg(test)] +mod brush_pressure_size_default_tests; #[cfg(test)] mod embed_all_linked_tests; #[cfg(test)] diff --git a/crates/paint/src/brush.rs b/crates/paint/src/brush.rs index e43da363c5..a4de8a0c85 100644 --- a/crates/paint/src/brush.rs +++ b/crates/paint/src/brush.rs @@ -630,7 +630,8 @@ impl Default for BrushSettings { spacing_enabled: true, opacity: 1.0, flow: 1.0, - pressure_size: true, + // Off, as the reference application leaves it after Reset Tool (#11809). + pressure_size: false, pressure_opacity: false, color: [0.0, 0.0, 0.0, 1.0], color_cmyk: None, diff --git a/crates/ui-egui/src/panels/brush_preview.rs b/crates/ui-egui/src/panels/brush_preview.rs index f77975d45c..ba345d51e7 100644 --- a/crates/ui-egui/src/panels/brush_preview.rs +++ b/crates/ui-egui/src/panels/brush_preview.rs @@ -296,7 +296,9 @@ mod tests { #[test] fn preview_draws_a_stroke_that_fits() { - let mut b = BrushSettings { size: 400.0, ..Default::default() }; + // The preview's S-curve carries a pressure ramp, so the coverage window below is a + // tapering stroke's: Pressure for Size is off by default since #11809, so the brush asks. + let mut b = BrushSettings { size: 400.0, pressure_size: true, ..Default::default() }; let px = preview_pixels(&b, 120, 40, [1.0, 0.0, 0.0, 1.0]); assert_eq!(px.len(), 120 * 40 * 4); let covered = px.as_chunks::<4>().0.iter().filter(|p| p[3] > 128).count();