From 393fe5dc802c9bba52c48ff13f692f1473e2a12f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 12:16:59 -0800 Subject: [PATCH] OpenType: the panel menu has a Stylistic Sets submenu The OpenType panel menu gains a Stylistic Sets submenu after Reset OpenType Features. It lists the same sets, labels and checks as the panel's Stylistic Sets button, and a set chosen there turns on or off for the characters the panel acts on in one undo step, keeping their other features. The submenu is disabled with no text selected or when the font offers no sets. --- crates/ui-egui/src/panels/opentype.rs | 100 +++++++++++++++++++++----- docs/target-app-parity.md | 1 + 2 files changed, 85 insertions(+), 16 deletions(-) diff --git a/crates/ui-egui/src/panels/opentype.rs b/crates/ui-egui/src/panels/opentype.rs index fe144edbf9..4cfcb27e89 100644 --- a/crates/ui-egui/src/panels/opentype.rs +++ b/crates/ui-egui/src/panels/opentype.rs @@ -1,7 +1,7 @@ //! OpenType panel: per-character OpenType features (ligatures, alternates, swashes, small caps, -//! ordinals, fractions, figure style, position, and with the East Asian options the menu's H or V -//! Style and Roman Italics) for the selected text (every frame of each selected threaded story) or -//! the Type tool's selected characters. +//! ordinals, fractions, figure style, position, stylistic sets from the panel or its menu, and with +//! the East Asian options the menu's H or V Style and Roman Italics) for the selected text (every +//! frame of each selected threaded story) or the Type tool's selected characters. use egui::Ui; use serde_json::json; @@ -257,18 +257,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { change = Some(Change::Toggle(flag, shown != Some(true))); } } - // The font, not the text, decides which numbered sets can be offered. Each set is an - // independent feature, so the menu permits several at once. A font's own label wins over - // the numbered fallback. See the public Stylistic Sets help page. A set is checked when every - // character has it. - let sets: Vec<(StylisticSet, Flag, bool)> = offered_sets(&st) - .into_iter() - .map(|set| { - let flag = Flag::Extra(EXTRA_FEATURES[usize::from(set.number - 1)]); - let on = shown_flag(app, flag) == Some(true); - (set, flag, on) - }) - .collect(); + let sets = set_entries(app, &st); ui.add_enabled_ui(!sets.is_empty(), |ui| { ui.menu_button(tl!("Stylistic Sets"), |ui| { widgets::menu_scroll(ui, |ui| { @@ -300,6 +289,22 @@ fn tracking_drops_ligatures(app: &VectorcraftApp) -> bool { }) } +/// The Stylistic Sets entries of the panel's button and of the panel menu's submenu: each set the +/// font `st` names offers, the feature it turns on and off, and whether it is checked. The font, +/// not the text, decides which numbered sets can be offered. Each set is an independent feature, +/// so the menu permits several at once. A font's own label wins over the numbered fallback. See +/// the public Stylistic Sets help page. A set is checked when every character has it. +fn set_entries(app: &VectorcraftApp, st: &CharStyle) -> Vec<(StylisticSet, Flag, bool)> { + offered_sets(st) + .into_iter() + .map(|set| { + let flag = Flag::Extra(EXTRA_FEATURES[usize::from(set.number - 1)]); + let on = shown_flag(app, flag) == Some(true); + (set, flag, on) + }) + .collect() +} + /// The stylistic sets of the font `st` names. A font that is not available offers none, rather than /// the sets of the face drawn in its place. fn offered_sets(st: &vectorcraft_doc::CharStyle) -> Vec { @@ -345,10 +350,31 @@ fn east_asian_items() -> [Toggle; 2] { } pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { - let has = text_style(app).is_some(); + let style = text_style(app); + let has = style.is_some(); if menu_item(ui, tl!("Reset OpenType Features"), has, false) { set(app, OtFeatures::default()); } + // Stylistic Sets: the sets, labels and checks of the panel's Stylistic Sets button. A set chosen + // while only some characters have it turns it on for all of them. Disabled with no text or when + // the font offers no sets. + let sets = style.map(|(st, _)| set_entries(app, &st)).unwrap_or_default(); + let mut toggle = None; + ui.add_enabled_ui(!sets.is_empty(), |ui| { + // Indented like the items beside it (their check column). + ui.menu_button(format!(" {}", tl!("Stylistic Sets")), |ui| { + widgets::menu_scroll(ui, |ui| { + for (set, flag, on) in &sets { + if widgets::menu_item_name(ui, &set_label(set), true, *on) { + toggle = Some(Change::Toggle(*flag, !on)); + } + } + }); + }); + }); + if let Some(c) = toggle { + edit(app, c); + } if app.session.prefs.show_east_asian_options { ui.separator(); // Checked when every character it changes has it; chosen then, it turns it off. @@ -767,6 +793,48 @@ mod tests { assert_eq!(undo_steps(&app), undo + 1); } + /// The panel menu's Stylistic Sets submenu lists the font's sets with the labels of the panel's + /// Stylistic Sets button. Chosen, a set turns on for the selected type in one undo step and + /// shows checked, keeping the other features; chosen again, it turns off. With no text + /// selected the submenu is disabled and does not open. + #[test] + fn the_panel_menu_stylistic_sets_submenu_turns_sets_on_and_off() { + let mut app = selected_text(); + let Some((st, _)) = text_style(&app) else { panic!("no text style") }; + let sets = set_entries(&app, &st); + // Builds without the bundled fonts have no face that offers sets. + let Some((first, _, _)) = sets.first() else { return }; + let (label, tag) = (set_label(first), EXTRA_FEATURES[usize::from(first.number - 1)]); + set(&mut app, OtFeatures { small_caps: true, ..Default::default() }); + let entry = |t: &str| t.trim_start_matches(['✓', ' ']).to_string(); + // Opens the submenu in a fresh context and returns the drawn text of `label`'s entry and + // its rect, if the submenu shows it. + let open = |app: &mut VectorcraftApp, ctx: &egui::Context| { + crate::theme::install_fonts(ctx); + let texts = super::super::tests_appearance::frame_events(ctx, app, vec![], menu); + let sub = super::super::tests_appearance::text_rect(&texts, " Stylistic Sets"); + super::super::tests_appearance::click(ctx, app, sub.center(), menu); + let texts = super::super::tests_appearance::frame_events(ctx, app, vec![], menu); + texts.into_iter().find(|(t, _)| entry(t) == label && t != " Stylistic Sets") + }; + let ctx = egui::Context::default(); + let Some((text, at)) = open(&mut app, &ctx) else { panic!("{label} missing from the submenu") }; + assert!(!text.starts_with('✓'), "{text:?}"); + let undo = undo_steps(&app); + super::super::tests_appearance::click(&ctx, &mut app, at.center(), menu); + assert_eq!(undo_steps(&app), undo + 1); + let on = text_style(&app).unwrap().0.features; + assert!(on.iter().any(|f| f == tag) && on.iter().any(|f| f == "smcp"), "{on:?}"); + let ctx = egui::Context::default(); + let Some((text, at)) = open(&mut app, &ctx) else { panic!("{label} missing from the reopened submenu") }; + assert!(text.starts_with('✓'), "{text:?}"); + super::super::tests_appearance::click(&ctx, &mut app, at.center(), menu); + assert_eq!(text_style(&app).unwrap().0.features, ["smcp"]); + app.session.execute("select.set", &json!({"ids": []})).unwrap(); + let ctx = egui::Context::default(); + assert!(open(&mut app, &ctx).is_none(), "the submenu opened with no text selected"); + } + /// H or V Style and Roman Italics are in the panel menu with the East Asian options only. #[test] fn kana_style_and_roman_italics_show_with_the_east_asian_options() { diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index e9fc9a6820..d8327c0153 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1533,6 +1533,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur With a Type tool and exactly one character selected, the canvas shows that character's alternate glyphs in a row beside it, and a click on one replaces the character's glyph, as [Replace characters with alternate glyphs](https://helpx.adobe.com/illustrator/desktop/design-with-text/special-characters-glyphs/replace-characters-with-alternate-glyphs.html) describes ("Replace a character with on-canvas alternate glyphs"). The row shows at most five alternates, and an arrow at its end opens the Glyphs panel on Alternates for Current Selection when the character has more, as the [reference manual](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=479) describes. A click runs the command the panel's double-click runs, as one undo step, so a letter of an Arabic word keeps the word joined. These rules are VectorCraft's own: the row leaves out the glyph the character is drawn with and puts the default glyph first for a character drawn with an alternate; it stands under a character of horizontal type and on the right of a character of vertical type, or on the other side when the canvas ends there or the Contextual Task Bar is there; Preferences › Type › Show Character Alternates (`showCharacterAlternates`, on by default) turns it off. Tests: `canvas::alternates_bar::tests`, `tests::prefs::show_character_alternates_preference_is_on_by_default_and_saved`. With an OpenType font in the Glyphs panel, the Show menu and the panel menu list the font's glyph categories after Alternates for Current Selection, and choosing one restricts the grid to the glyphs of that kind, as the [Glyphs panel overview](https://helpx.adobe.com/illustrator/desktop/design-with-text/special-characters-glyphs/glyphs-panel-overview.html) describes. The categories are Ligatures, Swash, Stylistic Alternates, each stylistic set by the font's name for it (else Set N), Small Caps, Ornaments, Fractions and Figures, each listed only when the font's `GSUB` features give it glyphs; which features make up each category and their order are VectorCraft's own. A font without the chosen category shows Entire Font. `text.glyphCategories` lists them for agents. Tests: `fontdb::gsub::tests` in the text crate, `panels::glyphs::tests::the_show_menu_lists_the_fonts_opentype_categories`, `tests::fontlist::glyph_categories_list_the_glyphs_of_each_kind_of_feature`. The OpenType panel's Stylistic Sets menu offers `ss01`–`ss20` sets present in the selected text's font, using the font's custom labels when available and numbered labels otherwise. Sets can be combined and deselected individually. With mixed fonts, the menu shows the first selected character's font's sets and applies the feature tag to all selected text; a font without that set draws unchanged. The mixed-font rule is a VectorCraft design choice. Behavior reference: [Add stylistic sets to selected text](https://helpx.adobe.com/illustrator/desktop/design-with-text/special-characters-glyphs/add-stylistic-sets-to-selected-text.html) and the [OpenType specification](https://learn.microsoft.com/en-us/typography/opentype/spec/features_pt). + The OpenType panel menu has a Stylistic Sets submenu after Reset OpenType Features, with the same sets, labels and checks as the panel's Stylistic Sets button; a set chosen there turns on or off for the characters the panel acts on in one undo step, keeping their other features, and the submenu is disabled with no text selected or when the font offers no sets. The 2019 user guide ([the help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf)) has stylistic sets chosen from the OpenType panel menu. The submenu's place in the menu is VectorCraft's own. Tests: `panels::opentype::tests::the_panel_menu_stylistic_sets_submenu_turns_sets_on_and_off`. With Show East Asian Options on, the OpenType panel menu has H or V Style and Roman Italics, as [Format East Asian characters](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html) describes. H or V Style sets the feature tag `hkna`, which draws kana with the forms the font makes for horizontal type, and with `vkna` for vertical type in vertical type; Roman Italics sets `ital`, the font's italic forms of half-width alphanumerics ([OpenType feature list](https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist)). Each is checked when every selected character has it and turns it on or off for all of them in one undo step; character styles carry both in OpenType Features. Tests: `panels::opentype::tests::kana_style_and_roman_italics_turn_on_and_off`, `features::tests::kana_style_and_roman_italics_are_kept_and_shaped`. `text.setStyle {stroke, strokeWidth}` sets the character stroke's color and weight of the selected type or of a range of its characters (the weight in document points, as `stroke.set` sets it), in the same undo step as the command's other changes. Tests: `tests::textedit::set_style_sets_the_character_stroke`. - **Paragraph alignment:** the shared Paragraph/Properties alignment row leaves every button unselected when the paragraphs it acts on differ. Auto resolves per paragraph; choosing an alignment uses the existing command. Headless paragraph_mixed_alignment_* regressions exercise mixed → Center → Undo, caret/uniform states, Unicode range boundaries, Auto/direction, split runs and grouped text. These regressions and full integration CI pass. Original captures confirm mixed → Center → Undo in the existing alignment-button layout. The [public Paragraph panel guide](https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/paragraph-panel-overview.html) lists the seven controls, but does not specify mixed-state rendering. Other paragraph fields remain outside this change; scores and hours unchanged.