diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index f81ea2f7f9..8234aa1ba4 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1336,7 +1336,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.dialogReset", "Reset", "", - "{} the open dialog's Reset, which its Cancel button reads while Alt (Option on macOS) is held (Flare Tool Options, dialog `flareOptions`): its fields go back to their defaults and the dialog stays open, so OK applies them → the dialog; an error when no dialog is open or the open one has no Reset", + "{} the open dialog's Reset, which its Cancel button reads while Alt (Option on macOS) is held (Flare Tool Options, dialog `flareOptions`; Save PDF, dialog `savePdf`): its fields go back to their defaults (Save PDF: the chosen preset's settings, with the path and artboards kept) and the dialog stays open, so OK applies them → the dialog; an error when no dialog is open or the open one has no Reset", ), ( "ui.justification", diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs index 4f8bdf7667..428a8768ff 100644 --- a/crates/ui-egui/src/dialogs/save_pdf.rs +++ b/crates/ui-egui/src/dialogs/save_pdf.rs @@ -7,7 +7,9 @@ //! `document.pdfSettings`. Save Preset… names the settings as a preset (`pdf.preset.save`). //! Opened from Export As with Use Artboards off (`__artBounds`), the dialog has no Artboards //! section, and OK writes one page of the visible art's bounds through [`io::export`]; opened -//! from Export Selection (`__selection` too), the page is the selection's crop. +//! from Export Selection (`__selection` too), the page is the selection's crop. While Alt (Option +//! on macOS) is held, Cancel reads Reset, which puts the options back to the chosen preset's +//! settings and leaves the dialog open (`ui.dialogReset`). //! //! The same dialog edits a preset (kind `pdfPreset`, from Edit → PDF Presets): a `name` and //! `description` instead of the preset and artboards, and OK saves the preset. @@ -30,8 +32,15 @@ use crate::{VectorcraftApp, io, widgets}; pub(super) const KIND: &str = "savePdf"; -pub(super) const SPEC: DialogSpec = - DialogSpec { heading: |_| tl!("Save PDF").into(), body, confirm, ok: Some("Save PDF"), inputs: |_| &["path"], ..DialogSpec::FORM }; +pub(super) const SPEC: DialogSpec = DialogSpec { + heading: |_| tl!("Save PDF").into(), + body, + confirm, + ok: Some("Save PDF"), + inputs: |_| &["path"], + reset: Some(reset), + ..DialogSpec::FORM +}; /// The dialog kind of the preset editor (New / Edit in Edit → PDF Presets). pub(super) const PRESET_KIND: &str = "pdfPreset"; @@ -502,13 +511,33 @@ fn preset_rows(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) { fn apply_preset(app: &mut VectorcraftApp, d: &mut Dialog, name: &str) { match settings_fields(app, &json!({ "preset": name })) { Ok(settings) => { - d.fields.extend(settings); + replace_settings(d, settings); d.fields.insert("preset".into(), json!(name)); } Err(e) => app.status(e), } } +/// The UI-only fields that stand for options: the Security section's password checkboxes. +const OPTION_FLAGS: [&str; 2] = ["__requireOpenPassword", "__restrictPermissions"]; + +/// Replace every option with `settings` (from [`settings_fields`]), the password checkboxes +/// included. The preset, the artboard choice, the path and the other UI-only fields (the section, +/// the Save Preset name) stay. +fn replace_settings(d: &mut Dialog, settings: Map) { + d.fields.retain(|k, _| matches!(k.as_str(), "preset" | "range" | "path") || (k.starts_with("__") && !OPTION_FLAGS.contains(&k.as_str()))); + d.fields.extend(settings); +} + +/// Reset (Cancel with Alt or Option held): the options go back to the chosen preset's settings, as +/// choosing that preset sets them, and the dialog stays open. A preset that can no longer be found +/// (a saved one deleted while the dialog is open) leaves the dialog as it is. +fn reset(app: &VectorcraftApp, d: &mut Dialog) { + if let Ok(settings) = settings_fields(app, &json!({ "preset": d.str("preset") })) { + replace_settings(d, settings); + } +} + /// General: the options, then the artboards (Save PDF) or the description (preset editor). fn general(ui: &mut egui::Ui, d: &mut Dialog, editor: bool) { heading(ui, tl!("Options")); diff --git a/crates/ui-egui/src/dialogs/save_pdf/tests.rs b/crates/ui-egui/src/dialogs/save_pdf/tests.rs index b73ec294b1..9315b29f23 100644 --- a/crates/ui-egui/src/dialogs/save_pdf/tests.rs +++ b/crates/ui-egui/src/dialogs/save_pdf/tests.rs @@ -346,6 +346,71 @@ fn presets_reset_the_settings_and_fields_fall_back_to_defaults() { assert!(app.run("ui.savePdfDialog", json!({"compatibility": "1.0"})).is_err(), "bad options are refused"); } +/// Reset (`ui.dialogReset`, or Cancel with Alt or Option held) puts every option back to the +/// chosen preset's settings, passwords and their checkboxes included, and keeps the preset, the +/// path, the artboard range, the section and the dialog. After another preset is chosen, Reset +/// goes back to that one, and choosing it also clears the password checkboxes. +#[test] +fn reset_puts_the_chosen_presets_settings_back_and_keeps_the_path_and_artboards() { + let (mut app, written, _) = app(); + app.run("pdf.preset.save", json!({"name": "Mine", "compatibility": "1.5", "marks": {"trim": true}})).unwrap(); + app.run("ui.savePdfDialog", json!({"path": "/tmp/reset.pdf", "preset": "Mine"})).unwrap(); + set_field(&mut app, "__allArtboards", json!(false)); + set_field(&mut app, "range", json!("2")); + set_field(&mut app, "__section", json!("Security")); + set_field(&mut app, "compatibility", json!("1.7")); + set_field(&mut app, "marks.trim", json!(false)); + set_field(&mut app, "compression.color.ppi", json!(72)); + set_field(&mut app, OPEN_PASSWORD, json!("secret")); + set_field(&mut app, "__restrictPermissions", json!(true)); + let r = app.run("ui.dialogReset", json!({})).unwrap(); + assert_eq!(r["kind"], KIND); + let d = app.ui.dialog.as_ref().expect("Reset leaves the dialog open"); + assert_eq!(get(d, "compatibility"), "1.5"); + assert_eq!(get(d, "marks.trim"), true); + assert_eq!(get(d, "compression.color.ppi"), 300.0, "a nested option goes back too"); + assert_eq!(get(d, OPEN_PASSWORD).as_str().unwrap_or_default(), "", "the password is cleared"); + assert!(!d.fields.contains_key("__restrictPermissions"), "the checkbox is cleared"); + assert_eq!( + (d.str("preset"), d.str("path"), d.str("range"), d.str("__section")), + ("Mine".to_string(), "/tmp/reset.pdf".to_string(), "2".to_string(), "Security".to_string()) + ); + assert!(!d.bool("__allArtboards")); + + let mut d = d.clone(); + d.fields.insert("__requireOpenPassword".into(), json!(true)); + apply_preset(&mut app, &mut d, pdf::DEFAULT_PRESET); + assert!(!d.fields.contains_key("__requireOpenPassword"), "choosing a preset clears the checkbox"); + app.ui.dialog = Some(d); + set_field(&mut app, "compatibility", json!("1.4")); + app.run("ui.dialogReset", json!({})).unwrap(); + let d = app.ui.dialog.as_ref().expect("the dialog stays open"); + assert_eq!(d.str("preset"), pdf::DEFAULT_PRESET); + assert_eq!(get(d, "compatibility"), "1.7"); + assert_eq!(get(d, "marks.trim"), false); + // OK writes the reset options to the kept path and range. + super::super::confirm(&mut app).unwrap(); + let w = written.borrow(); + assert_eq!((w.len(), w[0].0.as_str()), (1, "/tmp/reset.pdf")); + assert!(w[0].1.starts_with(b"%PDF-1.7")); + assert_eq!(vectorcraft_pdf::import(&w[0].1).unwrap().artboards.len(), 1, "range 2"); +} + +/// Reset with a saved preset deleted while the dialog is open leaves the options as they are, +/// rather than switching to another preset's. +#[test] +fn reset_with_a_deleted_preset_keeps_the_options() { + let (mut app, _, _) = app(); + app.run("pdf.preset.save", json!({"name": "Gone", "compatibility": "1.5"})).unwrap(); + app.run("ui.savePdfDialog", json!({"preset": "Gone"})).unwrap(); + set_field(&mut app, "compatibility", json!("1.6")); + app.run("pdf.preset.delete", json!({"name": "Gone"})).unwrap(); + app.run("ui.dialogReset", json!({})).unwrap(); + let d = app.ui.dialog.as_ref().expect("the dialog stays open"); + assert_eq!(d.str("preset"), "Gone"); + assert_eq!(get(d, "compatibility"), "1.6"); +} + #[test] fn marks_and_bleeds_reach_the_pdf() { let (mut app, written, _) = app(); diff --git a/crates/ui-egui/src/dialogs/tests.rs b/crates/ui-egui/src/dialogs/tests.rs index 201b34171d..9e24b7a276 100644 --- a/crates/ui-egui/src/dialogs/tests.rs +++ b/crates/ui-egui/src/dialogs/tests.rs @@ -2524,6 +2524,31 @@ fn flare_options_alt_turns_cancel_into_reset() { ); } +/// While Alt is held, Save PDF's Cancel button reads Reset; Reset puts the chosen preset's settings +/// back and leaves the dialog open with its path, letting Alt go shows Cancel again, and Cancel +/// closes the dialog. +#[test] +fn save_pdf_alt_turns_cancel_into_reset() { + let mut app = app(); + app.run("ui.savePdfDialog", json!({"path": "/tmp/alt.pdf"})).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert("compatibility".into(), json!("1.4")); + let mut f = Frames::new(); + f.button(&mut app, "Cancel"); + f.run(&mut app, vec![egui::Event::ModifiersChanged(egui::Modifiers::ALT)]); + let reset = f.button(&mut app, "Reset"); + let texts = f.texts(&mut app); + assert!(!texts.iter().any(|(t, _)| t == "Cancel"), "Reset takes Cancel's place: {texts:?}"); + f.press(&mut app, reset, true); + f.press(&mut app, reset, false); + let d = app.ui.dialog.as_ref().expect("Reset leaves the dialog open"); + assert_eq!((d.str("compatibility"), d.str("path")), ("1.7".to_string(), "/tmp/alt.pdf".to_string())); + f.run(&mut app, vec![egui::Event::ModifiersChanged(egui::Modifiers::NONE)]); + let cancel = f.button(&mut app, "Cancel"); + f.press(&mut app, cancel, true); + f.press(&mut app, cancel, false); + assert!(app.ui.dialog.is_none(), "Cancel closes the dialog"); +} + /// Reset Actions' question: OK replaces the action sets with the built-in set, Append adds the /// built-in set after them, and Cancel or Escape (`cancel`) leaves them as they are. #[test] diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 2b285c704b..5e43e8576c 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1337,7 +1337,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.dialogReset", "Reset", "", - "{} the open dialog's Reset, which its Cancel button reads while Alt (Option on macOS) is held (Flare Tool Options, dialog `flareOptions`): its fields go back to their defaults and the dialog stays open, so OK applies them → the dialog; an error when no dialog is open or the open one has no Reset", + "{} the open dialog's Reset, which its Cancel button reads while Alt (Option on macOS) is held (Flare Tool Options, dialog `flareOptions`; Save PDF, dialog `savePdf`): its fields go back to their defaults (Save PDF: the chosen preset's settings, with the path and artboards kept) and the dialog stays open, so OK applies them → the dialog; an error when no dialog is open or the open one has no Reset", ), ( "ui.justification", diff --git a/docs/mcp.md b/docs/mcp.md index bee07110e6..ac1d935cfe 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -1259,6 +1259,9 @@ exporter plug-in's parameters. Other formats are written at once. OK writes the OK returns what `file.exportAs` returns, which has no `format` or `bounds` (Text Export Options: `{path}`). Any option skips the options dialog, but without `path` the save panel still picks the file. To write without a dialog, pass `path`. `file.exportAs {path, exportSelection: true, …options}` writes the selection the same way. +In the Save PDF dialog, `ui.dialogReset {}` (Cancel while Alt, or Option on macOS, is held) puts every option back to +the chosen preset's settings, clears the passwords, and leaves the dialog open with its preset, path, artboard range and +section; `answer_dialog {action: "cancel"}` still closes it without saving. Raster exports default to the document's raster effects resolution. An explicit `scale` sets pixels per point (72 times that value in ppi); `options.ppi` wins over either scale option. CLI `run --export` and diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index f506da06e1..ebd2c72f7b 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1940,6 +1940,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur In a `.ai` opened from its editing data, Bas Relief in an art style takes its Detail, Smoothness and Light direction from the style's settings block, and an object other than type with it opens as itself with the live effect. A settings block that VectorCraft can't read (malformed, another effect's, a value out of range or a key it doesn't know) keeps the object's drawn look (part of #637; [raster effects reference](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/apply-filter-effects/raster-effects-reference.html), [Photoshop File Formats Specification](https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/), [scripting the filter gallery](https://community.adobe.com/questions-712/scripting-support-for-the-filter-gallery-1064646); `crates/eps/src/import/ai/style/tests.rs`, `crates/eps/src/import/ai/tests.rs`). PDF export and `.ai` saves write a page with a side longer than 14,400 pt with a `UserUnit` (PDF 1.6), its longer side divided by 14,400 and rounded up to the next thousandth, so that no side is longer than 14,400 units (ISO 32000-1, Annex C.2); a PDF 1.5 file with such a page is written as PDF 1.6 with PDF 1.5's encryption, PDF/X files and PDF 1.3 and 1.4 files write it in points (in PDF 1.3 and 1.4, a page past 32,767 pt that needs a real number past 32,767 is refused with an error naming it), a page whose short side is 3 pt or longer but would be under 3 units at that `UserUnit` gets a smaller one that keeps the short side at 3 units, and the export's warnings give each such page's size and how it is written (#6382). The Save PDF dialog's "Write pages longer than 200 in at full size in points" (`longPagesInPoints`, on by default; `.ai` saves leave it off) writes such pages in points without a `UserUnit` at every PDF version, in files without a PDF/X or PDF/A standard, so readers that ignore `UserUnit` show them at full size. Export As PDF with Use Artboards off also opens the Save PDF dialog, without its Artboards section, and writes one page of the visible art's bounds with the dialog's options (`document.exportPdf {useArtboards: false}`; `crates/ui-egui/src/dialogs/tests_export.rs`, `crates/engine/src/cmd/fileio/tests_pdf.rs`). + While Alt (Option on macOS) is held, the Save PDF dialog's Cancel button reads Reset, which puts every option back to the chosen preset's settings, passwords included, and leaves the dialog open; letting the key go shows Cancel again (`ui.dialogReset`). [The help page](https://help.adobe.com/archive/en_US/illustrator/cs3/illustrator_cs3_help.pdf#page=283) says that holding Alt or Option and clicking Reset returns the options to their defaults. Resetting to the chosen preset's settings, and keeping the preset, path, artboard range and section, are VectorCraft's own rules (`crates/ui-egui/src/dialogs/save_pdf/tests.rs`, `crates/ui-egui/src/dialogs/tests.rs`). `document.exportSelection` run without params (a shortcut) takes the same route after its save panel: a picked PDF opens the Save PDF dialog without its Artboards section, and SVG, the raster formats, EPS, DXF, text and exporter plug-ins with parameters open their options, whose OK writes the selection alone, cropped to it, with the chosen options (`crates/ui-egui/src/dialogs/tests_export_selection.rs`). A `.ai` export with Use Artboards off writes one page of the visible art's bounds without the native document or the editing copy for other apps, with a warning, so the file does not reopen with one artboard in place of the document's; without PDF content it is refused (`crates/engine/src/cmd/fileio/tests_pdfedit.rs`). That page, and an HP-GL plot of the art's bounds, are measured on the art the file draws: non-printing layers the PDF or `.ai` file leaves out do not make it larger, and nor do the non-printing layers, objects at 0% opacity, placed images, clear gradient meshes and unpainted paths a plot leaves out; Export As refuses an HP-GL plot of nothing it draws before the save dialog (`crates/engine/src/cmd/fileio/tests_pdf.rs`, `crates/engine/src/cmd/fileio/tests_hpgl.rs`, `crates/ui-egui/src/dialogs/tests_export.rs`).