From 7703c42c31d4be27ba9a09e712a84eb969488adc Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 15:08:28 -0800 Subject: [PATCH 1/2] OpenType: Proportional Metrics in the panel menu with the East Asian options With Show East Asian Options on, the OpenType panel menu has a Proportional Metrics item before H or V Style. The help page (https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html) lists it among the OpenType panel options that this setting shows. The item sets the proportionalMetrics character attribute that the Character panel menu's item sets (palt in horizontal type, vpal in vertical type), through text.setFormat for selected type and text.setRangeStyle while the Type tool edits text. It is checked when every character it changes has the attribute, read like H or V Style and Roman Italics (at a caret, every character of the text), and a click turns it on for all of them, or off when checked, in one undo step. It is disabled with no type selected. Its place in the menu and the check rule are VectorCraft's own. Docs: docs/target-app-parity.md, docs/type-parity.md, docs/mcp.md. --- crates/ui-egui/src/panels/opentype.rs | 124 ++++++++++++++++++++++++-- docs/mcp.md | 5 +- docs/target-app-parity.md | 1 + docs/type-parity.md | 1 + 4 files changed, 125 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/panels/opentype.rs b/crates/ui-egui/src/panels/opentype.rs index 4cfcb27e89..e52c852afb 100644 --- a/crates/ui-egui/src/panels/opentype.rs +++ b/crates/ui-egui/src/panels/opentype.rs @@ -1,7 +1,8 @@ //! OpenType panel: per-character OpenType features (ligatures, alternates, swashes, small caps, //! 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. +//! the East Asian options the menu's Proportional Metrics, 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; @@ -123,19 +124,24 @@ fn shown_figure(app: &VectorcraftApp) -> Option { /// threaded story, the command styles all the text ([`run_features`]), so every character of it /// counts, as in [`edit`]. fn shown_flag(app: &VectorcraftApp, flag: Flag) -> Option { - let on = |s: &CharStyle| flag.get(&OtFeatures::from_tags(s.features.iter().map(String::as_str))); + shown(app, |s| flag.get(&OtFeatures::from_tags(s.features.iter().map(String::as_str)))) +} + +/// Whether `on` holds for every character a menu item changes (`Some(true)`), for none of them +/// (`Some(false)`), or only for some (`None`), read as [`shown_flag`] reads a feature. +fn shown(app: &VectorcraftApp, on: impl Fn(&CharStyle) -> bool) -> Option { if let Some(mut runs) = whole_text_runs(app) { // A run with no text, such as an empty frame's, counts only when no run has text. if runs.iter().any(|r| !r.text.is_empty()) { runs.retain(|r| !r.text.is_empty()); } let Some(first) = runs.first() else { - return shared(app, on); + return shared(app, &on); }; let v = on(&first.style); return runs.iter().all(|r| on(&r.style) == v).then_some(v); } - shared(app, on) + shared(app, &on) } /// The runs the panel's commands style as a whole while the Type tool edits text: those of every @@ -378,6 +384,14 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { if app.session.prefs.show_east_asian_options { ui.separator(); // Checked when every character it changes has it; chosen then, it turns it off. + // Proportional Metrics: full-width glyphs on the font's proportional widths (`palt`, `vpal`), + // the character attribute the Character panel menu's item sets. + let proportional = shown(app, |s| s.proportional_metrics) == Some(true); + if menu_item(ui, tl!("Proportional Metrics"), has, proportional) + && let Err(e) = super::character::run_format(app, json!({"proportionalMetrics": !proportional})) + { + app.ui.status = e; + } for (label, flag) in east_asian_items() { let on = shown_flag(app, flag) == Some(true); if menu_item(ui, label, has, on) { @@ -957,4 +971,104 @@ mod tests { assert!(runs.iter().all(|(_, f)| !f.as_array().is_some_and(|f| f.iter().any(|x| x == tag))), "{label}: {runs:?}"); } } + + /// The text, Proportional Metrics and features of each run of `id`. + fn metrics_runs(app: &VectorcraftApp, id: &Value) -> Vec<(String, bool, Vec)> { + let Some(id) = id.as_u64() else { panic!("no id: {id}") }; + match &app.session.active().unwrap().doc.node(NodeId(id)).unwrap().kind { + NodeKind::Text(t) => t.runs.iter().map(|r| (r.text.clone(), r.style.proportional_metrics, r.style.features.clone())).collect(), + _ => panic!("not text"), + } + } + + /// The drawn text and rect of the panel menu's `label` item. + fn menu_row(ctx: &egui::Context, app: &mut VectorcraftApp, label: &str) -> (String, egui::Rect) { + let texts = super::super::tests_appearance::frame_events(ctx, app, vec![], menu); + texts.into_iter().find(|(t, _)| t.trim_start_matches(['✓', ' ']) == label).unwrap_or_else(|| panic!("{label} missing")) + } + + /// Proportional Metrics is in the panel menu with the East Asian options only, before H or V + /// Style, and with no type selected it is disabled: a click changes nothing. + #[test] + fn proportional_metrics_shows_with_the_east_asian_options() { + let mut app = selected_text(); + assert!(!crate::tests_labels::painted_text(&mut app, menu).contains("Proportional Metrics")); + app.session.prefs.show_east_asian_options = true; + let text = crate::tests_labels::painted_text(&mut app, menu); + let (Some(metrics), Some(kana)) = (text.find("Proportional Metrics"), text.find("H or V Style")) else { panic!("{text}") }; + assert!(metrics < kana, "{text}"); + app.session.execute("select.set", &json!({"ids": []})).unwrap(); + let ctx = egui::Context::default(); + let (text, at) = menu_row(&ctx, &mut app, "Proportional Metrics"); + 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, "no text: nothing changes"); + } + + /// With the Type tool's characters only partly set, Proportional Metrics shows unchecked; + /// chosen, it turns on for every selected character in one undo step, each run keeping its + /// features, and shows checked; chosen again, it turns off in one undo step. + #[test] + fn proportional_metrics_turns_on_and_off_for_a_mixed_range() { + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.session.prefs.show_east_asian_options = true; + app.session.execute("file.new", &json!({"width": 300, "height": 200})).unwrap(); + app.session.select_tool("type", Default::default()).unwrap(); + let id = app.session.execute("text.create", &json!({"x": 10, "y": 40, "text": "かなAB"})).unwrap()["id"].clone(); + let first = json!({"id": id, "start": 0, "end": 3, "features": ["smcp"], "proportionalMetrics": true}); + app.session.execute("text.setRangeStyle", &first).unwrap(); + app.session.apply_actions(vec![vectorcraft_tools::Action::Notify("text.editNew".into())]).unwrap(); + // "かなAB" is 8 bytes. + app.session.set_tool_option("select", &json!({"start": 0, "end": 8})); + let ctx = egui::Context::default(); + let (text, at) = menu_row(&ctx, &mut app, "Proportional Metrics"); + 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 runs = metrics_runs(&app, &id); + assert!(runs.iter().all(|(_, on, _)| *on), "{runs:?}"); + assert_eq!(runs.iter().map(|(t, _, f)| (t.as_str(), f.clone())).collect::>(), [("か", vec!["smcp".to_string()]), ("なAB", vec![])]); + let (text, at) = menu_row(&ctx, &mut app, "Proportional Metrics"); + assert!(text.starts_with('✓'), "{text:?}"); + super::super::tests_appearance::click(&ctx, &mut app, at.center(), menu); + assert_eq!(undo_steps(&app), undo + 2); + let runs = metrics_runs(&app, &id); + assert!(runs.iter().all(|(_, on, f)| !*on && (f.is_empty() || *f == ["smcp"])), "{runs:?}"); + } + + /// With the Selection tool, Proportional Metrics turns on for the whole selected object. At a + /// Type tool caret after a character that has it while the rest of the text does not, the item + /// reads every character the command styles at a caret (all of them): it shows unchecked, and + /// choosing it turns it on for the whole text. + #[test] + fn proportional_metrics_reaches_a_selected_object_and_the_text_at_a_caret() { + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.session.prefs.show_east_asian_options = true; + app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap(); + let id = app.session.execute("text.create", &json!({"x": 10, "y": 40, "text": "かなAB"})).unwrap()["id"].clone(); + app.session.execute("select.set", &json!({"ids": [id]})).unwrap(); + let ctx = egui::Context::default(); + let at = menu_row(&ctx, &mut app, "Proportional Metrics").1; + super::super::tests_appearance::click(&ctx, &mut app, at.center(), menu); + assert!(metrics_runs(&app, &id).iter().all(|(_, on, _)| *on), "{:?}", metrics_runs(&app, &id)); + + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.session.prefs.show_east_asian_options = true; + app.session.execute("file.new", &json!({"width": 300, "height": 200})).unwrap(); + app.session.select_tool("type", Default::default()).unwrap(); + let id = app.session.execute("text.create", &json!({"x": 10, "y": 40, "text": "かなAB"})).unwrap()["id"].clone(); + app.session.execute("text.setRangeStyle", &json!({"id": id, "start": 0, "end": 3, "proportionalMetrics": true})).unwrap(); + app.session.apply_actions(vec![vectorcraft_tools::Action::Notify("text.editNew".into())]).unwrap(); + // The caret after "か", whose style the next typed character takes. + app.session.set_tool_option("select", &json!({"start": 3, "end": 3})); + assert_eq!(text_editing(&app).map(|(_, a, b)| (a, b)), Some((3, 3))); + let ctx = egui::Context::default(); + let (text, at) = menu_row(&ctx, &mut app, "Proportional Metrics"); + assert!(!text.starts_with('✓'), "{text:?}"); + super::super::tests_appearance::click(&ctx, &mut app, at.center(), menu); + let runs = metrics_runs(&app, &id); + assert!(runs.iter().all(|(_, on, _)| *on), "{runs:?}"); + } } diff --git a/docs/mcp.md b/docs/mcp.md index e7abf476a9..d7322cd219 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -12405,7 +12405,10 @@ a font without vertical metrics keeps its cells. Line-end Punctuation Half Width punctuation `palt` or `vpal` re-spaced (the opening bracket at a line's start, consecutive punctuation, the closing mark at a line's end); punctuation left full width is trimmed as before. With automatic kerning the font's kerning for the re-spaced glyphs comes too: `apkn` with `palt`, and `vkrn` and `vapk` with `vpal` (vertical type is otherwise -not kerned). Off by default and saved only when on. One undo step. +not kerned). Off by default and saved only when on. One undo step. With Show East Asian Options on, the Character +panel menu and the OpenType panel menu ([the help page](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html)) +each have a Proportional Metrics item that sends this attribute; the OpenType panel's item is checked when every +character it changes has it. ```json {"name":"run_command","arguments":{"command":"text.setFormat","params":{"proportionalMetrics":true}}} diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 57ac87a396..676106a205 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1765,6 +1765,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur 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`. + With Show East Asian Options on, the OpenType panel menu also has Proportional Metrics, before H or V Style; [the help page](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html) lists it among the OpenType panel options that this setting shows. It sets the `proportionalMetrics` character attribute that the Character panel menu's item sets (`palt` in horizontal type, `vpal` in vertical type), through `text.setFormat` for selected type and `text.setRangeStyle` while the Type tool edits text. It is checked when every character it changes has the attribute (at a Type tool caret, every character of the text), and choosing it turns the attribute on for all of them, or off when it is checked, in one undo step, keeping their other attributes; with no type selected it is disabled. Its place in the menu and the check rule are VectorCraft's own. Tests: `panels::opentype::tests::proportional_metrics_turns_on_and_off_for_a_mixed_range`, `panels::opentype::tests::proportional_metrics_reaches_a_selected_object_and_the_text_at_a_caret`. `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. For Auto Size area type in columns, the bisection for the frame's height runs on the lines of the one-column layout, and its result is checked with at most two layouts of the columns. When the text wraps around objects or does not fit the one-column layout, or when the check fails, the columns are laid out at every step of the bisection, as before. Typing at the start of a story of 50,000 characters in 2 columns took 1,670 ms a keystroke and now takes 292 ms (release build, `auto_height_in_columns_typing_timing`). diff --git a/docs/type-parity.md b/docs/type-parity.md index 111ee5d838..6855ba364b 100644 --- a/docs/type-parity.md +++ b/docs/type-parity.md @@ -35,6 +35,7 @@ against Illustrator's public documentation; **estimated** unless noted. | OpenType panel, Glyphs panel, alternates | done | Highlight Alternate Glyphs preference (#394, off by default) paints pink behind OpenType substitutions on screen when on (required shaping such as Arabic joining forms and the lam-alef ligature, including a lam-alef older fonts file under `liga`, is not highlighted; an optional feature that changes the ligature is); stylistic sets ss01–ss20, stylistic and titling alternates, proportional and lining figures, superscript and subscript are character-style features (`text.setStyle {features}`, #1607); the OpenType panel's Position menu sets superscript, subscript, numerator or denominator glyphs (`sups`, `subs`, `numr`, `dnom`). The OpenType panel's Stylistic Sets menu lists the selected font's `ss01`–`ss20` features, using a font-supplied name where available and `Set N` otherwise; several sets can be active, and selecting an active one removes it. For a mixed-font selection it uses the first selected character's font, a VectorCraft design choice ([public help](https://helpx.adobe.com/illustrator/desktop/design-with-text/special-characters-glyphs/add-stylistic-sets-to-selected-text.html), [OpenType feature specification](https://learn.microsoft.com/en-us/typography/opentype/spec/features_pt)). The Glyphs panel highlights the character selected with the Type tool (a range's first character, else the one before the caret) and scrolls it into view as the selection moves (#4908; `panels::glyphs` tests); its Show menu lists Unicode ranges and Alternates for Current Selection, the selected character's alternate glyphs from the font's `GSUB` table. A double-click applies the OpenType feature that draws a variant to that character alone, or uses a glyph choice when no supported feature draws it; see the Glyphs panel row below for Entire Font and the joining limits. A grid cell whose glyph has alternates shows a triangle in its lower right corner; a click on it opens a pop-up of that glyph and its alternates in the font's order, and a pick inserts the character at the caret drawn with that glyph, or draws the selected character with it, in one undo step; in Entire Font a glyph no character maps has the triangle too, and a pick goes on the selected character as a double-click on that glyph's cell does ([CS6 reference, Glyphs panel overview](https://web.archive.org/web/20220911143322/https://helpx.adobe.com/pdf/cs6/illustrator_reference.pdf#page=373)); the triangle's size and the pop-up's eight columns and six rows are VectorCraft's own (`panels::glyphs` tests `a_cells_corner_triangle_opens_its_alternates_and_a_pick_inserts_one`, `a_pick_replaces_the_selected_character_and_says_why_when_it_cannot`, `a_pick_that_cannot_be_drawn_leaves_the_text_as_it_was`, `an_unencoded_glyphs_corner_triangle_applies_its_alternates_to_the_selection`; `has_alternates_follows_the_listed_substitutions` in the text crate) | | Glyphs panel: alternates as OpenType feature values, unencoded glyphs | done | #5514, 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 (Show › Alternates For Current Selection; replace the selected character by double-clicking the glyph). A character-style feature takes a value (`"salt=2"`, the font's alternate number; `ss01`–`ss20`, `swsh`, `titl` and `aalt` too) in `features` and `featureChanges`, in SVG `font-feature-settings` (`"salt" 2`) and in native files as the plain string. Show › Entire Font applies an unencoded glyph the same way when it is an alternate of the selected character in its word, applies one no feature reaches (`A.salt` in a font with no `salt`) to the selected character as a glyph choice (it may not join), and dims the others with the reason in the tooltip (e.g. `yehfarsi.fina.alt2 belongs to ی (U+06CC) at the end of a word; your selection is ي (U+064A)`); an Arabic presentation form picked there inserts its letter so the word joins. Runs that differ only in their features shape as one piece of text, each run's features over its own characters, so a variant on one letter of an Arabic word keeps its neighbours' initial, medial and final forms and the letters still touch. The panel lists the alternates of the glyph the shaper makes for the selected character in its word (a medial letter shows medial variants), and a double-click applies the OpenType feature that draws the variant (`salt=N` or `ssNN`) to that character alone, in one undo step (`text.setRangeStyle`); a variant no feature reaches falls back to a replacement glyph (`text.setGlyphAlternate`), which its tooltip says may not join. Show › Entire Font also lists the glyphs no character maps, with their name or `gid N` and the feature that gives them. The text crate reads each face's `GSUB` once (alternate sets, single substitutions, the feature that reaches a glyph). Not done: alternates reached through contextual or ligature lookups, and features of the font that the style has no tag for (`cv01`–`cv99`, `hist`). Evidence: `tests::glyph_alternates` in the text crate (a fixture font with a medial teh at `salt=1` to `3`, the neighbours' forms, no gap; Kufi Murabba PIIIX when it is installed), `features::tests::feature_values_are_parsed_validated_and_shaped`, `tests::textedit::feature_values_are_set_replaced_and_saved`, the `panels::glyphs` tests. | | OpenType panel menu: H or V Style, Roman Italics | done | With Show East Asian Options, as [Format East Asian characters](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html) describes: H or V Style is the character feature `hkna` (kana in the font's horizontal forms, shaped as `vkna` in vertical type) and Roman Italics is `ital` (the font's italic half-width alphanumerics), set with `text.setStyle` / `text.setRangeStyle {features, featureChanges}`, on or off only, and in Character Style Options › OpenType Features ([OpenType feature list](https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist)). | +| OpenType panel menu: Proportional Metrics | done | With Show East Asian Options, before H or V Style ([the help page](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html) lists it among the OpenType panel options): the `proportionalMetrics` character attribute of `text.setFormat` / `text.setRangeStyle`, as the Character panel menu's item sets it. | | Font menu: samples, live preview, filters, favourites, recent families; font matching by any name; Find Font | done | #3515: recently applied families appear first, once each; missing families are omitted and the existing Number of Recent Fonts setting applies; #339; script filter: Japanese, Latin, Thai; the font scan on Linux also reads the folders fontconfig's configuration lists, such as TeX fonts under `/usr/share/texmf/fonts` (#1548, fixes #1529; not verified on Linux); Select Text by Font takes a scope: the document, chosen artboards or chosen layers; Find Font's Find In offers Document, Artboard (the active one) and Layers (the selected ones, else the current one) (#5529, a VectorCraft addition); Replace With Font lists family and style rows, one click setting both, with a search over them; its list scrolls on its own, apart from the document's font list (#4972); wherever the font menu opens, its filters keep the same four rows, and it opens at least wide enough for them and for a family name up to 220 points wide with its sample (up to 60% of the window), each sample filling its row's height (a VectorCraft layout); a filter chosen in the font menu of the Character panel, the Control bar or the Properties panel is on in the others, and the filters are cleared when the app quits ([Font browser overview](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/font-options-overview.html)); the font menus of the Glyphs panel and of the dialogs that pick a font share the same filters (a VectorCraft choice); Show Similar Fonts: the ≈ button on a family's row lists the families that look like it first ([Font browser overview](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/font-options-overview.html)), by VectorCraft's own measure of PANOSE, weight, width, heights, average width and italic angle, same script first, a family sharing none of these numbers with it last in its group (VectorCraft's own rule), and the ≈ chip under the filters clears it (`text.similarFonts`; evidence: `font_menu::tests::show_similar_fonts_orders_the_list_by_likeness`, `tests::similar::families_are_ordered_by_likeness`, `tests::similar::a_family_without_numbers_comes_after_the_measured_ones`). | | Missing glyphs set in an installed font made for their script (Thai, Lao, Khmer, Myanmar first; then any font that has them) | done | Thai: Leelawadee UI, Tahoma, Thonburi, Sukhumvit Set, Noto Sans Thai, TLWG | | Full font-name matching (OpenType name ID 4) | done | #1258: loaded/cataloged faces and Missing Fonts searches; localized names and variable default faces; Windows font-service QA pending | From e45b157b672c7e979af62372700eb518e4bad7bf Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 17:40:52 -0800 Subject: [PATCH 2/2] OpenType: menu check marks skip empty frames of selected stories With the Selection tool, the panel menu's Proportional Metrics, H or V Style and Roman Italics read every run of the selected stories, including an empty frame's run. An empty frame without the setting made the item show unchecked while every character had it, and choosing it then turned the setting on instead of off. A run with no text now counts only when no run has text, as at a Type tool caret. --- crates/ui-egui/src/panels/opentype.rs | 57 ++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panels/opentype.rs b/crates/ui-egui/src/panels/opentype.rs index e52c852afb..05fb6f671e 100644 --- a/crates/ui-egui/src/panels/opentype.rs +++ b/crates/ui-egui/src/panels/opentype.rs @@ -122,7 +122,8 @@ fn shown_figure(app: &VectorcraftApp) -> Option { /// Whether `flag` is on for every character a toggle changes (`Some(true)`), for none of them /// (`Some(false)`), or only for some (`None`). At a Type tool caret, and after Select All in a /// threaded story, the command styles all the text ([`run_features`]), so every character of it -/// counts, as in [`edit`]. +/// counts, as in [`edit`]. There, and with the Selection tool, a run with no text (an empty +/// frame's) counts only when no run has text. fn shown_flag(app: &VectorcraftApp, flag: Flag) -> Option { shown(app, |s| flag.get(&OtFeatures::from_tags(s.features.iter().map(String::as_str)))) } @@ -130,7 +131,13 @@ fn shown_flag(app: &VectorcraftApp, flag: Flag) -> Option { /// Whether `on` holds for every character a menu item changes (`Some(true)`), for none of them /// (`Some(false)`), or only for some (`None`), read as [`shown_flag`] reads a feature. fn shown(app: &VectorcraftApp, on: impl Fn(&CharStyle) -> bool) -> Option { - if let Some(mut runs) = whole_text_runs(app) { + let runs = match whole_text_runs(app) { + Some(runs) => Some(runs), + // With the Selection tool: every run of every frame of the selected stories. + None if text_editing(app).is_none() => Some(super::character::selected_story_texts(app).into_iter().flat_map(|t| t.runs.iter()).collect()), + None => None, + }; + if let Some(mut runs) = runs { // A run with no text, such as an empty frame's, counts only when no run has text. if runs.iter().any(|r| !r.text.is_empty()) { runs.retain(|r| !r.text.is_empty()); @@ -1071,4 +1078,50 @@ mod tests { let runs = metrics_runs(&app, &id); assert!(runs.iter().all(|(_, on, _)| *on), "{runs:?}"); } + + /// With the Selection tool on a threaded story whose second frame is empty, the East Asian + /// items read only the characters: with the text set and the empty frame's run not, each item + /// shows checked, and choosing it turns the setting off for the text. + #[test] + fn east_asian_items_skip_an_empty_frame_of_a_selected_story() { + type Set = fn(&mut CharStyle, bool); + type Get = fn(&CharStyle) -> bool; + let items: [(&str, Set, Get); 3] = [ + ("Proportional Metrics", |s, on| s.proportional_metrics = on, |s| s.proportional_metrics), + ("H or V Style", |s, on| s.features = if on { vec!["hkna".into()] } else { vec![] }, |s| s.features.iter().any(|f| f == "hkna")), + ("Roman Italics", |s, on| s.features = if on { vec!["ital".into()] } else { vec![] }, |s| s.features.iter().any(|f| f == "ital")), + ]; + for (label, set, get) in items { + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.session.prefs.show_east_asian_options = true; + app.run("file.new", json!({"width": 600, "height": 300})).unwrap(); + let area = json!({"x": 10, "y": 10, "text": "かなAB", "size": 12, "area": {"width": 150, "height": 60}}); + let a = app.run("text.create", area).unwrap()["id"].as_u64().unwrap(); + let b = app.run("shape.rectangle", json!({"x": 200, "y": 10, "width": 150, "height": 200})).unwrap()["id"].as_u64().unwrap(); + app.run("select.set", json!({"ids": [a, b]})).unwrap(); + app.run("text.thread.create", json!({})).unwrap(); + app.run("select.set", json!({"ids": [a]})).unwrap(); + assert_eq!(super::super::character::selected_story_texts(&app).len(), 2, "{label}"); + for (id, on) in [(a, true), (b, false)] { + let doc = std::sync::Arc::make_mut(&mut app.session.doc_mut().unwrap().doc); + let Some(NodeKind::Text(t)) = doc.node_mut(NodeId(id)).map(|n| &mut n.kind) else { panic!("no frame {id}") }; + for r in &mut t.runs { + set(&mut r.style, on); + } + } + let empty = match &app.session.active().unwrap().doc.node(NodeId(b)).unwrap().kind { + NodeKind::Text(t) => t.runs.iter().filter(|r| r.text.is_empty()).count(), + _ => panic!("{label}: not text"), + }; + assert!(empty > 0, "{label}: the empty frame has no run"); + let ctx = egui::Context::default(); + let (text, at) = menu_row(&ctx, &mut app, label); + assert!(text.starts_with('✓'), "{label}: {text:?}"); + super::super::tests_appearance::click(&ctx, &mut app, at.center(), menu); + match &app.session.active().unwrap().doc.node(NodeId(a)).unwrap().kind { + NodeKind::Text(t) => assert!(t.runs.iter().all(|r| !get(&r.style)), "{label}"), + _ => panic!("{label}: not text"), + } + } + } }