From 187a75ca3f7279b5a03cfab01a117e7810bb5b8e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 16 Oct 2026 11:24:37 -0700 Subject: [PATCH] Character: Small Caps, Superscript and Subscript buttons and menu items set the text The Character panel's Small Caps, Superscript and Subscript buttons were disabled, with "(on the roadmap)" tips, and always drawn off, and the panel menu's items of the same names were disabled, although text.setFormat and text.setRangeStyle already set smallCaps and position. The reference app applies all three from the Character panel menu. The three buttons and menu items now turn small caps and the superscript or subscript position on and off for the selected type, or for the text the Type tool has selected, in Document Setup's proportions. Turning Superscript on turns Subscript off, and turning Subscript on turns Superscript off. They show as on when the first selected character has the attribute, as the All Caps, Underline and Strikethrough toggles do. docs/mcp.md did not mention smallCaps and position; it now describes them for text.setFormat and text.setRangeStyle. Docs: docs/mcp.md, docs/target-app-parity.md. --- crates/ui-egui/src/panels/character.rs | 154 ++++++++++++++++++++++--- docs/mcp.md | 16 +++ docs/target-app-parity.md | 1 + 3 files changed, 154 insertions(+), 17 deletions(-) diff --git a/crates/ui-egui/src/panels/character.rs b/crates/ui-egui/src/panels/character.rs index a36edc790..fd2bd4995 100644 --- a/crates/ui-egui/src/panels/character.rs +++ b/crates/ui-egui/src/panels/character.rs @@ -1,5 +1,6 @@ //! Character panel: font family / style, size, leading, kerning, tracking, vertical and horizontal -//! scale, baseline shift, character rotation and the caps / underline / strikethrough toggles. +//! scale, baseline shift, character rotation and the All Caps, Small Caps, Superscript, Subscript, +//! Underline and Strikethrough toggles. use std::sync::{Mutex, OnceLock}; @@ -564,21 +565,29 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { } ui.add_space(4.0); ui.horizontal(|ui| { - for (kind, tip, key, on, enabled) in [ - (Glyph::AllCaps, tl!("All Caps"), "allCaps", s.all_caps, true), - (Glyph::SmallCaps, tl!("Small Caps (on the roadmap)"), "", false, false), - (Glyph::Super, tl!("Superscript (on the roadmap)"), "", false, false), - (Glyph::Sub, tl!("Subscript (on the roadmap)"), "", false, false), - (Glyph::Underline, tl!("Underline"), "underline", s.underline, true), - (Glyph::Strike, tl!("Strikethrough"), "strikethrough", s.strikethrough, true), + let small = s.small_caps.is_some(); + let position = s.position.id(); + for (kind, tip, on, change) in [ + (Glyph::AllCaps, tl!("All Caps"), s.all_caps, json!({"allCaps": !s.all_caps})), + (Glyph::SmallCaps, tl!("Small Caps"), small, json!({"smallCaps": !small})), + (Glyph::Super, tl!("Superscript"), position == "superscript", position_toggle(position, "superscript")), + (Glyph::Sub, tl!("Subscript"), position == "subscript", position_toggle(position, "subscript")), + (Glyph::Underline, tl!("Underline"), s.underline, json!({"underline": !s.underline})), + (Glyph::Strike, tl!("Strikethrough"), s.strikethrough, json!({"strikethrough": !s.strikethrough})), ] { - if style_toggle(ui, kind, tip, on, enabled) && !key.is_empty() { - format(app, json!({key: !on})); + if style_toggle(ui, kind, tip, on) { + format(app, change); } } }); } +/// The `text.setFormat` params of the Superscript or Subscript toggle `p` for text whose +/// position is `position`: `normal` when `p` is on, else `p`, which turns the other one off. +fn position_toggle(position: &str, p: &str) -> Value { + json!({"position": if position == p { "normal" } else { p }}) +} + #[derive(Clone, Copy, PartialEq, Eq)] enum Glyph { AllCaps, @@ -590,15 +599,15 @@ enum Glyph { } /// A drawn "T" style toggle (All Caps, Small Caps, Superscript, Subscript, Underline, Strikethrough). -fn style_toggle(ui: &mut Ui, g: Glyph, tip: &str, on: bool, enabled: bool) -> bool { +fn style_toggle(ui: &mut Ui, g: Glyph, tip: &str, on: bool) -> bool { let t = Tokens::get(ui.ctx()); - let (r, resp) = ui.allocate_exact_size(vec2(30.0, 26.0), if enabled { egui::Sense::click() } else { egui::Sense::hover() }); + let (r, resp) = ui.allocate_exact_size(vec2(30.0, 26.0), egui::Sense::click()); if on { ui.painter().rect_filled(r, 3, t.tool_active); - } else if resp.hovered() && enabled { + } else if resp.hovered() { ui.painter().rect_filled(r, 3, t.hover); } - let col = if enabled { t.text_strong } else { t.text_disabled }; + let col = t.text_strong; let big = egui::FontId::proportional(15.0); let small = egui::FontId::proportional(10.5); let c = r.center(); @@ -630,7 +639,7 @@ fn style_toggle(ui: &mut Ui, g: Glyph, tip: &str, on: bool, enabled: bool) -> bo } } let resp = resp.on_hover_text(tl!(tip)); - enabled && resp.clicked() + resp.clicked() } pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { @@ -651,8 +660,16 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { format(app, json!({key: !on})); } } - for l in ["Small Caps", "Superscript", "Subscript"] { - menu_item(ui, tl!(l), false, false); + let small = s.as_ref().is_some_and(|s| s.small_caps.is_some()); + let position = s.as_ref().map_or("normal", |s| s.position.id()); + for (label, on, change) in [ + (tl!("Small Caps"), small, json!({"smallCaps": !small})), + (tl!("Superscript"), position == "superscript", position_toggle(position, "superscript")), + (tl!("Subscript"), position == "subscript", position_toggle(position, "subscript")), + ] { + if menu_item(ui, label, has, on) { + format(app, change); + } } ui.separator(); // Character Alignment: where characters smaller than the largest on their line line up, with @@ -856,6 +873,109 @@ mod tests { assert!(!crate::menus::enabled(&app, "type.bold")); } + /// From one frame of the panel: a point inside each of the Small Caps, Superscript and + /// Subscript buttons, and which of them are drawn on. The two buttons with a "1" are + /// Superscript (the "1" up) and Subscript; Small Caps is the button before them. + fn script_buttons(ctx: &egui::Context, app: &mut VectorcraftApp) -> ([egui::Pos2; 3], [bool; 3]) { + let mut out = ctx.run_ui(egui::RawInput::default(), |ui| show(app, ui)); + out.textures_delta.clear(); + fn walk(s: &egui::Shape, on: egui::Color32, ones: &mut Vec, lit: &mut Vec) { + match s { + egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, on, ones, lit)), + egui::Shape::Text(t) if t.galley.text() == "1" => ones.push(t.visual_bounding_rect().center()), + egui::Shape::Rect(r) if r.fill == on && r.rect.size() == vec2(30.0, 26.0) => lit.push(r.rect), + _ => {} + } + } + let (mut ones, mut lit) = (vec![], vec![]); + for c in &out.shapes { + walk(&c.shape, Tokens::get(ctx).tool_active, &mut ones, &mut lit); + } + let [sup, sub] = ones[..] else { panic!("two script buttons: {ones:?}") }; + assert!(sup.x < sub.x && sup.y < sub.y, "Superscript, then Subscript: {ones:?}"); + // Each "1" is drawn 6 points right of its button's center and 5 points above or below it. + let y = (sup.y + sub.y) / 2.0; + let (sup, sub) = (egui::pos2(sup.x - 6.0, y), egui::pos2(sub.x - 6.0, y)); + let points = [sup - vec2(sub.x - sup.x, 0.0), sup, sub]; + (points, points.map(|p| lit.iter().any(|r| r.contains(p)))) + } + + /// Each run's (small caps, position). + fn scripts(app: &VectorcraftApp, id: &Value) -> Vec<(Option, &'static str)> { + match &app.session.active().unwrap().doc.node(NodeId(id.as_u64().unwrap())).unwrap().kind { + NodeKind::Text(t) => t.runs.iter().map(|r| (r.style.small_caps, r.style.position.id())).collect(), + _ => panic!("text"), + } + } + + /// The Small Caps, Superscript and Subscript buttons set the selected type's small caps and + /// position, with one undo step for each click, and show them; Superscript and Subscript turn + /// each other off. While the Type tool edits, they set and show the selected characters. + #[test] + fn small_caps_superscript_and_subscript_buttons_set_and_show_the_text() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 300, "height": 200})).unwrap(); + app.session.select_tool("type", Default::default()).unwrap(); + let id = app.run("text.create", json!({"x": 20, "y": 50, "text": "E=mc2", "size": 12})).unwrap()["id"].clone(); + let ctx = egui::Context::default(); + let (at, lit) = script_buttons(&ctx, &mut app); + assert_eq!(lit, [false; 3]); + let small = Some(app.session.active().unwrap().doc.setup.small_caps_size); + for (button, runs, shown) in [ + (0, (small, "normal"), [true, false, false]), + (1, (small, "superscript"), [true, true, false]), + (2, (small, "subscript"), [true, false, true]), + (2, (small, "normal"), [true, false, false]), + (1, (small, "superscript"), [true, true, false]), + (1, (small, "normal"), [true, false, false]), + (0, (None, "normal"), [false; 3]), + ] { + let undo = app.session.active().unwrap().history.undo.len(); + super::super::tests_appearance::click(&ctx, &mut app, at[button], show); + assert_eq!(scripts(&app, &id), [runs], "button {button}"); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 1, "button {button}"); + assert_eq!(script_buttons(&ctx, &mut app).1, shown, "button {button}"); + } + // The Type tool's selection: "2" alone. + app.session.apply_actions(vec![vectorcraft_tools::Action::Notify("text.editNew".into())]).unwrap(); + app.session.set_tool_option("select", &json!({"start": 4, "end": 5})); + assert!(text_editing(&app).is_some()); + super::super::tests_appearance::click(&ctx, &mut app, at[1], show); + assert_eq!(scripts(&app, &id), [(None, "normal"), (None, "superscript")]); + assert_eq!(script_buttons(&ctx, &mut app).1, [false, true, false]); + app.session.set_tool_option("select", &json!({"start": 0, "end": 4})); + assert_eq!(script_buttons(&ctx, &mut app).1, [false; 3]); + } + + /// The panel menu's Small Caps, Superscript and Subscript set the selected type's small caps + /// and position and show a check mark when on; Superscript and Subscript turn each other off. + #[test] + fn small_caps_superscript_and_subscript_menu_items_set_and_check_the_text() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 300, "height": 200})).unwrap(); + let id = app.run("text.create", json!({"x": 20, "y": 50, "text": "E=mc2", "size": 12})).unwrap()["id"].clone(); + let ctx = egui::Context::default(); + let checked = |app: &mut VectorcraftApp| { + let texts = super::super::tests_appearance::frame_events(&ctx, app, vec![], menu); + ["Small Caps", "Superscript", "Subscript"].map(|l| texts.iter().any(|(t, _)| *t == format!("✓ {l}"))) + }; + assert_eq!(checked(&mut app), [false; 3]); + let small = Some(app.session.active().unwrap().doc.setup.small_caps_size); + for (item, runs, shown) in [ + ("Small Caps", (small, "normal"), [true, false, false]), + ("Superscript", (small, "superscript"), [true, true, false]), + ("Subscript", (small, "subscript"), [true, false, true]), + ("Subscript", (small, "normal"), [true, false, false]), + ("Small Caps", (None, "normal"), [false; 3]), + ] { + let texts = super::super::tests_appearance::frame_events(&ctx, &mut app, vec![], menu); + let at = texts.iter().find(|(t, _)| t.trim_start_matches(['✓', ' ']) == item).unwrap_or_else(|| panic!("{item}: {texts:?}")).1; + super::super::tests_appearance::click(&ctx, &mut app, at.center(), menu); + assert_eq!(scripts(&app, &id), [runs], "{item}"); + assert_eq!(checked(&mut app), shown, "{item}"); + } + } + /// Character Alignment and Proportional Metrics are in the panel menu with the East Asian /// options only (as Mojikumi Set and Top-to-Top Leading are in the Paragraph panel). #[test] diff --git a/docs/mcp.md b/docs/mcp.md index c62d78b51..feea3e434 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3297,6 +3297,22 @@ undo step. {"name":"run_command","arguments":{"command":"text.setFormat","params":{"burasagari":"forced"}}} ``` +## Small Caps, Superscript and Subscript + +`text.setFormat {smallCaps, position}` (the selected type, or `ids`) and `text.setRangeStyle {id, start, end, smallCaps, +position}` (a range) set what the Character panel's Small Caps, Superscript and Subscript buttons and menu items set. +`smallCaps: true` draws lowercase letters as capitals at Document Setup's small caps size (70% of the font size by +default); capitals keep their size, and with All Caps on every letter is a full-size capital. `position: "superscript"` +or `"subscript"` draws the characters at Document Setup's superscript or subscript size, raised or lowered by its +position (by default 58.3% of the font size, moved by 33.3% of it), and `"normal"` puts them back on the baseline. +Setting superscript on subscript characters replaces the subscript, and setting subscript on superscript characters +replaces the superscript. When `document.setup {superscript, subscript, smallCapsSize}` changes the proportions, the +characters take the new ones. One undo step. + +```json +{"name":"run_command","arguments":{"command":"text.setFormat","params":{"position":"superscript","smallCaps":false}}} +``` + ## Character Alignment `text.setFormat {charAlign}` (the selected type, or `ids`) and `text.setRangeStyle {id, start, end, charAlign}` (a range) diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index dec15fa24..e06432e0d 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -562,6 +562,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Free Distort's dialog (Effect › Distort & Transform › Free Distort…) shows a box in the proportions of the first selected object's bounds with a handle on each corner. Dragging a handle moves that corner. A handle focused by a click or Tab moves 1% of the box with each arrow key, and 10% with Shift. Reset puts the four corners back on the box. The preview and OK run `effect.apply`, or `effect.setParams` when the dialog edits an applied effect, and the Appearance panel's inline editor opens the dialog with Edit…. Behavior reference: Illustrator CC Help (2014, [PDF](https://help.adobe.com/archive/en/illustrator/cc/2014/illustrator_reference.pdf)), page 285 (PDF page 291). - **Kerning across style runs:** characters that differ only in fill, stroke, underline, strikethrough, overprint, character style name, leading, baseline shift, rotation, Character Alignment, kerning, or tracking that keeps or drops ligatures alike are shaped together, so restyling one character keeps the font's kerning pairs with its neighbors. A character with manual kerning that follows one with automatic kerning keeps the font's kerning with it (unless All Caps or Small Caps sets it as two letters, as ß becomes SS), and its value replaces the font's kerning after it. A ligature does not form across a change of style, and a change of font, size or OpenType features still shapes the characters apart. Behavior reference: [Line and character spacing](https://web.archive.org/web/20260916050333/https://helpx.adobe.com/illustrator/using/line-character-spacing.html) (public documentation). Tests: `crates/text/src/tests_typo.rs`, `crates/text/src/tests_bidi.rs`. - **Type:** Character size, leading, baseline shift and horizontal-scale controls account for object/group transforms (#1034): exact document-point sizes, mixed-value display and keyboard increments, range edits, resettable horizontal stretch, undo/redo and native save/reopen (`tests_typescale`, Character panel tests). Point size is the transformed em-height axis, independent of glyph ink bounds; affine rotation, reflection and shear are retained. Group scaling still scales text; preserving font sizes is a separate enhancement. Behaviour reference: [Transform text](https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/transform-text.html) (public documentation). Text Wrap, Type on a Path effects (Rainbow/Skew/3D Ribbon/Stair Step/Gravity) and Options (Flip, Align to Path, Spacing; OK keeps the type where it is), type on a path's start, centre and end brackets (Selection and Direct Selection drag them to set where the type runs, slide it along its path and, across the path, flip it: #429), Character and Paragraph Styles (override-preserving redefine), paragraph attributes per paragraph (alignment, indents, spacing, hyphenation, hanging punctuation, tab stops, paragraph style, direction, mojikumi and leading model; the Paragraph, Tabs and Paragraph Styles panels act on the paragraphs the Type tool's selection or caret touches, Return continues the paragraph's style, threads and SVG keep them), Area Type Options (rows/columns/inset/first baseline, vertical Align Top/Center/Bottom/Justify per row/column, reflowing non-rectangular frames and text wrap), threaded text across any closed shapes, Fit Headline, the Every-line Composer for justified and ragged text (paragraph-wide breaks for an even rag, Single-line per object from the Paragraph panel menu or `text.setFormat {composer}`). Area type resizes like Illustrator's type areas: a bounding-box handle drag (Selection tool) or Area Type Options Width/Height size the frame and the text reflows at its size (threads too); Direct Selection drags a frame corner or edge (`text.reshapeArea`). Point type still scales. Auto Size: the frame height follows the text after every edit, in the same undo step (rectangular frames of horizontal type in one row; columns get the least height that holds them; a height set by hand or threading turns it off), and the "Auto Size New Area Type" preference gives it to new area type. Shrink Text to Fit (beyond Illustrator): overflowing area type scales its sizes, leading and baseline shifts down by the largest factor (in 0.1 pt steps of the first run, down to a minimum percentage) that fits, at layout time so every export sees it. `text.areaOptions` and `document.inspect` report overflow and the shrink factor. The Selection tool shows the type widget beside selected type's bounding box (hollow on point type, filled on area type); double-clicking it converts between them (Type › Convert To Area Type / Convert To Point Type), keeping the text and its styles in place. Variable fonts list every named instance as a style of their family (Figtree Light to Black and their italics, Bahnschrift, Segoe UI Variable), and the instance chosen is shaped, drawn, outlined and measured at its axis settings; PDF and SVG embed it as that instance. Variation axis sliders are not done. Beyond Illustrator: inline graphics (`text.insertInline`, Type ▸ Insert Inline Symbol) set a document symbol in a run of type as one character that flows, wraps and justifies like a glyph (InDesign-style inline objects, e.g. mana symbols in card rules text): sized to a multiple of the font size, centred on the cap height, opening up tall lines, following Redefine Symbol; a character of its run's size for Character Alignment and Top-to-Top leading, placed by the bidi reordering in right-to-left text (a neutral U+FFFC); drawn on the canvas, kept as live text plus a `` in SVG and as vector art in PDF; Backspace removes it whole. Hebrew and Arabic are laid out right to left with the Unicode bidirectional algorithm (embedded Latin and numbers keep their direction, lines put in visual order after wrapping) in point, area and path type, with caret, selection and arrow keys in visual order; each paragraph's direction comes from its first strong character unless Paragraph Direction sets it (Paragraph panel with Show Indic Options, `text.setFormat {direction}`), and new type aligns to the start of its direction. SVG export outlines right-to-left text. Arabic typefaces: builds made with a craft-fonts checkout that holds its Arabic families (Noto Sans Arabic, the Arabic fallback, plus Cairo, Tajawal, Almarai, IBM Plex Sans Arabic, Noto Kufi Arabic, Amiri, Alexandria, Fustat, Reem Kufi, Aref Ruqaa and Gulzar once craft-fonts adds them, storytold/craft-fonts#11; releases get them when their craft-fonts pin moves) list them in the font menus on desktop; the web build fetches them from beside the wasm (Noto Sans Arabic before start, so Arabic never shows as boxes, the rest in the background). Font Size and Leading are combo boxes in the Character and Properties panels (Font Size in the Control bar too, beside the Character link, font family and style): type, step with ↑/↓ or the spinner, scrub the label, or pick a preset (6–72 pt, shown in the type unit; Leading also Auto), each pick one undo step; Kerning and Tracking list -100…200; a size, leading, kerning or tracking the selected text doesn't share shows blank (#458). Type › Bold and Italic (beyond Illustrator, as page layout apps have them; Cmd+Shift+B / Cmd+Shift+I while the Type tool edits text) switch the selected type to its family's own Bold or Italic face and back, keeping its width (a Narrow face stays Narrow); a family without that face says so (#724). The commands that make or restyle type (and the MCP `add_text` tool) say in their result when area type does not fit its frame, and `add_text` takes Auto Size and Shrink Text to Fit (#1500, fixes #1471). Print and Print Preview warn about the area type and type on a path that prints without the text that doesn't fit, and give their ids. A tab stop in the Tabs panel drags from where the press landed, a stop just added included (#1487, fixes #1458). Area type in a non-rectangular shape moves a word too wide for the top lines down to the first line that holds it instead of breaking it (#1617, fixes #1615). Stylistic sets (ss01–ss20), stylistic and titling alternates, proportional and lining figures, and superscript and subscript glyphs can be turned on as OpenType features of a character style (`text.setStyle {features}`), and the OpenType panel keeps them (#1611, fixes #1607). Escape while typing ends the edit, keeps the type selected and switches to the Selection tool (#1802, #1686, #1656). Select › Same matches type on its characters' fill and stroke (#1746, #1737). `text.create`, `text.createInPath` and the MCP `add_text` tool take `justify`, so point type can be centred on or end at its point (#1752, #1748). + The Character panel's Small Caps, Superscript and Subscript buttons and the panel menu's items of the same names turn small caps and the superscript or subscript position on and off for the selected type, or for the text the Type tool has selected (`text.setFormat` or `text.setRangeStyle` `{smallCaps, position}`), in Document Setup's proportions. Turning Superscript on turns Subscript off, and turning Subscript on turns Superscript off. A button or item shows as on when the first selected character (at a caret, the character before it) has its attribute. - **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`). An edit copies a thread's story only when it changes one of the thread's frames: with a story of 50,000 characters threaded through 8 frames with a style change at every word, moving another object took 7.8 ms and now takes 0.013 ms, and a frame of a drag took 7.2 ms and now takes 0.012 ms (release build, `threaded_story_edit_timing`).