From b84775b5f4a8b40a4daeb668242412dff97d8763 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Fri, 20 Nov 2026 05:21:45 +0100 Subject: [PATCH 1/8] fix(type): a new Type Mask takes the active text layer's style A Type Mask click built its working text layer from the tool options alone, so an 80 pt text layer active on the canvas made a 48 pt mask. The measured case now reads the active layer's font, style and size as the options bar shows them; the vertical mask, a paragraph drag and a non-text active layer keep today's tool options. Refs #12077 --- .../ui-egui/src/tools/type_tool/defaults.rs | 34 +++ .../mask_active_layer_style_tests.rs | 282 ++++++++++++++++++ crates/ui-egui/src/tools/type_tool/pointer.rs | 18 +- 3 files changed, 333 insertions(+), 1 deletion(-) create mode 100644 crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs diff --git a/crates/ui-egui/src/tools/type_tool/defaults.rs b/crates/ui-egui/src/tools/type_tool/defaults.rs index e356e2b52d..9fb604ce6d 100644 --- a/crates/ui-egui/src/tools/type_tool/defaults.rs +++ b/crates/ui-egui/src/tools/type_tool/defaults.rs @@ -92,6 +92,40 @@ pub(super) fn default_style_params(app: &PhotocraftApp) -> serde_json::Value { p } +/// The `type.create` keys a new Type Mask takes from the document's active text layer (#12077): +/// the font, style and size the options bar shows for that layer, so the mask starts in the same +/// type settings instead of the tool's fresh defaults. Measured is only a click (not a paragraph +/// box) with the Horizontal Type Mask over a horizontal text layer, so any other active layer +/// gives `None` and today's tool options apply. The colour stays the foreground colour, as the +/// rest of the create parameters do. +pub(super) fn mask_style_from_active_layer(app: &PhotocraftApp) -> Option { + let st = app.session.active()?; + let t = text_layer(&st.doc, st.active_layer?)?; + if t.orientation != photocraft_doc::text::Orientation::Horizontal { + return None; + } + // The same first run the options bar names the layer by (`bar_character_values`), at the same + // shown size: a 12 pt layer scaled 200 % shows 24 pt. Only reached with no type session open, + // where `shown_scale` reads this very layer. + let c = t.char_runs().into_iter().next()?.style; + let mut p = json!({}); + // An empty name is the layer's placeholder for the default family, not a name to hand to + // `type.create`: the key is only taken when the layer names one. + if !c.font_family.is_empty() { + p["font"] = json!(c.font_family); + } + if !c.font_style.is_empty() { + p["fontStyle"] = json!(c.font_style); + } + let size = json!(c.size_pt * shown_scale(app)); + // A size the document carries that is not a finite number stays out, so the tool's own size + // applies, as it does today. + if finite_style_value(&size) { + p["size"] = size; + } + Some(p) +} + /// Style numbers become f32 in the engine. JSON itself permits finite f64 values too large /// for that conversion; a hand-edited setting must not inject infinity into a new layer. /// Style collections (features, axes, colour) contain only scalar values, so no recursion. diff --git a/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs b/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs new file mode 100644 index 0000000000..023211f89b --- /dev/null +++ b/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs @@ -0,0 +1,282 @@ +//! #12077: with a text layer active, the Horizontal Type Mask starts a new mask in that layer's +//! type settings - the font, style and size the options bar shows for the layer - and not in the +//! tool's fresh defaults. The measured document (800x600 RGB/8, an 80 pt "TXT" active) gives the +//! same selection size as the same text typed with the tool itself set to 80 pt and a pixel layer +//! active; the text layer is not changed and stays active after the commit. +//! +//! The issue's *not measured* rows keep today's behaviour, pinned here: the Vertical Type Mask, a +//! paragraph (box) drag, a mixed orientation (a vertical text layer active), a non-text active +//! layer, and the tool options after the mask. Clicks and the box drag go through the canvas's +//! tool events. + +use egui::Modifiers; +use photocraft_doc::LayerId; +use serde_json::json; + +use super::super::commit; +use super::super::mask_replace_selection_tests::{bounds, click, new_app, selection}; +use super::super::{current_text, text_layer}; +use crate::PhotocraftApp; +use crate::canvas::testing::{ToolEvent, tool_event}; +use crate::state::Tool; + +/// The layer's first character run, which is what `bar_character_values` names the layer by. +fn char_style(app: &PhotocraftApp, id: LayerId) -> photocraft_doc::text::CharStyle { + let t = text_layer(&app.session.active().unwrap().doc, id).expect("a type layer"); + t.char_runs().into_iter().next().expect("a first character run").style +} + +/// What the options bar shows for the layer: its first character run's family, style name and size. +fn style(app: &PhotocraftApp, id: LayerId) -> (String, String, f32) { + let c = char_style(app, id); + (c.font_family, c.font_style, c.size_pt) +} + +/// The working layer the open mask session is typing into. +fn mask_style(app: &PhotocraftApp) -> (String, String, f32) { + let ed = app.ui.text_edit.as_ref().expect("an open mask session"); + style(app, LayerId(ed.layer)) +} + +fn active_layer(app: &PhotocraftApp) -> Option { + app.session.active().and_then(|st| st.active_layer) +} + +fn layers(app: &PhotocraftApp) -> usize { + app.session.active().unwrap().doc.layers.len() +} + +/// [`new_app`]'s document, whose active layer is a type layer named `TXT` with the family +/// `"Inter"`, the style `"Bold"` and `pt` points - the issue's 80 pt text layer. +fn txt_active(pt: f32) -> (Box, LayerId) { + let mut app = new_app(); + let id = + app.run("type.create", json!({"text": "TXT", "x": 60, "y": 120, "font": "Inter", "fontStyle": "Bold", "size": pt})).unwrap()["layer"].as_u64().unwrap(); + let id = LayerId(id); + // The tool's own options, deliberately different from the layer's. + app.ui.tool_options.type_font = "Tool Font".into(); + app.ui.tool_options.type_style = "Regular".into(); + app.ui.tool_options.type_size = 48.0; + (app, id) +} + +/// Start a mask with a click at `at` and type `s`. +fn mask(app: &mut PhotocraftApp, at: (f64, f64), s: &str) { + click(app, at.0, at.1, Modifiers::NONE); + assert!(app.ui.text_edit.as_ref().is_some_and(|ed| ed.mask && ed.created), "a new mask session at {at:?}"); + super::super::host::type_text(app, s); +} + +/// A paragraph mask dragged from `from` to `to` (both ways over 4 screen pixels). +fn box_mask(app: &mut PhotocraftApp, from: (f64, f64), to: (f64, f64), s: &str) { + tool_event(app, ToolEvent::Down { x: from.0, y: from.1, pressure: 1.0 }, Modifiers::NONE); + tool_event(app, ToolEvent::Up { x: to.0, y: to.1 }, Modifiers::NONE); + assert!(app.ui.text_edit.as_ref().is_some_and(|ed| ed.mask && ed.created), "a new mask box {from:?} to {to:?}"); + super::super::host::type_text(app, s); +} + +/// The size of the committed mask's selection, in whole pixels. +fn selection_size(app: &PhotocraftApp) -> (u32, u32) { + let r = bounds(&selection(app)).expect("a Type Mask selection"); + (r.width(), r.height()) +} + +/// The measured row: an 80 pt text layer active and a click on empty canvas starts the mask at +/// 80 pt, not at the tool's 48 pt. +#[test] +fn a_mask_click_with_an_active_text_layer_starts_at_that_layers_size() { + let (mut app, _) = txt_active(80.0); + mask(&mut app, (60.0, 300.0), "MASK"); + assert_eq!(mask_style(&app).2, 80.0, "the active layer's size, not the tool's 48"); +} + +/// The measured acceptance "font, size and style as the options bar shows them for that layer". +#[test] +fn a_mask_click_takes_the_active_layers_font_and_style() { + let (mut app, _) = txt_active(80.0); + mask(&mut app, (60.0, 300.0), "MASK"); + assert_eq!(mask_style(&app), ("Inter".into(), "Bold".into(), 80.0), "the layer's font, style and size"); +} + +/// A 12 pt layer scaled 200 % shows 24 pt in the options bar and the Character panel, so that is +/// the size the mask takes. +#[test] +fn a_mask_click_takes_the_size_the_options_bar_shows_for_the_layer() { + let (mut app, id) = txt_active(12.0); + app.run("type.edit", json!({"layer": id.0, "transform": [2.0, 0.0, 0.0, 2.0, 60.0, 120.0]})).unwrap(); + mask(&mut app, (60.0, 300.0), "MASK"); + assert_eq!(mask_style(&app).2, 24.0, "12 pt at 200 % reads 24 pt, as the bar shows it"); +} + +/// The issue's comparison rows: the mask started by an active 80 pt text layer and the mask the +/// same text makes with a pixel layer active and the tool set to what the bar shows for that layer +/// (font, style and size) have the same selection size, and both differ from today's 48 pt result +/// made at the same point. +#[test] +fn the_active_layer_mask_selects_the_same_glyphs_as_the_tool_at_the_same_size() { + let (mut from_layer, _) = txt_active(80.0); + mask(&mut from_layer, (60.0, 300.0), "MASK"); + commit(&mut from_layer); + let from_layer = selection_size(&from_layer); + + let (mut from_tool, _) = txt_active(80.0); + from_tool.run("layer.new.layer", json!({})).unwrap(); + // The bar shows "Inter" "Bold" 80 pt for the layer, so the comparison tool is set to all three. + from_tool.ui.tool_options.type_font = "Inter".into(); + from_tool.ui.tool_options.type_style = "Bold".into(); + from_tool.ui.tool_options.type_size = 80.0; + mask(&mut from_tool, (60.0, 300.0), "MASK"); + commit(&mut from_tool); + let from_tool = selection_size(&from_tool); + + let (mut at_48, _) = txt_active(80.0); + at_48.run("layer.new.layer", json!({})).unwrap(); + mask(&mut at_48, (60.0, 300.0), "MASK"); + commit(&mut at_48); + let at_48 = selection_size(&at_48); + + assert_eq!(from_layer, from_tool, "the same size as the tool set to the layer's size"); + assert_ne!(from_layer, at_48, "and not today's 48 pt outline {at_48:?}"); +} + +/// The second measured row: the text layer is not changed and stays active after the commit, and +/// the session still leaves only the selection behind. +#[test] +fn the_text_layer_is_unchanged_and_stays_active_after_the_commit() { + let (mut app, id) = txt_active(80.0); + let (before_style, before_text, count) = (style(&app, id), current_text(&app, id), layers(&app)); + mask(&mut app, (60.0, 300.0), "MASK"); + commit(&mut app); + assert!(app.ui.text_edit.is_none(), "the session ended"); + assert_eq!(current_text(&app, id), before_text, "\"TXT\" is not changed"); + assert_eq!(style(&app, id), before_style, "nor its font, style or size"); + assert_eq!(active_layer(&app), Some(id), "and it is the active layer again after the commit"); + assert_eq!(layers(&app), count, "no layer is left behind"); + assert!(selection(&app).is_some(), "the selection is what the commit made"); +} + +/// The third measured row, and the case with no active layer at all: today's tool options still +/// apply. Guard test: passes before and after the change. +#[test] +fn a_non_text_active_layer_keeps_todays_tool_options() { + // A document whose only layer is the Background pixel layer. + let mut background = new_app(); + background.ui.tool_options.type_font = "Tool Font".into(); + background.ui.tool_options.type_style = "Regular".into(); + background.ui.tool_options.type_size = 48.0; + // The empty pixel layer above "TXT" is active. + let (mut pixel, _) = txt_active(80.0); + pixel.run("layer.new.layer", json!({})).unwrap(); + // "TXT" is present but nothing is the active layer. + let (mut none_active, _) = txt_active(80.0); + none_active.run("select.deselectLayers", json!({})).unwrap(); + assert_eq!(active_layer(&none_active), None, "no active layer"); + let cases: Vec<(&str, Box)> = vec![("Background", background), ("pixel layer", pixel), ("no active layer", none_active)]; + for (what, mut app) in cases { + mask(&mut app, (60.0, 300.0), "MASK"); + assert_eq!(mask_style(&app), ("Tool Font".into(), "Regular".into(), 48.0), "{what}: the tool options as today"); + } +} + +/// Not measured and keeping today's behaviour, as a whole: the Vertical Type Mask, and a click +/// whose active text layer is vertical; a paragraph drag with a horizontal text layer active. +#[test] +fn the_vertical_mask_and_a_paragraph_drag_keep_todays_tool_options() { + // The Vertical Type Mask with a horizontal text layer active. + let (mut vertical, _) = txt_active(80.0); + vertical.ui.tool = Tool::VerticalTypeMask; + mask(&mut vertical, (600.0, 100.0), "MASK"); + assert_eq!(mask_style(&vertical), ("Tool Font".into(), "Regular".into(), 48.0), "the vertical mask keeps today's defaults"); + // The Horizontal Type Mask with a vertical text layer active. + let (mut mixed, _) = new_vertical(); + mixed.ui.tool = Tool::HorizontalTypeMask; + mask(&mut mixed, (600.0, 300.0), "MASK"); + assert_eq!(mask_style(&mixed), ("Tool Font".into(), "Regular".into(), 48.0), "a mixed orientation keeps today's defaults"); + // A paragraph (box) drag with a horizontal text layer active. + let (mut dragged, _) = txt_active(80.0); + box_mask(&mut dragged, (60.0, 250.0), (400.0, 340.0), "MASK"); + assert_eq!(mask_style(&dragged), ("Tool Font".into(), "Regular".into(), 48.0), "a box drag keeps today's defaults"); +} + +/// [`txt_active`] with a vertical type layer active instead. +fn new_vertical() -> (Box, LayerId) { + let mut app = new_app(); + let id = app + .run("type.create", json!({"text": "TXT", "x": 60, "y": 120, "font": "Inter", "fontStyle": "Bold", "size": 80.0, "orientation": "vertical"})) + .unwrap()["layer"] + .as_u64() + .unwrap(); + app.ui.tool_options.type_font = "Tool Font".into(); + app.ui.tool_options.type_style = "Regular".into(); + app.ui.tool_options.type_size = 48.0; + (app, LayerId(id)) +} + +/// The plain Type tool is not a Type Mask: with the same 80 pt layer active its click still uses +/// the tool options (#10824 covers the settings of a type target, not this). Guard test: passes +/// before and after the change. +#[test] +fn the_plain_type_tool_still_starts_at_the_tool_options() { + let (mut app, _) = txt_active(80.0); + app.ui.tool = Tool::Type; + click(&mut app, 60.0, 300.0, Modifiers::NONE); + let ed = app.ui.text_edit.clone().expect("a new type session"); + assert!(!ed.mask, "a type layer, not a mask"); + assert_eq!(mask_style(&app), ("Tool Font".into(), "Regular".into(), 48.0), "the Type tool's own defaults"); +} + +/// The zero case: a text layer with no characters still shows its font, style and size in the bar +/// (its one run), so the mask starts at them - the takeover only moves create parameters, it +/// cannot knock anything out. +#[test] +fn an_empty_active_text_layer_gives_its_style_too() { + let mut app = new_app(); + app.run("type.create", json!({"text": "", "x": 60, "y": 120, "font": "Inter", "fontStyle": "Bold", "size": 80})).unwrap(); + app.ui.tool_options.type_font = "Tool Font".into(); + app.ui.tool_options.type_style = "Regular".into(); + app.ui.tool_options.type_size = 48.0; + mask(&mut app, (60.0, 300.0), "MASK"); + assert_eq!(mask_style(&app), ("Inter".into(), "Bold".into(), 80.0), "the empty layer's run, as the bar shows it"); +} + +/// Not measured: which settings besides the size are taken over. Only the bar's font, style and +/// size move to the mask - the active layer's leading, tracking, baseline shift and underline do +/// not. Guard test: passes before and after the change. +#[test] +fn a_mask_takes_no_other_character_settings_from_the_layer() { + let mut app = new_app(); + app.run("type.create", json!({"text": "TXT", "x": 60, "y": 120, "font": "Inter", "fontStyle": "Bold", "size": 80, "leading": 100, "tracking": 200, "baselineShift": 5, "underline": true})) + .unwrap(); + app.ui.tool_options.type_font = "Tool Font".into(); + app.ui.tool_options.type_style = "Regular".into(); + app.ui.tool_options.type_size = 48.0; + mask(&mut app, (60.0, 300.0), "MASK"); + let id = LayerId(app.ui.text_edit.as_ref().expect("an open mask session").layer); + let c = char_style(&app, id); + assert_eq!((c.leading_pt, c.tracking, c.baseline_shift_pt, c.underline), (None, 0.0, 0.0, false), "only font, style and size move over"); + assert_eq!((c.font_family.as_str(), c.font_style.as_str(), c.size_pt), ("Inter", "Bold", 80.0), "those three do"); +} + +/// A layer that names no family or style (their placeholder for "the default"): the mask takes its +/// size but keeps the tool's own font and style, so no empty name reaches `type.create`. +#[test] +fn a_layer_that_names_no_family_or_style_gives_only_its_size() { + let mut app = new_app(); + app.run("type.create", json!({"text": "TXT", "x": 60, "y": 120, "font": "", "fontStyle": "", "size": 80})).unwrap(); + app.ui.tool_options.type_font = "Tool Font".into(); + app.ui.tool_options.type_style = "Regular".into(); + app.ui.tool_options.type_size = 48.0; + mask(&mut app, (60.0, 300.0), "MASK"); + assert_eq!(mask_style(&app), ("Tool Font".into(), "Regular".into(), 80.0), "the size is taken, the empty names are not"); +} + +/// Not measured: whether the tool options themselves change afterwards. Today they do not, and +/// they still do not. Guard test: passes before and after the change. +#[test] +fn taking_the_active_layers_style_leaves_the_tool_options_as_they_are() { + let (mut app, _) = txt_active(80.0); + mask(&mut app, (60.0, 300.0), "MASK"); + commit(&mut app); + let o = &app.ui.tool_options; + assert_eq!((o.type_font.as_str(), o.type_style.as_str(), o.type_size), ("Tool Font", "Regular", 48.0), "the tool options are untouched"); +} diff --git a/crates/ui-egui/src/tools/type_tool/pointer.rs b/crates/ui-egui/src/tools/type_tool/pointer.rs index d393fbd06f..5ae5ea7aaf 100644 --- a/crates/ui-egui/src/tools/type_tool/pointer.rs +++ b/crates/ui-egui/src/tools/type_tool/pointer.rs @@ -13,7 +13,7 @@ use craft::ui::canvas::{CanvasTool, ToolAction, ToolContext, ToolHostResponse, T use craft::ui::primitives::{Draw, PaintShape, StrokeColor, StrokeWidth}; use craft::ui::style::DataColor; -use super::defaults::default_style_params; +use super::defaults::{default_style_params, mask_style_from_active_layer}; use super::editing::begin_edit; use super::layout::{hit_layer, offset_at}; @@ -227,6 +227,18 @@ fn create_text(app: &mut PhotocraftApp, start: [f64; 2], end: [f64; 2]) { let placeholder = app.ui.tool != crate::state::Tool::VerticalTypeMask && app.session.prefs().type_.fill_new_type_layers_with_placeholder; let text = if placeholder { PLACEHOLDER } else { "" }; let mut p = default_style_params(app); + // #12077: the measured case - a click, not a paragraph box, with the Horizontal Type Mask over + // a horizontal text layer - starts the mask in that layer's font, style and size, as the + // options bar shows them for the layer. The vertical mask and a box drag are not measured in + // the issue, so they keep today's tool options. + if mask + && !is_box + && app.ui.tool == crate::state::Tool::HorizontalTypeMask + && let Some(style) = mask_style_from_active_layer(app) + && let (Some(params), Some(style)) = (p.as_object_mut(), style.as_object()) + { + params.extend(style.clone()); + } p["text"] = json!(text); p["orientation"] = json!(if app.ui.tool.is_vertical_type() { "vertical" } else { "horizontal" }); if is_box { @@ -359,3 +371,7 @@ mod mask_placeholder_tests; #[cfg(test)] #[path = "mask_click_text_layer_tests.rs"] mod mask_click_text_layer_tests; + +#[cfg(test)] +#[path = "mask_active_layer_style_tests.rs"] +mod mask_active_layer_style_tests; From d890b19ece7958d7ead72ae3ea2aea0ac0b7858a Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Fri, 20 Nov 2026 07:06:05 +0100 Subject: [PATCH 2/8] fix(type): keep a non-finite layer size out of the mask's create params `mask_style_from_active_layer` built the size with `json!` and only then asked `finite_style_value` about it. `json!` turns a non-finite f32 into `null` and `finite_style_value` accepts `null`, so `type.create` received `"size": null`, its `check_size_tracking` refused the whole parameter set, and the `if let Ok(v)` in `create_text` passed the error over: a Horizontal Type Mask click over a document whose active text layer carries a NaN or an infinite size did nothing at all. Gate the f32 product with `is_finite()` and only then make it JSON, so such a layer keeps the tool's own size and the mask still starts. Pinned by `a_non_finite_layer_size_keeps_the_tool_size`, red before this commit ("a new mask session at (60.0, 300.0)"). --- .../ui-egui/src/tools/type_tool/defaults.rs | 11 +++---- .../mask_active_layer_style_tests.rs | 29 +++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/tools/type_tool/defaults.rs b/crates/ui-egui/src/tools/type_tool/defaults.rs index 9fb604ce6d..17e6e45292 100644 --- a/crates/ui-egui/src/tools/type_tool/defaults.rs +++ b/crates/ui-egui/src/tools/type_tool/defaults.rs @@ -117,11 +117,12 @@ pub(super) fn mask_style_from_active_layer(app: &PhotocraftApp) -> Option Date: Fri, 20 Nov 2026 07:06:13 +0100 Subject: [PATCH 3/8] test(type): stop calling a red mask style test a guard `a_mask_takes_no_other_character_settings_from_the_layer` is red without this change - its last line names the font, style and size the takeover moves over - but its doc comment called it a guard test that passes before and after. The comment now says which it is; the PR text names the five tests that really are guards. --- .../src/tools/type_tool/mask_active_layer_style_tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs b/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs index 0df3196cc0..93e2d94adf 100644 --- a/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs @@ -241,7 +241,8 @@ fn an_empty_active_text_layer_gives_its_style_too() { /// Not measured: which settings besides the size are taken over. Only the bar's font, style and /// size move to the mask - the active layer's leading, tracking, baseline shift and underline do -/// not. Guard test: passes before and after the change. +/// not. Red before the change like the takeover itself: its last line names the three keys that +/// move over. #[test] fn a_mask_takes_no_other_character_settings_from_the_layer() { let mut app = new_app(); From 6d0109a7b42b5d78b1aec870d48d8fc5eb140287 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Sat, 21 Nov 2026 21:31:44 +0100 Subject: [PATCH 4/8] test(type): a mask click on a layer whose shown size leaves the create range makes no mask (red) An 800 pt text layer under a 2x transform shows 1600 pt, above the engine's accepted 0.1-1296 pt range, and a corrupt document can carry a 0 pt run below the minimum. mask_style_from_active_layer gates on finiteness only, so the refused size reaches type.create and the whole click makes no mask at all: the new test fails at the session opening. Answering review thread 4639743127. --- .../mask_active_layer_style_tests.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs b/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs index 93e2d94adf..e3fcd10af1 100644 --- a/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs @@ -300,6 +300,28 @@ fn a_non_finite_layer_size_keeps_the_tool_size() { } } +/// A shown size can also leave the range `type.create` accepts while staying finite: an 800 pt +/// layer under a 2x transform shows 1600 pt, above the engine's 1296 pt maximum, and a corrupt +/// document can carry a 0 pt run, below its 0.1 pt minimum. Inheriting a refused size fails the +/// whole create, so the click would make no mask at all. The size stays out of the parameters +/// there too, and the mask still starts - at the tool's own size, the layer's font and style +/// taken. Red before the range gate: no mask session opens (1600 pt case), or the create answer +/// refuses the click (0 pt case). +#[test] +fn a_shown_layer_size_outside_the_create_range_keeps_the_tool_size() { + // A plain document reaches the too-large case: 800 pt is a size the commands write, only the + // transform makes the shown size leave the accepted range. + let (mut app, id) = txt_active(800.0); + app.run("type.edit", json!({"layer": id.0, "transform": [2.0, 0.0, 0.0, 2.0, 60.0, 120.0]})).unwrap(); + mask(&mut app, (60.0, 300.0), "MASK"); + assert_eq!(mask_style(&app), ("Inter".into(), "Bold".into(), 48.0), "the tool's size, not the 1600 pt the create refuses"); + // And the corrupt-document case below the accepted minimum. + let (mut app, id) = txt_active(80.0); + corrupt_layer_size(&mut app, id, 0.0); + mask(&mut app, (60.0, 300.0), "MASK"); + assert_eq!(mask_style(&app), ("Inter".into(), "Bold".into(), 48.0), "the tool's size, not the 0 pt the create refuses"); +} + /// Not measured: whether the tool options themselves change afterwards. Today they do not, and /// they still do not. Guard test: passes before and after the change. #[test] From 7078cf579efc8c88639a1bc3a488f14533410ac1 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Sat, 21 Nov 2026 21:37:54 +0100 Subject: [PATCH 5/8] fix(type): a new Type Mask inherits only a size type.create accepts The inherited size is the first run's point size times the layer's transform scale, and that product is finite yet out of range very plausibly: an 800 pt layer under a 2x transform shows 1600 pt, past the engine's 1296 pt maximum (TYPE_SIZE_MAX_PT), and a corrupt document can carry a 0 pt run, below the 0.1 pt minimum. A refused size fails type.create as a whole, so the mask click made no mask at all - worse than the tool's own size, which is always valid. Gate the key through the engine's own check_size_tracking, the same single source the options-bar defaults filter uses: an out-of-range or non-finite shown size stays out of the parameters (the tool's size applies), while font and style still move over as measured. The too-large test case moves to a 4x/0.7 transform: at 2x the 800 pt glyphs cover the old click point, and a Type Mask click ON a text layer edits it instead (#12075) - the new click at (700, 550) sits below the glyph band and starts a fresh mask, which is the case under test. Answering review thread 4639743127. --- .../ui-egui/src/tools/type_tool/defaults.rs | 12 +++++++---- .../mask_active_layer_style_tests.rs | 21 ++++++++++--------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/crates/ui-egui/src/tools/type_tool/defaults.rs b/crates/ui-egui/src/tools/type_tool/defaults.rs index 17e6e45292..2af01662ea 100644 --- a/crates/ui-egui/src/tools/type_tool/defaults.rs +++ b/crates/ui-egui/src/tools/type_tool/defaults.rs @@ -118,10 +118,14 @@ pub(super) fn mask_style_from_active_layer(app: &PhotocraftApp) -> Option Date: Sat, 21 Nov 2026 21:59:07 +0100 Subject: [PATCH 6/8] test(type): start the too-large mask case at the file's usual click point The 4x/0.7 transform puts the glyph band right of x = 189 and above y = 120, so the click this file's other cases use (60, 300) already misses the layer's glyphs (a Type Mask click ON glyphs edits that layer, #12075) and starts a fresh mask. Re-verified red at the unfixed defaults and green at the fixed one. --- .../tools/type_tool/mask_active_layer_style_tests.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs b/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs index 667ef1b1d6..d4f31e3ad6 100644 --- a/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs @@ -309,12 +309,13 @@ fn a_non_finite_layer_size_keeps_the_tool_size() { #[test] fn a_shown_layer_size_outside_the_create_range_keeps_the_tool_size() { // A plain document reaches the too-large case: 800 pt is a size the commands write, only the - // transform pushes the shown product past the maximum. The vertical 0.7 keeps the glyph band - // well above y = 400, so the click at (700, 550) starts a new mask instead of editing the - // layer's glyphs under it (#12075). + // transform pushes the shown product past the maximum. The transformed glyph band then sits + // entirely right of x = 189 and above y = 120, so the same click this file's other cases use + // does not land on the layer's glyphs (which would edit the layer, #12075) but starts a + // fresh mask. let (mut app, id) = txt_active(800.0); app.run("type.edit", json!({"layer": id.0, "transform": [4.0, 0.0, 0.0, 0.7, 60.0, 120.0]})).unwrap(); - mask(&mut app, (700.0, 550.0), "MASK"); + mask(&mut app, (60.0, 300.0), "MASK"); assert_eq!(mask_style(&app), ("Inter".into(), "Bold".into(), 48.0), "the tool's size, not the 1338 pt the create refuses"); // And the corrupt-document case below the accepted minimum. let (mut app, id) = txt_active(80.0); @@ -333,3 +334,4 @@ fn taking_the_active_layers_style_leaves_the_tool_options_as_they_are() { let o = &app.ui.tool_options; assert_eq!((o.type_font.as_str(), o.type_style.as_str(), o.type_size), ("Tool Font", "Regular", 48.0), "the tool options are untouched"); } + From 02193d83b92fe9307655b75cba4e3dae2501217c Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Sat, 21 Nov 2026 22:17:29 +0100 Subject: [PATCH 7/8] style(type): drop a trailing blank line in the mask style tests Left by an edit during the range-gate work; no content change. --- .../ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs b/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs index d4f31e3ad6..1b0320a3fc 100644 --- a/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs @@ -334,4 +334,3 @@ fn taking_the_active_layers_style_leaves_the_tool_options_as_they_are() { let o = &app.ui.tool_options; assert_eq!((o.type_font.as_str(), o.type_style.as_str(), o.type_size), ("Tool Font", "Regular", 48.0), "the tool options are untouched"); } - From ce776f0cb9024e5ee9ffb5d64855873cb87a0925 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Sat, 21 Nov 2026 22:35:56 +0100 Subject: [PATCH 8/8] fix(type): adapt the corrupt-size mask test to the engine's doc accessor The merged main no longer lets a caller assign through DocState: it takes no DerefMut, and the test helper wrote st.doc directly, so the ui-egui lib test target failed to build (E0594) and the CI archive step with it. Write through doc_mut(), the way main's own type_tool canvas test does. --- .../src/tools/type_tool/mask_active_layer_style_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs b/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs index 1b0320a3fc..1d946637b0 100644 --- a/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/mask_active_layer_style_tests.rs @@ -282,7 +282,7 @@ fn corrupt_layer_size(app: &mut PhotocraftApp, id: LayerId, bad: f32) { r.style.size_pt = bad; } } - st.doc = std::sync::Arc::new(doc); + *st.doc_mut() = std::sync::Arc::new(doc); st.revision += 1; }