From d21c403e5f8a127bdc63e584f574bdbd8c9dd08a Mon Sep 17 00:00:00 2001 From: Tareq Halaby Date: Tue, 3 Nov 2026 17:55:35 +0100 Subject: [PATCH 1/3] Type: add OpenType Numerals submenu (figure styles) (#11051) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Type: add OpenType Numerals submenu (figure styles) Type › OpenType › Numerals sets lnum/onum/pnum/tnum as a radio style (Default through Tabular Oldstyle). Checkmarks follow the selection start; TYPE-218-5 scorecard/gaps updated; parity floor 640. * refactor(engine): one style-at-character lookup for the OpenType menus feature_on_at and numerals_style_at each walked the runs the same way; they now share style_at. NumeralsStyle::from_id and numerals_style_of read the existing tables instead of repeating them. Co-Authored-By: Claude Opus 5.5 * fix(text): persist OpenType numeral tags through PSD EngineData Map lnum/pnum/tnum as EngineData bools and the width×height combos as FigureStyle (Krita/Illustrator), so Numerals choices survive PSD round-trip. * docs(gaps): note Numerals PSD figure-tag round-trip * revert(text): keep PSD EngineData to the keys Photoshop writes Backs out the PSD half of 18610324 and its gaps note (58813de3); the engine reformat in that commit stays. - `LiningFigures`, `ProportionalFigures` and `TabularFigures` are not Photoshop EngineData keys (the commit says Photoshop only has `OldStyle`), so writing them puts keys of our own into users' PSDs. - The `/FigureStyle` code table (1-4) has no oracle: no Photoshop-authored file in photocraft-corpus, and neither ag-psd nor psd-tools reads it. AGENTS.md rule 3 asks for public specs or observation. PSD persistence of the numeral styles can come back with a Photoshop-authored oracle. The Numerals menu still round-trips through .pcraft. Co-Authored-By: Claude Opus 5.5 * test(text): lock PSD EngineData to Photoshop OldStyle for numerals Document AGENTS.md clean-room: only onum survives TySh round-trip; lnum/pnum/tnum stay .pcraft-only until a Photoshop-authored corpus oracle. --------- Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- crates/engine/src/cmd/type_extra_cmds.rs | 182 +++++++++++++++++- .../engine/src/cmd/type_extra_cmds/tests.rs | 132 +++++++++++++ crates/text/src/tests.rs | 20 ++ crates/ui-egui/src/menu_catalog.rs | 9 + crates/ui-egui/src/menus/parity.rs | 2 +- .../ui-egui/src/menus/view_cmds/dispatch.rs | 9 +- crates/ui-egui/src/menus/view_cmds/tests.rs | 20 ++ docs/gaps.md | 7 +- docs/parity-checklist.md | 4 +- docs/scorecard.md | 6 +- scorecard/type.toml | 2 +- 11 files changed, 378 insertions(+), 15 deletions(-) diff --git a/crates/engine/src/cmd/type_extra_cmds.rs b/crates/engine/src/cmd/type_extra_cmds.rs index d8c11a52d6..566912b21c 100644 --- a/crates/engine/src/cmd/type_extra_cmds.rs +++ b/crates/engine/src/cmd/type_extra_cmds.rs @@ -1,6 +1,7 @@ //! The Type menu: anti-aliasing, orientation, point ⇄ paragraph conversion, Create Work Path, -//! Convert to Shape, Rasterize, Warp Text, the OpenType toggles, Paste Lorem Ipsum, Update All -//! Text Layers, missing-font replacement and the default type styles. +//! Convert to Shape, Rasterize, Warp Text, the OpenType toggles (with the Numerals submenu), +//! Paste Lorem Ipsum, Update All Text Layers, missing-font replacement and the default type +//! styles. //! //! Everything edits the typed [`TextLayer`] model and re-renders through `type_cmds::refresh`, //! so the PSD `TySh` data (and with it warp, anti-aliasing and the OpenType flags) is regenerated @@ -502,6 +503,88 @@ fn warp_text(s: &mut Session, p: &Value) -> Result { // ---------- OpenType toggles ---------- +/// OpenType figure tags Type › OpenType › Numerals clears or sets (`lnum`/`onum`/`pnum`/`tnum`). +pub const NUMERAL_FEATURE_TAGS: [&str; 4] = ["lnum", "onum", "pnum", "tnum"]; + +/// One item of Type › OpenType › Numerals (Adobe figure-style radio set). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum NumeralsStyle { + Default, + Lining, + Oldstyle, + Proportional, + Tabular, + ProportionalLining, + TabularLining, + ProportionalOldstyle, + TabularOldstyle, +} + +impl NumeralsStyle { + /// Command-id suffix after `type.openType.numerals.`. + pub const fn id(self) -> &'static str { + match self { + Self::Default => "default", + Self::Lining => "lining", + Self::Oldstyle => "oldstyle", + Self::Proportional => "proportional", + Self::Tabular => "tabular", + Self::ProportionalLining => "proportionalLining", + Self::TabularLining => "tabularLining", + Self::ProportionalOldstyle => "proportionalOldstyle", + Self::TabularOldstyle => "tabularOldstyle", + } + } + + /// Menu label for this numerals style. + pub const fn label(self) -> &'static str { + match self { + Self::Default => "Default", + Self::Lining => "Lining", + Self::Oldstyle => "Oldstyle", + Self::Proportional => "Proportional", + Self::Tabular => "Tabular", + Self::ProportionalLining => "Proportional Lining", + Self::TabularLining => "Tabular Lining", + Self::ProportionalOldstyle => "Proportional Oldstyle", + Self::TabularOldstyle => "Tabular Oldstyle", + } + } + + /// Parse a `type.openType.numerals.*` suffix. + pub fn from_id(id: &str) -> Option { + Self::ALL.into_iter().find(|style| style.id() == id) + } + + /// Every Numerals menu item, in menu order. + pub const ALL: [Self; 9] = [ + Self::Default, + Self::Lining, + Self::Oldstyle, + Self::Proportional, + Self::Tabular, + Self::ProportionalLining, + Self::TabularLining, + Self::ProportionalOldstyle, + Self::TabularOldstyle, + ]; + + /// OpenType tags this style turns on (the other [`NUMERAL_FEATURE_TAGS`] are cleared). + pub const fn tags(self) -> &'static [&'static str] { + match self { + Self::Default => &[], + Self::Lining => &["lnum"], + Self::Oldstyle => &["onum"], + Self::Proportional => &["pnum"], + Self::Tabular => &["tnum"], + Self::ProportionalLining => &["pnum", "lnum"], + Self::TabularLining => &["tnum", "lnum"], + Self::ProportionalOldstyle => &["pnum", "onum"], + Self::TabularOldstyle => &["tnum", "onum"], + } + } +} + /// Is the OpenType toggle `tag` on for a character style? (`liga`/`dlig` have dedicated fields.) pub fn feature_on(st: &photocraft_doc::text::CharStyle, tag: &str) -> bool { match tag { @@ -511,6 +594,36 @@ pub fn feature_on(st: &photocraft_doc::text::CharStyle, tag: &str) -> bool { } } +/// The character style at character `ci` of `t`: its run's, or past the end the last run's. +fn style_at(t: &TextLayer, ci: usize) -> Option { + let at = byte_index(&t.text, ci); + let mut end = 0usize; + let mut last = None; + for run in t.char_runs() { + end = end.saturating_add(run.len); + if at < end { + return Some(run.style); + } + last = Some(run.style); + } + last +} + +/// Is the OpenType toggle `tag` on at character `ci` of `t`? Past the end it reads the last run. +pub fn feature_on_at(t: &TextLayer, ci: usize, tag: &str) -> bool { + style_at(t, ci).is_some_and(|st| feature_on(&st, tag)) +} + +/// Which Numerals menu item matches `st`'s figure tags? `None` when the mix is not a menu item. +pub fn numerals_style_of(st: &photocraft_doc::text::CharStyle) -> Option { + NumeralsStyle::ALL.into_iter().find(|style| NUMERAL_FEATURE_TAGS.iter().all(|tag| feature_on(st, tag) == style.tags().contains(tag))) +} + +/// Numerals style at character `ci` of `t` (same run pick as [`feature_on_at`]). +pub fn numerals_style_at(t: &TextLayer, ci: usize) -> Option { + style_at(t, ci).and_then(|st| numerals_style_of(&st)) +} + fn set_feature(st: &mut photocraft_doc::text::CharStyle, tag: &str, on: bool) { match tag { "liga" => st.ligatures = on, @@ -524,13 +637,37 @@ fn set_feature(st: &mut photocraft_doc::text::CharStyle, tag: &str, on: bool) { } } +fn apply_numerals(st: &mut photocraft_doc::text::CharStyle, style: NumeralsStyle) { + let on = style.tags(); + for tag in NUMERAL_FEATURE_TAGS { + set_feature(st, tag, on.contains(&tag)); + } +} + +fn set_numerals(s: &mut Session, p: &Value, style: NumeralsStyle) -> Result { + with_text_targets(s, p, "Change OpenType Numerals", |t, (a, b)| { + style_range(t, a.min(b), a.max(b), &|st| apply_numerals(st, style)); + Ok(()) + })?; + Ok(json!({"numerals": style.id()})) +} + fn toggle_opentype(s: &mut Session, p: &Value, tag: &'static str) -> Result { let ids = format_targets(s, p)?; let st = s.active().ok_or(EngineError::NoDocument)?; let representative = st.active_layer.filter(|id| ids.contains(id)).or_else(|| ids.first().copied()); - let cur = representative - .and_then(|id| st.doc.layer(id)) - .is_some_and(|l| matches!(&l.content, LayerContent::Text(t) if t.char_runs().first().is_some_and(|r| feature_on(&r.style, tag)))); + // The toggle direction follows the style where the edit starts: the range start on a single + // layer, else the first character. + let start_char = if p.get("layers").is_none() || p.get("layer").is_some() { + p.get("range").and_then(Value::as_array).filter(|r| r.len() == 2).map_or(0, |r| { + let a = r.first().and_then(Value::as_u64).unwrap_or(0); + let b = r.get(1).and_then(Value::as_u64).unwrap_or(a); + usize::try_from(a.min(b)).unwrap_or(usize::MAX) + }) + } else { + 0 + }; + let cur = representative.and_then(|id| st.doc.layer(id)).is_some_and(|l| matches!(&l.content, LayerContent::Text(t) if feature_on_at(t, start_char, tag))); let on = p.get("on").and_then(Value::as_bool).unwrap_or(!cur); with_text_targets(s, p, "Change OpenType Feature", |t, (a, b)| { style_range(t, a.min(b), a.max(b), &|st| set_feature(st, tag, on)); @@ -770,6 +907,41 @@ pub fn specs() -> Vec { spec!("type.openType.ornaments", "Ornaments", &["Type", "OpenType"], OT, has_format_target, |s, p| toggle_opentype(s, p, "ornm")), spec!("type.openType.ordinals", "Ordinals", &["Type", "OpenType"], OT, has_format_target, |s, p| toggle_opentype(s, p, "ordn")), spec!("type.openType.fractions", "Fractions", &["Type", "OpenType"], OT, has_format_target, |s, p| toggle_opentype(s, p, "frac")), + spec!("type.openType.numerals.default", "Default", &["Type", "OpenType", "Numerals"], FP, has_format_target, |s, p| set_numerals( + s, + p, + NumeralsStyle::Default + )), + spec!("type.openType.numerals.lining", "Lining", &["Type", "OpenType", "Numerals"], FP, has_format_target, |s, p| { + set_numerals(s, p, NumeralsStyle::Lining) + }), + spec!("type.openType.numerals.oldstyle", "Oldstyle", &["Type", "OpenType", "Numerals"], FP, has_format_target, |s, p| { + set_numerals(s, p, NumeralsStyle::Oldstyle) + }), + spec!("type.openType.numerals.proportional", "Proportional", &["Type", "OpenType", "Numerals"], FP, has_format_target, |s, p| set_numerals( + s, + p, + NumeralsStyle::Proportional + )), + spec!("type.openType.numerals.tabular", "Tabular", &["Type", "OpenType", "Numerals"], FP, has_format_target, |s, p| { + set_numerals(s, p, NumeralsStyle::Tabular) + }), + spec!("type.openType.numerals.proportionalLining", "Proportional Lining", &["Type", "OpenType", "Numerals"], FP, has_format_target, |s, p| { + set_numerals(s, p, NumeralsStyle::ProportionalLining) + }), + spec!("type.openType.numerals.tabularLining", "Tabular Lining", &["Type", "OpenType", "Numerals"], FP, has_format_target, |s, p| set_numerals( + s, + p, + NumeralsStyle::TabularLining + )), + spec!("type.openType.numerals.proportionalOldstyle", "Proportional Oldstyle", &["Type", "OpenType", "Numerals"], FP, has_format_target, |s, p| { + set_numerals(s, p, NumeralsStyle::ProportionalOldstyle) + }), + spec!("type.openType.numerals.tabularOldstyle", "Tabular Oldstyle", &["Type", "OpenType", "Numerals"], FP, has_format_target, |s, p| set_numerals( + s, + p, + NumeralsStyle::TabularOldstyle + )), spec!("type.createWorkPath", "Create Work Path", &["Type"], LP, has_text, create_work_path), spec!("type.convertToShape", "Convert to Shape", &["Type"], LP, has_text, convert_to_shape), spec!("type.rasterizeTypeLayer", "Rasterize Type Layer", &["Type"], LP, has_text, |s, p| s.execute("type.rasterize", p.clone())), diff --git a/crates/engine/src/cmd/type_extra_cmds/tests.rs b/crates/engine/src/cmd/type_extra_cmds/tests.rs index 8ae504cfa1..4008f82001 100644 --- a/crates/engine/src/cmd/type_extra_cmds/tests.rs +++ b/crates/engine/src/cmd/type_extra_cmds/tests.rs @@ -243,6 +243,138 @@ fn opentype_toggles_store_features() { assert!(feature_on(&back.char_runs()[0].style, "swsh") && !back.char_runs()[0].style.ligatures); } +/// Is `tag` on at character `ci` of an ASCII text layer? +fn on_at(s: &Session, id: LayerId, ci: usize, tag: &str) -> bool { + let mut end = 0; + text(s, id) + .char_runs() + .iter() + .find(|r| { + end += r.len; + ci < end + }) + .is_some_and(|r| feature_on(&r.style, tag)) +} + +#[test] +fn numerals_are_registered_with_their_menu_path() { + for style in NumeralsStyle::ALL { + let spec = crate::commands::find(&format!("type.openType.numerals.{}", style.id())).unwrap(); + assert_eq!(spec.label, style.label()); + assert_eq!(spec.menu, ["Type", "OpenType", "Numerals"]); + } + assert!(crate::commands::find("type.openType.numerals.unknown").is_none()); +} + +#[test] +fn numerals_replace_figure_tags_and_keep_other_features() { + let mut s = session(8); + let id = text_layer(&mut s, "012345"); + let before = text(&s, id).char_runs()[0].style.clone(); + s.execute("type.openType.fractions", json!({"on": true})).unwrap(); + s.execute("type.openType.numerals.tabularLining", json!({})).unwrap(); + assert_eq!(numerals_style_of(&text(&s, id).char_runs()[0].style), Some(NumeralsStyle::TabularLining)); + assert!(on_at(&s, id, 0, "tnum") && on_at(&s, id, 0, "lnum") && !on_at(&s, id, 0, "onum") && !on_at(&s, id, 0, "pnum")); + assert!(feature_on(&text(&s, id).char_runs()[0].style, "frac"), "non-figure features stay"); + s.execute("type.openType.numerals.proportionalOldstyle", json!({})).unwrap(); + assert_eq!(numerals_style_of(&text(&s, id).char_runs()[0].style), Some(NumeralsStyle::ProportionalOldstyle)); + assert!(on_at(&s, id, 0, "pnum") && on_at(&s, id, 0, "onum") && !on_at(&s, id, 0, "tnum") && !on_at(&s, id, 0, "lnum")); + s.execute("type.openType.numerals.default", json!({})).unwrap(); + assert_eq!(numerals_style_of(&text(&s, id).char_runs()[0].style), Some(NumeralsStyle::Default)); + for tag in NUMERAL_FEATURE_TAGS { + assert!(!on_at(&s, id, 0, tag), "{tag}"); + } + let st = text(&s, id).char_runs()[0].style.clone(); + assert!(st.ligatures, "liga untouched"); + assert_eq!((st.size_pt, st.font_family.clone(), st.color), (before.size_pt, before.font_family, before.color)); +} + +#[test] +fn numerals_range_edits_only_those_characters() { + let mut s = session(8); + let id = text_layer(&mut s, "abcdef"); + s.execute("type.openType.numerals.lining", json!({"range": [2, 5]})).unwrap(); + let on: Vec = (0..6).map(|i| on_at(&s, id, i, "lnum")).collect(); + assert_eq!(on, [false, false, true, true, true, false]); + assert_eq!(numerals_style_at(text(&s, id), 2), Some(NumeralsStyle::Lining)); + assert_eq!(numerals_style_at(text(&s, id), 0), Some(NumeralsStyle::Default)); + s.execute("type.openType.numerals.tabular", json!({"range": [2, 5]})).unwrap(); + assert!(on_at(&s, id, 3, "tnum") && !on_at(&s, id, 3, "lnum")); + assert!(!on_at(&s, id, 0, "tnum")); +} + +#[test] +fn numerals_apply_to_every_listed_layer() { + let mut s = session(8); + let a = text_layer(&mut s, "one"); + let b = text_layer(&mut s, "two"); + s.execute("type.openType.numerals.oldstyle", json!({"layers": [a.0, b.0]})).unwrap(); + assert!(on_at(&s, a, 0, "onum") && on_at(&s, b, 2, "onum")); + s.execute("type.openType.numerals.default", json!({"layers": [a.0, b.0]})).unwrap(); + assert!(!on_at(&s, a, 0, "onum") && !on_at(&s, b, 0, "onum")); +} + +#[test] +fn numerals_are_one_undo_step_each() { + let mut s = session(8); + let id = text_layer(&mut s, "123"); + s.execute("type.openType.numerals.lining", json!({})).unwrap(); + s.execute("type.openType.numerals.tabularOldstyle", json!({})).unwrap(); + assert!(s.undo()); + assert_eq!(numerals_style_of(&text(&s, id).char_runs()[0].style), Some(NumeralsStyle::Lining)); + assert!(s.undo()); + assert_eq!(numerals_style_of(&text(&s, id).char_runs()[0].style), Some(NumeralsStyle::Default)); + assert!(s.redo()); + assert_eq!(numerals_style_of(&text(&s, id).char_runs()[0].style), Some(NumeralsStyle::Lining)); +} + +#[test] +fn numerals_survive_a_pcraft_round_trip() { + let mut s = session(8); + let id = text_layer(&mut s, "Il36"); + s.execute("type.openType.numerals.proportionalLining", json!({})).unwrap(); + let bytes = photocraft_format::save_to_bytes(&s.active().unwrap().doc, &Default::default()).unwrap(); + let doc = photocraft_format::load_from_bytes(&bytes).unwrap(); + let Some(LayerContent::Text(t)) = doc.layer(id).map(|l| &l.content) else { panic!("text layer lost") }; + assert_eq!(numerals_style_of(&t.char_runs()[0].style), Some(NumeralsStyle::ProportionalLining)); +} + +#[test] +fn numerals_fail_gracefully_on_bad_params() { + let mut s = session(8); + let bg = s.active().unwrap().active_layer.unwrap(); + let id = text_layer(&mut s, "abc"); + let cmd = "type.openType.numerals.tabularLining"; + assert!(s.execute(cmd, json!({"layer": 987_654})).is_err(), "unknown layer"); + assert!(s.execute(cmd, json!({"layer": bg.0})).is_err(), "not a type layer"); + assert!(s.execute(cmd, json!({"layers": ["x"]})).is_err()); + s.execute(cmd, json!({"range": [5, 2]})).unwrap(); + s.execute(cmd, json!({"range": [50, 90]})).unwrap(); + s.execute(cmd, json!({"range": [u64::MAX, 0]})).unwrap(); + s.execute(cmd, json!({"range": "all"})).unwrap(); + assert!(s.execute(cmd, json!({"layer": id.0, "range": [0, 1]})).is_ok()); + assert_eq!(numerals_style_of(&text(&s, id).char_runs()[0].style), Some(NumeralsStyle::TabularLining)); +} + +#[test] +fn numerals_tabular_changes_inter_digit_widths() { + let mut s = session(8); + let r = s.execute("type.create", json!({"x": 20, "y": 70, "text": "1111111111", "font": "Inter", "size": 36, "color": "#000000"})).unwrap(); + let id = LayerId(r["layer"].as_u64().unwrap()); + let width = |s: &Session| { + let t = text(s, id).clone(); + let mut e = photocraft_text::shared().lock().unwrap_or_else(|e| e.into_inner()); + let layout = e.layout(&t, 72.0); + layout.lines.first().map_or(0.0, |line| line.x1 - line.x0) + }; + let plain = width(&s); + s.execute("type.openType.numerals.tabular", json!({})).unwrap(); + let tab = width(&s); + assert!((tab - plain).abs() > 0.5, "tnum changes Inter's digit advances: {plain} → {tab}"); + s.execute("type.openType.numerals.default", json!({})).unwrap(); + assert!((width(&s) - plain).abs() < 0.5, "default restores the advances"); +} + #[test] fn lorem_update_fonts_and_default_styles() { let mut s = session(16); diff --git a/crates/text/src/tests.rs b/crates/text/src/tests.rs index 3aa0e6d40f..b88ec9ec72 100644 --- a/crates/text/src/tests.rs +++ b/crates/text/src/tests.rs @@ -1732,6 +1732,26 @@ fn psd_round_trips_antialias_opentype_and_warp() { } } +/// EngineData only maps Photoshop's `OldStyle` bool to `onum`. Other Numerals tags (`lnum` / +/// `pnum` / `tnum`) stay in `.pcraft` until a Photoshop-authored PSD oracle exists — we do not +/// invent EngineData keys or copy figure-style tables from GPL editors (AGENTS.md clean-room). +#[test] +fn psd_engine_data_keeps_only_oldstyle_among_numeral_tags() { + let style = CharStyle { + font_family: "Inter".into(), + size_pt: 20.0, + features: ["lnum", "onum", "pnum", "tnum"].iter().map(|t| FontFeature { tag: (*t).into(), value: 1 }).collect(), + ..Default::default() + }; + let t = styled("0123456789", style); + let bytes = crate::psd::build_tysh(&t, 72.0, None); + let back = crate::psd::text_layer_from_tysh(&bytes, 72.0).expect("tysh"); + let runs = back.char_runs(); + let mut got: Vec<&str> = runs[0].style.features.iter().map(|f| f.tag.as_str()).collect(); + got.sort_unstable(); + assert_eq!(got, ["onum"]); +} + /// A legacy-signature `TySh` (#1469): zero PointBase, `bounds` (the layout box) and `boundingBox` /// (the ink box, as Photoshop writes it) both around `anchor` in a remote local space, and a /// `transform` that cancels the remote origin. diff --git a/crates/ui-egui/src/menu_catalog.rs b/crates/ui-egui/src/menu_catalog.rs index 1d98028625..09f732dc7a 100644 --- a/crates/ui-egui/src/menu_catalog.rs +++ b/crates/ui-egui/src/menu_catalog.rs @@ -474,6 +474,15 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[ (&["Type", "OpenType"], "Ornaments", None, "type.openType.ornaments"), (&["Type", "OpenType"], "Ordinals", None, "type.openType.ordinals"), (&["Type", "OpenType"], "Fractions", None, "type.openType.fractions"), + (&["Type", "OpenType", "Numerals"], "Default", None, "type.openType.numerals.default"), + (&["Type", "OpenType", "Numerals"], "Lining", None, "type.openType.numerals.lining"), + (&["Type", "OpenType", "Numerals"], "Oldstyle", None, "type.openType.numerals.oldstyle"), + (&["Type", "OpenType", "Numerals"], "Proportional", None, "type.openType.numerals.proportional"), + (&["Type", "OpenType", "Numerals"], "Tabular", None, "type.openType.numerals.tabular"), + (&["Type", "OpenType", "Numerals"], "Proportional Lining", None, "type.openType.numerals.proportionalLining"), + (&["Type", "OpenType", "Numerals"], "Tabular Lining", None, "type.openType.numerals.tabularLining"), + (&["Type", "OpenType", "Numerals"], "Proportional Oldstyle", None, "type.openType.numerals.proportionalOldstyle"), + (&["Type", "OpenType", "Numerals"], "Tabular Oldstyle", None, "type.openType.numerals.tabularOldstyle"), (&["Type"], "---", None, "---"), (&["Type"], "Create Work Path", None, "type.createWorkPath"), (&["Type"], "Convert to Shape", None, "type.convertToShape"), diff --git a/crates/ui-egui/src/menus/parity.rs b/crates/ui-egui/src/menus/parity.rs index ab5fd5eee7..2aa25e9b40 100644 --- a/crates/ui-egui/src/menus/parity.rs +++ b/crates/ui-egui/src/menus/parity.rs @@ -7,7 +7,7 @@ use crate::menu_catalog::CATALOG; use crate::menus::is_live; /// Minimum number of live catalog items. Raise it when parity grows; never lower it. -pub const FLOOR: usize = 631; +pub const FLOOR: usize = 640; /// One top-level menu's coverage. #[derive(Clone, Debug, serde::Serialize)] diff --git a/crates/ui-egui/src/menus/view_cmds/dispatch.rs b/crates/ui-egui/src/menus/view_cmds/dispatch.rs index 80e8d41c88..d103ef5f14 100644 --- a/crates/ui-egui/src/menus/view_cmds/dispatch.rs +++ b/crates/ui-egui/src/menus/view_cmds/dispatch.rs @@ -185,6 +185,13 @@ fn type_checked(app: &PhotocraftApp, id: &str) -> Option { return Some(t.is_some_and(|t| (t.orientation == photocraft_doc::text::Orientation::Vertical) == (k == "vertical"))); } let t = t?; + // The style where the menu reads: the selection start while editing a range (as the Character + // panel shows it), else the layer's first run. + let start = crate::type_tool::target(app).and_then(|(_, range)| range).map_or(0, |r| r[0]); + if let Some(key) = id.strip_prefix("type.openType.numerals.") { + let want = photocraft_engine::type_extra_cmds::NumeralsStyle::from_id(key)?; + return Some(photocraft_engine::type_extra_cmds::numerals_style_at(t, start) == Some(want)); + } let tag = match id.strip_prefix("type.openType.")? { "standardLigatures" => "liga", "contextualAlternates" => "calt", @@ -198,7 +205,7 @@ fn type_checked(app: &PhotocraftApp, id: &str) -> Option { "fractions" => "frac", _ => return None, }; - Some(t.char_runs().first().is_some_and(|r| photocraft_engine::type_extra_cmds::feature_on(&r.style, tag))) + Some(photocraft_engine::type_extra_cmds::feature_on_at(t, start, tag)) } /// Engine commands that get a dialog or file picker here when invoked without parameters. diff --git a/crates/ui-egui/src/menus/view_cmds/tests.rs b/crates/ui-egui/src/menus/view_cmds/tests.rs index 3ef2ab13fa..a8928891ad 100644 --- a/crates/ui-egui/src/menus/view_cmds/tests.rs +++ b/crates/ui-egui/src/menus/view_cmds/tests.rs @@ -255,6 +255,26 @@ fn type_menu_checkmarks_follow_the_layer() { assert_eq!(checked(&app, "type.orientation.horizontal"), Some(true)); } +#[test] +fn numerals_checkmark_follows_the_selection() { + let (mut app, ctx) = app_with(1); + let id = "type.openType.numerals.tabularLining"; + assert!(!crate::menus::is_enabled(&app, id)); + assert_eq!(checked(&app, id), None, "no type layer"); + app.run("type.create", json!({"x": 10, "y": 50, "text": "Type", "size": 24})).unwrap(); + assert!(crate::menus::is_enabled(&app, id)); + assert_eq!(checked(&app, "type.openType.numerals.default"), Some(true)); + assert_eq!(checked(&app, id), Some(false)); + menu(&mut app, &ctx, id, json!({})).unwrap(); + assert_eq!(checked(&app, id), Some(true)); + assert_eq!(checked(&app, "type.openType.numerals.default"), Some(false)); + assert_eq!(checked(&app, "type.openType.numerals.lining"), Some(false)); + menu(&mut app, &ctx, "type.openType.numerals.default", json!({})).unwrap(); + assert_eq!(checked(&app, "type.openType.numerals.default"), Some(true)); + assert_eq!(checked(&app, id), Some(false)); + assert_eq!(checked(&app, "type.openType.numerals.notAStyle"), None); +} + #[test] fn batch_menu_requires_a_recorded_action() { let (mut app, ctx) = app_with(1); diff --git a/docs/gaps.md b/docs/gaps.md index 0b7ee59a00..2460f2e34c 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -99,8 +99,10 @@ what an agent can't finish alone. and saves back into the file's `Txt2` since 2026-10-21, #7962), the visual RTL caret and PSD storage of the paragraph direction (TYPE-218-2; the paragraph direction buttons landed 2026-10-22), complex-script fallback fonts and golden tests - (TYPE-218-3), OpenType Numerals and Stylistic Sets submenus - (TYPE-218-5; the Character panel buttons landed 2026-10-11, #3752), text free transform + (TYPE-218-3), OpenType Stylistic Sets submenu and greying out features the font lacks + (TYPE-218-5; Character panel buttons 2026-10-11, #3752; Numerals submenu 2026-11-03 — + `.pcraft` keeps all figure tags; PSD EngineData only `OldStyle`/`onum` until a Photoshop-authored + oracle lands), text free transform (#2630), area type in PSD (TYPE-218-10). Done since the re-measure: manual and optical kerning with PSD round trip (TYPE-218-6, #206), variable-font axes (TYPE-218-4, #2985), Warp on live type without a rasterize prompt, as in Photoshop (TYPE-218-9, #3004), and the live Warp Text preview that opens @@ -528,6 +530,7 @@ what an agent can't finish alone. | 2026-10-11 | minor | G13: Czech dynamic UI text localized; engine messages and native review remain open | | 2026-10-11 | minor | G8: triple/quadruple/five-click type selection done (TYPE-218-8, #3493); Type evidence recounted | | 2026-10-11 | minor | G4: Pattern Stamp and Background Eraser draw live, Spot Healing shows a dark overlay while dragging (#3754); only the Mixer Brush is left of TOOL-213-7 | +| 2026-11-03 | minor | G8: Type › OpenType › Numerals submenu landed (TYPE-218-5); `.pcraft` keeps figure tags, PSD only `OldStyle`/`onum` for now; Stylistic Sets and font-feature greying still missing | | 2026-10-11 | minor | G8: Character panel OpenType buttons landed (TYPE-218-5, #3752); Numerals and Stylistic Sets submenus still missing | | 2026-10-11 | minor | G10: one-page flattened PDF write shipped (io::pdf, #3401); FILE-215-10 now partial | | 2026-10-10 | minor | G2: recorded Tilt-Shift computation/filtered-proxy measurements and limits; gap and estimate remain open diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md index 5c747e5d52..064be8aba2 100644 --- a/docs/parity-checklist.md +++ b/docs/parity-checklist.md @@ -2,7 +2,7 @@ Generated by `cargo xtask parity` from `crates/ui-egui/src/menu_catalog.rs` (Photoshop's menu tree) and the live command registry. Do not edit by hand. -**631 of 631 menu items live (100.0%).** +**640 of 640 menu items live (100.0%).** | Menu | Live | Total | % | |---|---:|---:|---:| @@ -10,7 +10,7 @@ Generated by `cargo xtask parity` from `crates/ui-egui/src/menu_catalog.rs` (Pho | Edit | 75 | 75 | 100% | | Image | 61 | 61 | 100% | | Layer | 163 | 163 | 100% | -| Type | 45 | 45 | 100% | +| Type | 54 | 54 | 100% | | Select | 25 | 25 | 100% | | Filter | 75 | 75 | 100% | | View | 74 | 74 | 100% | diff --git a/docs/scorecard.md b/docs/scorecard.md index 884db18142..813312df90 100644 --- a/docs/scorecard.md +++ b/docs/scorecard.md @@ -11,7 +11,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js | [Tools](#tools) | 36 | 9 | 0 | | | [Workspace and UI](#workspace-and-ui) | 15 | 6 | 2 | settings that do nothing: 10 of 186 (target 0) | | [Type](#type) | 5 | 5 | 0 | | -| [Automation](#automation) | 5 | 2 | 4 | 631 of 631 menu items live (100.0%) | +| [Automation](#automation) | 5 | 2 | 4 | 640 of 640 menu items live (100.0%) | | [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 30 of 30 crates; panic_hunt present | | [Distribution](#distribution) | 5 | 5 | 1 | | | [Open bugs](#open-bugs) | 31 | 1 | 0 | | @@ -241,7 +241,7 @@ Unread: `general.color_picker`, `workspace.auto_show_hidden_panels`, `workspace. | TYPE-218-2 | Paragraph direction (Auto/LTR/RTL) in the panel and options bar; visual RTL caret | partial | [#218](https://github.com/storytold/photocraft/issues/218) | Paragraph section (Window > Paragraph and Properties) and the options bar have Auto / Left-to-right / Right-to-left buttons setting the paragraph direction through type.setStyle; the options bar's choice is also the direction new type starts with (type_tool.rs direction_items; paragraph_direction_buttons_set_and_show_the_direction, options_bar_direction_sets_selected_layers_and_new_type). Still missing: visual RTL caret (the arrow keys move in logical order), and PSD doesn't store the direction (crates/text psd.rs neither reads nor writes it, so it reopens as Auto) | | TYPE-218-3 | Thai/Khmer/Indic fallback fonts; golden shaping tests for complex scripts and RTL | partial | [#218](https://github.com/storytold/photocraft/issues/218) | Fallback fonts are covered for Thai, Khmer, Lao, Myanmar (THAI_FAMILIES, KHMER_FAMILIES, LAO_FAMILIES, MYANMAR_FAMILIES in fonts.rs; #1909, #3259), the nine Indic scripts (INDIC_FAMILIES: Nirmala UI, Kohinoor and Sangam MN, Noto Sans) and Arabic and Hebrew. Still missing: per-script golden shaping tests against reference output (only smoke tests that an installed font shapes without .notdef, plus a bidi test) | | TYPE-218-4 | Variable font axis sliders from the font's axes; opsz follows the point size | done | [#218](https://github.com/storytold/photocraft/issues/218) | One slider per axis of the style's font in the Character section (Properties and Window > Character), setting type.setStyle variations; opsz follows the type size unless set (layout.rs variation_list); a style or weight resets the wght axis (#2985). PSD does not round-trip axis values yet | -| TYPE-218-5 | OpenType UI: Character panel buttons, Numerals and Stylistic Sets submenus | partial | [#218](https://github.com/storytold/photocraft/issues/218) | Type > OpenType toggles (type_extra_cmds.rs:512). Character panel (and the Properties Character section) has Photoshop's eight OpenType buttons: Standard Ligatures, Contextual Alternates, Discretionary Ligatures, Swash, Stylistic Alternates, Titling Alternates, Ordinals, Fractions, pressed while the feature is on at the selection and dispatching the type.openType.* commands (type_tool.rs opentype_row; character_panel_opentype_buttons_toggle_and_show_the_feature, #3752). Still missing: the Numerals and Stylistic Sets submenus, and greying out features the font lacks | +| TYPE-218-5 | OpenType UI: Character panel buttons, Numerals and Stylistic Sets submenus | partial | [#218](https://github.com/storytold/photocraft/issues/218) | Type > OpenType toggles (type_extra_cmds.rs). Character panel (and the Properties Character section) has Photoshop's eight OpenType buttons: Standard Ligatures, Contextual Alternates, Discretionary Ligatures, Swash, Stylistic Alternates, Titling Alternates, Ordinals, Fractions, pressed while the feature is on at the selection and dispatching the type.openType.* commands (type_tool.rs opentype_row; character_panel_opentype_buttons_toggle_and_show_the_feature, #3752). Type > OpenType > Numerals (Default, Lining, Oldstyle, Proportional, Tabular, and the four height×width combinations) landed 2026-11-03: each sets lnum/onum/pnum/tnum as a radio style on the selection or layer, round-trips .pcraft, and shows its checkmark from the style at the selection start. Still missing: the Stylistic Sets submenu, and greying out features the font lacks | | TYPE-218-6 | Manual pair kerning (Alt+arrows), optical kerning rendered, both round-trip PSD (#206) | done | [#218](https://github.com/storytold/photocraft/issues/218) | Alt+Left/Right at a collapsed caret kerns the pair (type_tool.rs kern_pair, 20 per step and 100 with Cmd; type_tool_alt_arrows_kern_the_pair). Optical kerning is computed from the glyph outlines in text/src/optical.rs and applied by layout.rs when the run's mode is Optical (optical_matches_photoshop, optical_kerning_tightens_open_pairs). Both modes and manual values round-trip through PSD (io/tests/it/psd_kerning.rs; the optical mode travels in Txt2, txt2_carries_optical_kerning) | | TYPE-218-7 | Warp Text dialog previews live and opens with the layer's current warp | done | [#218](https://github.com/storytold/photocraft/issues/218) | Type > Warp Text opens with the shown layer's warp, or None, never remembered values (filter_dialog.rs:503 warp_defaults; warp_text_dialog_tests.rs:80 warp_text_opens_with_the_type_layers_current_warp, :99 warp_text_opens_at_none_for_a_layer_without_warp, :108 remembered_warp_values_never_override_the_layers_warp). The dialog previews live without editing the document, Cancel leaves no step and OK is one undoable step (:138 warp_text_dialog_previews_the_warp_without_editing_the_document, :160 cancelling_warp_text_leaves_the_document_and_history_untouched, :179 confirming_warp_text_is_one_undoable_step); the reduced-proxy preview matches the full-size result (filter_dialog.rs:2150 warp_text_preview_matches_the_full_size_result_on_a_reduced_proxy) | | TYPE-218-8 | Text editing: select all, double/triple/quadruple-click selection, paste, with tests | done | [#218](https://github.com/storytold/photocraft/issues/218) | Like Photoshop, 2 clicks select the word, 3 the laid-out line (a column in vertical type), 4 the paragraph up to the hard return, 5 all text, and the next quick click starts over (#3493; type_tool.rs next_click_count, click_selection, multi_click). Tested through real canvas clicks in point, paragraph and vertical type, with paste replacing the selection and Cmd+A selecting all (type_tool_tests.rs multi_click_selects_word_line_paragraph_and_all_in_point_text, multi_click_separates_wrapped_lines_from_paragraphs, click_counts_cycle_and_restart, click_selection_without_layout_and_on_hostile_input, multi_click_without_a_session_does_nothing) | @@ -250,7 +250,7 @@ Unread: `general.color_picker`, `workspace.auto_show_hidden_panels`, `workspace. ## Automation -Menu wiring (`docs/parity-checklist.md`): 631 of 631 menu items live (100.0%). This counts dispatch, not behaviour. +Menu wiring (`docs/parity-checklist.md`): 640 of 640 menu items live (100.0%). This counts dispatch, not behaviour. | Id | Target | Status | Issue | Note | |---|---|---|---|---| diff --git a/scorecard/type.toml b/scorecard/type.toml index c119ac984d..24e5afe709 100644 --- a/scorecard/type.toml +++ b/scorecard/type.toml @@ -37,7 +37,7 @@ id = "TYPE-218-5" target = "OpenType UI: Character panel buttons, Numerals and Stylistic Sets submenus" status = "partial" issue = 218 -note = "Type > OpenType toggles (type_extra_cmds.rs:512). Character panel (and the Properties Character section) has Photoshop's eight OpenType buttons: Standard Ligatures, Contextual Alternates, Discretionary Ligatures, Swash, Stylistic Alternates, Titling Alternates, Ordinals, Fractions, pressed while the feature is on at the selection and dispatching the type.openType.* commands (type_tool.rs opentype_row; character_panel_opentype_buttons_toggle_and_show_the_feature, #3752). Still missing: the Numerals and Stylistic Sets submenus, and greying out features the font lacks" +note = "Type > OpenType toggles (type_extra_cmds.rs). Character panel (and the Properties Character section) has Photoshop's eight OpenType buttons: Standard Ligatures, Contextual Alternates, Discretionary Ligatures, Swash, Stylistic Alternates, Titling Alternates, Ordinals, Fractions, pressed while the feature is on at the selection and dispatching the type.openType.* commands (type_tool.rs opentype_row; character_panel_opentype_buttons_toggle_and_show_the_feature, #3752). Type > OpenType > Numerals (Default, Lining, Oldstyle, Proportional, Tabular, and the four height×width combinations) landed 2026-11-03: each sets lnum/onum/pnum/tnum as a radio style on the selection or layer, round-trips .pcraft, and shows its checkmark from the style at the selection start. Still missing: the Stylistic Sets submenu, and greying out features the font lacks" [[item]] id = "TYPE-218-6" From d9dc644db145f218836f021713efdb9d5dcde12b Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Tue, 3 Nov 2026 17:55:42 +0100 Subject: [PATCH 2/3] fix(ui): Roundness previews its radius within 1 px, and a held frame survives a factor change (#10474) (#11081) * fix(ui): Roundness previews its radius within 1 px too, and a held frame survives a factor change (#10474) Follow-up to #10524 from its last CodeRabbit review. - Roundness's disc reaches floor(r) pixels along an axis, so at 6 px and k = 4 the proxy radius 1.5 reached 1 proxy px: a 4 px preview for a 6 px result. The factor now keeps floor(r / k) * k within 1 px of floor(r), as Squareness already does with round (k = 3 at 6 px, k = 2 at 50 px). One whole-pixel function per mode replaces the special case. - A canvas test drives the worker across a factor change: the frame for k = 2 stays on the canvas, at its own size, until the k = 1 frame lands. Co-Authored-By: Claude Opus 5.5 * test(ui): a fractional Roundness radius previews closer at its chosen factor (#10474) CodeRabbit on #11081: only the factors were pinned. At 6.5 px the Roundness preview at the chosen k = 3 is compared with OK's result and must differ less than the k = 4 preview did. Co-Authored-By: Claude Opus 5.5 * fix(ui): a mid-drag frame for the previous proxy factor still reaches the canvas (#10474) CodeRabbit on #11081: the display gate keeps a held frame at any factor, but the mid-drag publish arm still required the same factor, so a frame finished for the factor the drag just left was dropped. It now uses same_target_at_any_scale too; a frame already exact for the dialog is still never displaced. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/canvas/filter_preview.rs | 11 +++++--- crates/ui-egui/src/canvas/tests.rs | 25 +++++++++++++++++++ crates/ui-egui/src/dialogs/filter_dialog.rs | 9 ++++--- .../src/dialogs/filter_dialog/tests.rs | 21 +++++++++++++--- 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/canvas/filter_preview.rs b/crates/ui-egui/src/canvas/filter_preview.rs index 0144390b46..3a6ee54d97 100644 --- a/crates/ui-egui/src/canvas/filter_preview.rs +++ b/crates/ui-egui/src/canvas/filter_preview.rs @@ -84,11 +84,14 @@ pub(crate) fn ensure_filter_preview(app: &mut PhotocraftApp, idx: usize, ctx: &e Ok(computed) if finished == request => publish_filter_preview(app, idx, finished, computed.result, computed.ms), // Mid-drag, a frame for the value the pointer has just left is what makes the // canvas follow the drag. Three things have to hold for it: it belongs to this - // preview, it has a frame to show (an empty one would blank a good preview), and - // it must not displace a frame that is already exact for the dialog, which is - // what a slider dragged out and back would otherwise make the canvas do. + // preview (at any proxy factor: it is drawn at its own, and a radius drag can move + // the factor, #10474), it has a frame to show (an empty one would blank a good + // preview), and it must not displace a frame that is already exact for the dialog, + // which is what a slider dragged out and back would otherwise make the canvas do. Ok(computed) - if finished.same_target(&request) && computed.result.is_some() && !app.filter_preview.as_ref().is_some_and(|p| p.key == request) => + if finished.same_target_at_any_scale(&request) + && computed.result.is_some() + && !app.filter_preview.as_ref().is_some_and(|p| p.key == request) => { publish_filter_preview(app, idx, finished, computed.result, computed.ms); } diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index 6bce89cc0d..73ef696976 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -371,6 +371,31 @@ fn drive_until(app: &mut PhotocraftApp, ctx: &egui::Context, what: &str, done: i } } +#[cfg(not(target_arch = "wasm32"))] +#[test] +fn a_held_preview_frame_stays_on_the_canvas_when_the_proxy_factor_changes() { + // #10474: Minimum and Maximum take their proxy factor from the radius, so a radius drag across + // a whole pixel changes `FilterPreviewKey::k`. The frame for the old factor stays on the + // canvas, drawn at its own factor, until the one for the new factor lands. + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 2400, "height": 2200})).unwrap(); + app.background_jobs = true; + app.ui.views.get_mut(0).expect("the new document's view").zoom = 0.25; + crate::filter_dialog::open(&mut app, "filter.other.maximum").unwrap(); + app.ui.dialogs[0].fields.insert("radius".into(), json!(6.0)); + let ctx = egui::Context::default(); + drive_until(&mut app, &ctx, "the first frame", |a| a.filter_preview.as_ref().is_some_and(|p| p.result.is_some())); + assert_eq!(app.filter_preview.as_ref().map(|p| p.key.k), Some(2), "6 px on a reduced document previews on the proxy"); + + // 1.5 px previews at full resolution: a new request at a new factor, computed on the worker. + app.ui.dialogs[0].fields.insert("radius".into(), json!(1.5)); + let (k, _, size) = ensure_filter_preview(&mut app, 0, &ctx).expect("the held frame stays on the canvas"); + assert_eq!((k, size), (2, [1200, 1100]), "drawn at its own factor"); + drive_until(&mut app, &ctx, "the full-resolution frame", |a| a.filter_preview.as_ref().is_some_and(|p| p.key.k == 1 && p.result.is_some())); + let (k, _, size) = ensure_filter_preview(&mut app, 0, &ctx).expect("the new frame"); + assert_eq!((k, size), (1, [2400, 2200])); +} + #[cfg(not(target_arch = "wasm32"))] #[test] fn a_preview_computed_mid_drag_reaches_the_canvas_and_then_converges() { diff --git a/crates/ui-egui/src/dialogs/filter_dialog.rs b/crates/ui-egui/src/dialogs/filter_dialog.rs index 08ce0f6ab1..f2e97a80e8 100644 --- a/crates/ui-egui/src/dialogs/filter_dialog.rs +++ b/crates/ui-egui/src/dialogs/filter_dialog.rs @@ -279,16 +279,17 @@ pub fn preview_factor(command: &str, params: &Value, k: u32) -> u32 { // Minimum and Maximum measure the radius in whole pixels (Squareness rounds it, Roundness // floors it, and 0 is the identity), so at k = 4 a typed 1.5 px became 0.375 = 0 proxy px and // the preview showed the untouched document while OK applied a real effect (#10474). Keep at - // least one proxy pixel of radius, and for Squareness the largest k whose rounded proxy radius, - // scaled back, is within 1 px of the one OK applies (6 px at k = 4 rounded to 2 proxy px, 8 px). + // least one proxy pixel of radius, and the largest k whose whole-pixel proxy radius, scaled + // back, is within 1 px of the one OK applies: Squareness at 6 px and k = 4 rounds 1.5 to 2 proxy + // px (8 px), and Roundness's disc reaches floor(1.5) = 1 proxy px along an axis (4 px). // A large radius still previews on a proxy: at full size Roundness costs O(radius) per pixel. if matches!(command, "filter.other.minimum" | "filter.other.maximum") { let Some(r) = params.get("radius").and_then(Value::as_f64).filter(|r| r.is_finite()) else { return k }; let r = r.clamp(0.2, 500.0); - let square = params.get("preserve").and_then(Value::as_str) != Some("roundness"); + let whole: fn(f64) -> f64 = if params.get("preserve").and_then(Value::as_str) == Some("roundness") { f64::floor } else { f64::round }; let fits = |d: u32| { let d = f64::from(d); - d <= r.floor() && (!square || ((r / d).round() * d - r.round()).abs() <= 1.0) + d <= r.floor() && (whole(r / d) * d - whole(r)).abs() <= 1.0 }; return (1..=k).rev().find(|&d| fits(d)).unwrap_or(1); } diff --git a/crates/ui-egui/src/dialogs/filter_dialog/tests.rs b/crates/ui-egui/src/dialogs/filter_dialog/tests.rs index c5013adc25..dcaa32ddbd 100644 --- a/crates/ui-egui/src/dialogs/filter_dialog/tests.rs +++ b/crates/ui-egui/src/dialogs/filter_dialog/tests.rs @@ -1047,16 +1047,29 @@ fn proxy_previews_scale_only_lengths() { assert_eq!(preview_factor("filter.pixelate.mosaic", &json!({"cellSize": "x"}), 4), 4); let (k, diff) = error("filter.pixelate.mosaic", json!({"cellSize": 10.0})); assert!(k == 2 && diff < 0.01, "Mosaic: {diff}"); + // Roundness at a fractional radius: at 6.5 px, k = 3 reaches floor(2.17) = 2 proxy px along an + // axis (6 px), where k = 4 reached floor(1.63) = 1 (4 px), so the chosen factor previews closer + // to what OK applies than k = 4 did (#10474). + for cmd in ["filter.other.minimum", "filter.other.maximum"] { + let p = json!({"radius": 6.5, "preserve": "roundness"}); + let (k, diff) = error(cmd, p.clone()); + let applied = preview_document(&doc, Some(bg), cmd, &p, 1).unwrap(); + let at_four = preview_document(&doc, Some(bg), cmd, &p, 4).unwrap(); + let four = mean_abs(&every_kth(&applied, 4), &every_kth(&at_four, 1)); + assert!(k == 3 && diff < four, "{cmd}: k = {k} differs by {diff}, k = 4 by {four}"); + } // Minimum and Maximum keep at least one proxy pixel of radius (#10474), and a large radius - // keeps a proxy instead of a full-size preview that costs minutes at radius 500. Squareness - // also keeps its rounded radius within 1 px of OK's: 6 px is 2 proxy px at k = 3 (6 px), not - // at k = 4 (8 px); 50 px is 17 at k = 3 (51 px), not 13 at k = 4 (52 px). + // keeps a proxy instead of a full-size preview that costs minutes at radius 500. Both keep + // their whole-pixel radius within 1 px of OK's. Squareness rounds: 6 px is 2 proxy px at k = 3 + // (6 px), not at k = 4 (8 px); 50 px is 17 at k = 3 (51 px), not 13 at k = 4 (52 px). Roundness's + // disc reaches floor(r) along an axis: 6 px is 2 at k = 3 (6 px), not 1 at k = 4 (4 px); 50 px + // is 25 at k = 2, not 12 at k = 4 or 16 at k = 3 (48 px). let factors = |cmd: &str, preserve: &str| { [0.2, 1.5, 2.5, 3.9, 6.0, 50.0, 500.0, 9999.0].map(|radius| preview_factor(cmd, &json!({"radius": radius, "preserve": preserve}), 4)) }; for cmd in ["filter.other.minimum", "filter.other.maximum"] { assert_eq!(factors(cmd, "squareness"), [1, 1, 2, 3, 3, 3, 4, 4], "{cmd} squareness"); - assert_eq!(factors(cmd, "roundness"), [1, 1, 2, 3, 4, 4, 4, 4], "{cmd} roundness"); + assert_eq!(factors(cmd, "roundness"), [1, 1, 2, 3, 3, 2, 4, 4], "{cmd} roundness"); assert_eq!(preview_factor(cmd, &json!({"radius": 6.0}), 4), 3, "{cmd}: Squareness is the default"); assert_eq!(preview_factor(cmd, &json!({"radius": "x"}), 4), 4, "{cmd}: a junk radius keeps the proxy"); } From d07684a379103df3523ceb4cd5210598303a9415 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Tue, 3 Nov 2026 17:55:50 +0100 Subject: [PATCH 3/3] fix(ui): Overscroll off keeps an image smaller than the window centred (#10488) (#11085) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(ui): Overscroll off keeps an image smaller than the window centred (#10488) With Tools › Overscroll off, an image smaller than the window stayed wherever zooming around the pointer left it, inside the window, so zooming out drifted it off centre. #1718 measured that on Photoshop 25.4, but two reports of Photoshop itself (#10488, #4799) say it stays centred with Overscroll off. The owner chose the centred behaviour: scrollbars::clamp_axis now centres an axis on which the image is no larger than the view; a larger image still can't leave its edges, and Overscroll on keeps the free view. Co-Authored-By: Claude Opus 5.5 * test(ui): Overscroll off centres a fitting rotated image (#10488) CodeRabbit on #11085: the rotated clamp path was only tested from an already-centred view. A 600 px square at 45 degrees, started off centre in a 900-point view, now ends with its screen bounds centred. Co-Authored-By: Claude Opus 5.5 * style(ui): keep the rotated centring test within rustfmt's width Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/canvas/scrollbars.rs | 58 ++++++++++++++++--------- docs/ui-parity.md | 1 + 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/crates/ui-egui/src/canvas/scrollbars.rs b/crates/ui-egui/src/canvas/scrollbars.rs index 375edc13b6..305e9c86d3 100644 --- a/crates/ui-egui/src/canvas/scrollbars.rs +++ b/crates/ui-egui/src/canvas/scrollbars.rs @@ -71,9 +71,13 @@ impl Span { } } -/// Clamp one axis of the view centre with Overscroll off, as Photoshop 25.4 does: an image larger -/// than the view can't leave its edges, and one smaller than the view stays inside it, where -/// zooming put it (zooming out around the pointer doesn't re-centre it; Fit on Screen does). +/// Clamp one axis of the view centre with Overscroll off: an image larger than the view can't +/// leave its edges, and one smaller than the view is centred in it, so zooming out around the +/// pointer keeps it in the middle (#10488, #4799). +/// +/// #1718 measured Photoshop 25.4 leaving a smaller image where zooming put it. Two reports of +/// Photoshop itself say it stays centred with Overscroll off, which is what turning Overscroll off +/// is asked for, so PhotoCraft centres it; Overscroll on keeps the free view. pub fn clamp_axis(center: f32, len: f32, size: f32, zoom: f32) -> f32 { if !(zoom.is_finite() && zoom > 0.0 && len.is_finite() && len > 0.0 && size.is_finite() && size > 0.0) { return center; @@ -82,9 +86,11 @@ pub fn clamp_axis(center: f32, len: f32, size: f32, zoom: f32) -> f32 { return len / 2.0; } let half = size / zoom / 2.0; - // Larger: the view stays within the image. Smaller: the image stays within the view. - let (a, b) = (half, len - half); - center.clamp(a.min(b), a.max(b)) + // Smaller than the view (or exactly its size): centred. Larger: the view stays within it. + if 2.0 * half >= len { + return len / 2.0; + } + center.clamp(half, len - half) } /// Apply Preferences › Tools › Overscroll (off) to `view` for a canvas of `size` points on a @@ -112,7 +118,7 @@ pub fn clamp_view_with_aspect(view: &mut View, size: egui::Vec2, ppp: f32, aspec if view.center[0].is_finite() { view.center[0] } else { w as f32 / 2.0 }, if view.center[1].is_finite() { view.center[1] } else { h as f32 / 2.0 }, ]; - let xf = crate::canvas::ViewXform { rect: egui::Rect::from_min_size(Pos2::ZERO, size), zoom, center, flip: false, rotation: view.rotation, aspect }; + let xf = crate::canvas::ViewXform { rect: Rect::from_min_size(Pos2::ZERO, size), zoom, center, flip: false, rotation: view.rotation, aspect }; let image = xf.image_bounds(view.doc_size); if !image.is_finite() { return false; @@ -309,12 +315,13 @@ mod tests { assert_eq!(clamp_axis(-400.0, 1000.0, 500.0, 1.0), 250.0); assert_eq!(clamp_axis(4000.0, 1000.0, 500.0, 1.0), 750.0); assert_eq!(clamp_axis(600.0, 1000.0, 500.0, 1.0), 600.0); - // Smaller than the view (2500 doc px of view for 1000 of image): it stays where it is - // while it is inside the view, and is pushed back in at the edges. - assert_eq!(clamp_axis(-90.0, 1000.0, 500.0, 0.2), -90.0); - assert_eq!(clamp_axis(-400.0, 1000.0, 500.0, 0.2), -250.0, "the image's right edge on the view's"); - assert_eq!(clamp_axis(1400.0, 1000.0, 500.0, 0.2), 1250.0, "its left edge on the view's"); + // Smaller than the view (2500 doc px of view for 1000 of image): centred, wherever zooming + // around the pointer left it (#10488). + for center in [-90.0, -400.0, 300.0, 1400.0] { + assert_eq!(clamp_axis(center, 1000.0, 500.0, 0.2), 500.0, "{center}"); + } assert_eq!(clamp_axis(500.0, 1000.0, 1000.0, 1.0), 500.0, "exactly the view's size: centred"); + assert_eq!(clamp_axis(10.0, 1000.0, 1000.0, 1.0), 500.0); let mut v = View { zoom: 1.0, center: [-500.0, 20.0], @@ -332,6 +339,20 @@ mod tests { assert!(!clamp_view(&mut v, vec2(500.0, 400.0), 1.0), "stable: no repaint loop"); } + #[test] + fn overscroll_off_centres_a_fitting_rotated_image() { + // 600 px at 45 degrees is about 849 points across, so it fits a 900-point view both ways. + // Started off centre, the clamp centres its screen-space bounds in the view (#10488). + let mut v = View { zoom: 1.0, center: [100.0, 450.0], doc_size: [600, 600], rotation: 45.0, ..Default::default() }; + let size = vec2(900.0, 900.0); + assert!(clamp_view_with_aspect(&mut v, size, 1.0, 1.0)); + let rect = Rect::from_min_size(Pos2::ZERO, size); + let xf = crate::canvas::ViewXform { rect, zoom: 1.0, center: v.center, flip: false, rotation: v.rotation, aspect: 1.0 }; + let c = xf.image_bounds(v.doc_size).center(); + assert!((c - xf.rect.center()).length() < 1e-2, "centred: {c:?}"); + assert!(!clamp_view_with_aspect(&mut v, size, 1.0, 1.0), "stable: no repaint loop"); + } + #[test] fn hostile_numbers_are_harmless() { for z in [0.0, -1.0, f32::NAN, f32::INFINITY] { @@ -516,16 +537,13 @@ mod tests { } else { assert!((x - w / 2.0).abs() < 1e-3, "clamped to the left edge: {x}"); } - // Zoomed out below fit (Photoshop): the image is not re-centred, it stays where it - // is while it fits in the view, and is pushed back in at the view's edge. + // Zoomed out below fit: the image is centred in the view on both axes, wherever + // the zoom left it (#10488). set_view(&mut h, 0.1, [-50.0, 9000.0]); if !overscroll { - let r = h.state().last_canvas_rect; - let (hw, hh) = (r.width() / 0.1 / 2.0, r.height() / 0.1 / 2.0); - let c = view(&h).center; - assert_eq!(c[0], -50.0, "inside the view: left alone"); - assert!((c[1] - hh).abs() < 1e-2, "pushed back in: the image's top on the view's: {c:?}"); - assert!(c[0] - hw <= 0.0 && c[0] + hw >= 2000.0 && c[1] - hh <= 0.0 && c[1] + hh >= 1500.0, "{c:?}"); + assert_eq!(view(&h).center, [1000.0, 750.0], "centred"); + } else { + assert_eq!(view(&h).center, [-50.0, 9000.0], "overscroll on: the view is free"); } } } diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 07192e710f..3dbec47b9f 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -350,4 +350,5 @@ Paragraph; the rest open as in-app floating windows. | 2026-10-15 | minor | ⇧⌥ blend mode letters work while a Free Transform box is open, without picking a tool | | 2026-10-14 | minor | Mode dropdowns for Clone Stamp, Pattern Stamp, History Brush, Healing and Paint Bucket; the blend mode keys reach them, and tools without a blend mode (not Dodge, Burn or Sponge) pass the keys to the layers | | 2026-10-16 | minor | Hand tool: ⌘ held zooms in and ⌥ zooms out, as in Photoshop (#6434) | +| 2026-11-03 | minor | Tools › Overscroll off centres an image smaller than the window on that axis, so zooming out around the pointer keeps it in the middle instead of where the zoom left it (#10488, #4799); this overrides #1718's Photoshop 25.4 measurement on the strength of two Photoshop users' reports, and Overscroll on keeps the free view; no percentage changed | | 2026-10-31 | minor | Ctrl + Alt + wheel over the canvas zooms like ⌥ + wheel (#10488): ×1.1 a notch around the pointer with Animated Zoom off, eased with it on, and it follows the ⌥ swap when General › Zoom with Scroll Wheel is on. Windows and Linux report a held Ctrl as ctrl AND command (`wheel_nav::alt_gesture`), macOS ⌘ + ⌥ is left alone, plain ⌘/Ctrl + wheel still scrolls sideways; the combination was a dead gesture, so nothing existing was replaced. The centred-zoom half of the report is still open: `canvas.rs:1737` re-clamps the view centre each frame only when Tools › Overscroll is off (it is on by default), so the drift the reporter saw is more likely the deliberate nearest-image-point anchor (`view_xform.rs:239`, #3720) or Zoom Clicked Point to Center, which needs its own repro; no percentage changed |