diff --git a/crates/ui-egui/src/dialogs/composite_fonts.rs b/crates/ui-egui/src/dialogs/composite_fonts.rs index 61bcee82b7..3ab762bfc5 100644 --- a/crates/ui-egui/src/dialogs/composite_fonts.rs +++ b/crates/ui-egui/src/dialogs/composite_fonts.rs @@ -149,7 +149,8 @@ pub struct CompositeFontsDialog { entry_mode: EntryMode, /// The index of the character picked in the set picked. picked_char: Option, - /// Show Sample's fields ([`sample::defaults`]). + /// Show Sample's fields ([`sample::defaults`]). Zoom previews menu choices and restores its opening + /// percentage on cancellation; a later automation edit takes precedence over that older gesture. sample: Map, /// The view settings of the Composite Font row's picker and of the Character Set row's. pickers: (PresetState, PresetState), diff --git a/crates/ui-egui/src/dialogs/composite_fonts/sample.rs b/crates/ui-egui/src/dialogs/composite_fonts/sample.rs index f266d1ca29..10e9ede502 100644 --- a/crates/ui-egui/src/dialogs/composite_fonts/sample.rs +++ b/crates/ui-egui/src/dialogs/composite_fonts/sample.rs @@ -283,7 +283,8 @@ thread_local! { } /// Show Sample's area under the table: the sample of `f` with the marks `fields` show, then a swatch -/// and a toggle for each mark and Zoom beside it. A change the user makes goes into `fields`. +/// and a toggle for each mark and Zoom beside it. Zoom writes live proposals into `fields`, restores +/// its opening percentage on cancellation and preserves a later automation edit. pub(super) fn show(ui: &mut Ui, fields: &mut Map, f: &CompositeFont) { let zoom_now = zoom(fields); let marks: Vec = Mark::ALL.into_iter().filter(|m| on(fields, m.field())).collect(); @@ -318,8 +319,10 @@ pub(super) fn show(ui: &mut Ui, fields: &mut Map, f: &CompositeFo } Row::new().id_salt("zoom").show(ui, |ui, _| { Text::new(tl!("Zoom")).show(ui); - if let Some(z) = Select::new(tl!("Zoom"), Bind::given(zoom_now), &entries).show(ui).value().copied() { - fields.insert("zoom".into(), json!(z)); + let mut chosen_zoom = zoom_now; + Select::new(tl!("Zoom"), Bind::bound(&mut chosen_zoom), &entries).show(ui); + if chosen_zoom != zoom_now { + fields.insert("zoom".into(), json!(chosen_zoom)); } }); }); @@ -384,3 +387,94 @@ pub(super) fn draw(f: &CompositeFont, size: f64, baseline: f64, px: (u16, u16), let empty = || vectorcraft_render::Rendered { width: u32::from(w), height: u32::from(h), pixels: vec![0; usize::from(w) * usize::from(h) * 4] }; RENDERER.with(|r| r.borrow_mut().render_node(&doc, &node, w, h, view)).unwrap_or_else(empty) } + +#[cfg(test)] +mod zoom_tests { + use craft::ui::contract::Role; + use craft::ui::dialog::dialog_id; + use egui::{Key, Modifiers, vec2}; + use vectorcraft_engine::Session; + + use super::super::{KIND, open, with_dialog}; + use super::*; + use crate::VectorcraftApp; + use crate::tests::panel_harness::Panel; + + fn opened(width: f32) -> Panel { + let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default())); + app.run("file.new", json!({"width": 300, "height": 200})).unwrap(); + let mut panel = Panel::new(app, crate::tests::picks::dialogs); + panel.room(vec2(width, 1000.0)); + open(&mut panel.app()).unwrap(); + with_dialog(&panel.app(), |dialog| { + dialog.fonts = vec![CompositeFont::new("Sample draft", "Source Sans 3", "Regular")]; + dialog.select(0); + }) + .unwrap(); + panel.frame(); + panel.click("Show Sample"); + panel + } + + fn fields(panel: &Panel) -> Map { + with_dialog(&panel.app(), |dialog| dialog.sample.clone()).expect("the Composite Fonts dialog remains open") + } + + #[test] + fn composite_sample_zoom_escape_restores_the_opening_value() { + for width in [1024.0, 1280.0] { + let mut panel = opened(width); + let before = fields(&panel); + let (document, undo, revision) = { + let app = panel.app(); + let st = app.session.active().unwrap(); + (st.doc.clone(), st.history.undo.len(), st.revision) + }; + assert_eq!(panel.value_role("Zoom", Role::COMBO_BOX).as_deref(), Some("100%")); + panel.click_role("Zoom", Role::COMBO_BOX); + panel.key(Key::ArrowDown, Modifiers::NONE); + assert_ne!(fields(&panel)["zoom"], before["zoom"], "the open popup previews its proposed magnification"); + panel.key(Key::Escape, Modifiers::NONE); + assert_eq!(fields(&panel), before, "Escape restores the complete sample draft while keeping the parent dialog open"); + assert_eq!(panel.value_role("Zoom", Role::COMBO_BOX).as_deref(), Some("100%")); + let app = panel.app(); + let st = app.session.active().unwrap(); + assert_eq!(st.doc, document); + assert_eq!(st.history.undo.len(), undo); + assert_eq!(st.revision, revision); + } + } + + #[test] + fn composite_sample_zoom_accepts_pointer_and_keyboard_choices() { + let mut panel = opened(1280.0); + panel.click_role("Zoom", Role::COMBO_BOX); + panel.key(Key::ArrowDown, Modifiers::NONE); + panel.key(Key::Enter, Modifiers::NONE); + assert_eq!(fields(&panel)["zoom"], json!(200)); + panel.click_role("Zoom", Role::COMBO_BOX); + panel.key(Key::ArrowDown, Modifiers::NONE); + panel.key(Key::Escape, Modifiers::NONE); + assert_eq!(fields(&panel)["zoom"], json!(200), "a later cancellation restores the last accepted choice"); + panel.click_role("Zoom", Role::COMBO_BOX); + panel.click("400%"); + assert_eq!(fields(&panel)["zoom"], json!(400)); + assert_eq!(panel.value_role("Zoom", Role::COMBO_BOX).as_deref(), Some("400%")); + } + + #[test] + fn composite_sample_zoom_preserves_an_automation_edit_during_a_popup() { + let mut panel = opened(1280.0); + panel.click_role("Zoom", Role::COMBO_BOX); + panel.key(Key::ArrowDown, Modifiers::NONE); + assert_eq!(fields(&panel)["zoom"], json!(200)); + { + let app = panel.app(); + let ctx = app.ui_ctx.clone().unwrap(); + app.dialogs().unwrap().with(|host| host.set_json_field(&ctx, dialog_id(KIND), "zoom", json!(400))).unwrap(); + } + panel.key(Key::Escape, Modifiers::NONE); + assert_eq!(fields(&panel)["zoom"], json!(400), "canceling an older popup must not undo the later automation edit"); + assert_eq!(panel.value_role("Zoom", Role::COMBO_BOX).as_deref(), Some("400%")); + } +} diff --git a/docs/mcp.md b/docs/mcp.md index 43673732f1..fe44a42ff5 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -13214,7 +13214,10 @@ The em box and ICF box are those of the font of the part that sets the sample's custom set that holds that character), the cap height and x-height those of the face the Roman letters are drawn in (a fallback face when the part's font lacks the character), Max Ascent/Descent the highest ascent and lowest descent of the faces the sample uses, and Max Ascender the top of its tallest glyph; each takes its part's size, baseline and vertical scale. Zoom draws it at 25% to 800% of 36 pt. The -sample text, the zoom steps and the size are VectorCraft's own. OK runs `type.compositeFonts.set` with every font as one +sample text, the zoom steps and the size are VectorCraft's own. Highlighting a Zoom choice previews it in the sample; +Enter or a click accepts it, and Escape restores the percentage from when the menu opened. A later `ui.dialog.set` +edit of `zoom` is preserved when the older popup is canceled. These Zoom interactions change only the sample preview, +without editing the document or its Undo history. OK runs `type.compositeFonts.set` with every font as one undo step; a refused font keeps the dialog open. `ui.dialog.set` takes `custom`, `entry` and `char` (the index of the character picked in the set) as soon as the dialog opens, and `sample` (true or false), `zoom` (25, 50, 75, 100, 200, 400 or 800) and `lineIcfBox`, `lineEmBox`, `lineBaseline`, `lineCapHeight`, `lineAscentDescent`, `lineAscender` and diff --git a/docs/ui-parity.md b/docs/ui-parity.md index a18a02f7d7..cd82eec40b 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -509,6 +509,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po | Control bar: numeric Corner Radius for eligible selected ordinary and live corners (part of #7238, request 3 only) | done | Anchor Points visibility group; common/mixed values, general document units and multi-object edits through `object.setLiveShape`, one Undo. A partial selection containing no eligible corners contributes no target. Corner kind and relative mode are retained; existing corner-widget selection, widget visibility and maximum-radius behavior are unchanged. Requests 1/2 remain open. | | Stroke panel: custom arrowheads after the built-in ones in both arrowhead menus, from the arrowheads file that the panel menu's Edit Arrowheads… opens; saving the file reloads the menus, and a stroke keeps a copy of its custom head's art | done | [Apply stroke on an object](https://helpx.adobe.com/illustrator/using/stroke-object.html) (Customize arrowheads); the file's layout (one symbol per head, pointing right, tip at the registration point, height drawn as wide as the built-in heads) is VectorCraft's own; `stroke.arrowheads.edit`, `stroke.arrowheads.list`, `stroke.arrowheads.reload`, `stroke.set` `{custom: name}`; engine `tests::arrowheads`, `stroke::tests_arrows::custom_heads_draw_their_own_art_at_the_tip` | | Control bar: Paragraph: link and Align left/center/right while type is selected (#5372) | done | After the Character controls, as the public documentation has the Control panel format paragraphs ([Paragraph panel overview](https://helpx.adobe.com/illustrator/using/formatting-paragraphs.html), [Align text](https://helpx.adobe.com/illustrator/using/align-text.html)); the link opens the Paragraph panel in a popover, as Character: does with the Character panel. The bar trims from its right end: X/Y/W/H, Distribute, Align, area type vertical alignment, then these buttons, then the link. The three-button set is our choice for room; all seven alignments are in the popover. `panels/paragraph/tests.rs` headless tests (`the_control_bar_shows_the_paragraph_alignment_of_the_selected_type`, `the_control_bar_trims_its_paragraph_section_after_the_controls_to_its_right`) | +| Composite Fonts sample Zoom restores canceled choices | done | Highlighting previews a percentage; Enter or a click accepts it, and Escape restores the previous choice without editing the document or Undo history. A later automation change is preserved. | | Pathfinder shape results keep their source names and SVG IDs | done | #1293; Minus Front keeps the back name, Minus Back the front name; Unite/Intersect/Exclude use the backmost named input; compound output carries it once; geometry and paint unchanged | | Attributes fill-rule controls with a compound member selected | done | Edits the compound's rule; direction still edits only the member; rendered-hole and Undo/Redo regression tests (#1197) | | Info panel follows the tool in use: W and H show the change in x and y, with the distance and the angle, while the selection moves, the Gradient tool draws a vector or a Pen drag pulls out an anchor's handle; the Scale tool's percentages; the center and angles of a Rotate, Reflect or Shear tool drag; the Zoom tool's magnification; the Paintbrush's brush. W and H follow Use Preview Bounds, several selected objects show only the paint and type they share, and Show Options names a tint or a gradient swatch | done | `info.readout`; `Tool::readout`; behavior from the Info panel overview in the [archived user guide](https://web.archive.org/web/20220911143322/https://helpx.adobe.com/pdf/cs6/illustrator_reference.pdf#page=76); number formats, the rows shown between drags and the Direct Selection and Group Selection readouts are VectorCraft's own |