From 10b33033ac678f8eb9952fd11a6af2aafc6a3974 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 23:16:55 -0800 Subject: [PATCH] Save PDF: the Summary is computed again when flattener presets, profiles or fonts change The cached Summary's stamp now also includes the saved flattener presets, the loaded color profiles and the available fonts, so deleting the flattener preset the dialog names, or removing the profile it converts to, while the dialog stays open no longer leaves the Summary section and ui.pdfSummary.save showing settings that a fresh computation refuses. --- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/dialogs/save_pdf.rs | 20 +++++---- crates/ui-egui/src/dialogs/save_pdf/tests.rs | 43 ++++++++++++++++++++ crates/ui-egui/src/menus/ui_commands.rs | 2 +- docs/mcp.md | 3 +- 5 files changed, 60 insertions(+), 10 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index 90c2a103e8..cb26147ccf 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1390,7 +1390,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.pdfSummary.save", "Save Summary…", "", - "{path} write the Summary of the open Save PDF dialog (or PDF preset editor) to path as UTF-8 text without a byte order mark, with LF line endings, line for line as the Summary section shows it: Options and each option that differs from the preset (or the line saying none does), a blank line, then Warnings and each warning (or None.). The Summary the section last drew for the same fields, document and saved presets is used without computing the settings again. The web downloads the file under path's file name. The Summary section's Save Summary… button writes the same text to a file picked in a save panel that suggests ` PDF Summary.txt` in the document's folder. The dialog stays open and the document does not change. No such dialog open, a path that is missing, empty or not a string, a path outside the automation write roots and a failed document.pdfSettings are errors that write nothing; a failed write is an error → {path, bytes}", + "{path} write the Summary of the open Save PDF dialog (or PDF preset editor) to path as UTF-8 text without a byte order mark, with LF line endings, line for line as the Summary section shows it: Options and each option that differs from the preset (or the line saying none does), a blank line, then Warnings and each warning (or None.). The Summary the section last drew for the same fields, document, saved PDF and flattener presets, loaded color profiles and available fonts is used without computing the settings again. The web downloads the file under path's file name. The Summary section's Save Summary… button writes the same text to a file picked in a save panel that suggests ` PDF Summary.txt` in the document's folder. The dialog stays open and the document does not change. No such dialog open, a path that is missing, empty or not a string, a path outside the automation write roots and a failed document.pdfSettings are errors that write nothing; a failed write is an error → {path, bytes}", ), ( "file.exportAs", diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs index 957a3beaf5..353f956b21 100644 --- a/crates/ui-egui/src/dialogs/save_pdf.rs +++ b/crates/ui-egui/src/dialogs/save_pdf.rs @@ -852,7 +852,8 @@ pub(super) fn option_label(option: &str) -> String { } /// `document.pdfSettings` for the dialog with the document's warnings (an export in memory), -/// cached until a field, the document or the saved presets change. +/// cached until a field, the document, the saved PDF or flattener presets, the loaded color +/// profiles or the available fonts change. fn summary_of(app: &mut VectorcraftApp, ctx: &egui::Context, p: &Value) -> Result { let (key, stamp) = summary_key(app, p); if let Some((s, v)) = ctx.data(|m| m.get_temp::<(egui::Id, Result)>(key)) @@ -865,12 +866,17 @@ fn summary_of(app: &mut VectorcraftApp, ctx: &egui::Context, p: &Value) -> Resul v } -/// Where [`summary_of`] keeps the Summary, and the stamp of the params `p`, the active document -/// and its revision, and the saved presets (which `preset` can name) it was computed for. +/// Where [`summary_of`] keeps the Summary, and the stamp of what it was computed for: the params +/// `p`, the active document and its revision, the saved PDF presets (which `preset` can name), the +/// saved flattener presets (which `flattenerPreset` can name), the loaded color profiles (which +/// `output.destination` and `output.outputIntent` can name) and the available fonts (which decide +/// what is embedded or outlined). fn summary_key(app: &VectorcraftApp, p: &Value) -> (egui::Id, egui::Id) { let document = app.session.active().map(|s| (s.uid, s.revision)); - let presets = serde_json::to_string(&app.session.prefs.pdf_presets).unwrap_or_default(); - (egui::Id::unique("save-pdf-summary"), egui::Id::unique((p.to_string(), document, presets))) + let prefs = &app.session.prefs; + let presets = serde_json::to_string(&(&prefs.pdf_presets, &prefs.flattener_presets)).unwrap_or_default(); + let shared = (vectorcraft_color::cms::profiles_generation(), vectorcraft_text::FontDb::global().generation()); + (egui::Id::unique("save-pdf-summary"), egui::Id::unique((p.to_string(), document, presets, shared))) } /// `document.pdfSettings` for the dialog's `document.exportPdf` params `p`, with the document's @@ -968,8 +974,8 @@ pub(crate) fn summary_open(app: &VectorcraftApp) -> bool { /// `ui.pdfSummary.save {path}`: write the open Save PDF dialog's (or preset editor's) Summary as /// text to `path` (the web downloads it under the path's file name). The Summary the section last -/// drew for the same fields, document and saved presets is used as it is; the settings are -/// computed only when there is none. The dialog stays open and the document is not changed → +/// drew for the same fields, document, saved PDF and flattener presets, loaded color profiles +/// and available fonts is used as it is; the settings are computed only when there is none. The dialog stays open and the document is not changed → /// `{path, bytes}`. A missing, empty or non-string `path` is an error that writes nothing. pub(crate) fn save_summary(app: &mut VectorcraftApp, p: &Value) -> Result { let key = "path"; diff --git a/crates/ui-egui/src/dialogs/save_pdf/tests.rs b/crates/ui-egui/src/dialogs/save_pdf/tests.rs index 8568d1fbbc..506257247c 100644 --- a/crates/ui-egui/src/dialogs/save_pdf/tests.rs +++ b/crates/ui-egui/src/dialogs/save_pdf/tests.rs @@ -238,6 +238,49 @@ fn save_summary_compares_against_a_replaced_preset() { assert!(text.starts_with("Options\nEvery option matches the preset.\n"), "compared against the replaced preset: {text}"); } +/// The Summary is computed again when the saved flattener preset the dialog names is deleted while +/// the dialog stays open: the settings are then refused, and nothing is written. +#[test] +fn save_summary_sees_a_deleted_flattener_preset() { + let (mut app, written, _) = app(); + app.run("flattener.presets.save", json!({"name": "Mine Flat", "preset": "Low Resolution"})).unwrap(); + app.run("file.export.pdf", json!({})).unwrap(); + set_field(&mut app, "flattenerPreset", json!("Mine Flat")); + app.ui_ctx = Some(egui::Context::default()); + app.run(SAVE_SUMMARY, json!({"path": "/tmp/a.txt"})).unwrap(); + app.run("flattener.presets.delete", json!({"name": "Mine Flat"})).unwrap(); + let e = app.run(SAVE_SUMMARY, json!({"path": "/tmp/b.txt"})).unwrap_err(); + assert!(e.contains("Mine Flat"), "the deleted preset is refused: {e}"); + assert_eq!(written.borrow().len(), 1, "nothing written for the deleted preset"); +} + +/// The Summary is computed again when a loaded profile the dialog converts to is removed while the +/// dialog stays open: the settings are then refused, and nothing is written. +#[test] +fn save_summary_sees_a_removed_profile() { + use vectorcraft_color::cms; + let name = "Summary Stamp CMYK"; + // The built-in CMYK profile's file renamed `name`: padded with spaces, which names drop. + let utf16 = |s: &str| s.encode_utf16().flat_map(u16::to_be_bytes).collect::>(); + let mut bytes = cms::icc_bytes(cms::DEVICE_CMYK).unwrap().to_vec(); + let (from, to) = (utf16(cms::DEVICE_CMYK), utf16(&format!("{name: PDF Summary.txt` in the document's folder. The dialog stays open and the document does not change. No such dialog open, a path that is missing, empty or not a string, a path outside the automation write roots and a failed document.pdfSettings are errors that write nothing; a failed write is an error → {path, bytes}", + "{path} write the Summary of the open Save PDF dialog (or PDF preset editor) to path as UTF-8 text without a byte order mark, with LF line endings, line for line as the Summary section shows it: Options and each option that differs from the preset (or the line saying none does), a blank line, then Warnings and each warning (or None.). The Summary the section last drew for the same fields, document, saved PDF and flattener presets, loaded color profiles and available fonts is used without computing the settings again. The web downloads the file under path's file name. The Summary section's Save Summary… button writes the same text to a file picked in a save panel that suggests ` PDF Summary.txt` in the document's folder. The dialog stays open and the document does not change. No such dialog open, a path that is missing, empty or not a string, a path outside the automation write roots and a failed document.pdfSettings are errors that write nothing; a failed write is an error → {path, bytes}", ), ( "file.exportAs", diff --git a/docs/mcp.md b/docs/mcp.md index f0e23a5587..2b44d116c7 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -1345,7 +1345,8 @@ The Summary section's Save Summary… button writes what the section shows to a mark, LF line endings), and its save panel suggests ` PDF Summary.txt` in the document's folder; the web downloads the file under that name. `ui.pdfSummary.save {path}` writes the same text for the open Save PDF dialog or PDF preset editor to `path` and returns `{path, bytes}`. It uses the Summary the section last drew for the same fields, -document and saved presets, and computes the settings only when there is none. No such dialog open, a `path` that is missing, empty +document, saved PDF and flattener presets, loaded color profiles and available fonts, and computes the settings only +when there is none. No such dialog open, a `path` that is missing, empty or not a string, a path outside the automation write roots and settings that `document.pdfSettings` refuses are errors that write nothing. The dialog stays open and the document does not change. `thumbnails: true` embeds each page drawn small (106 px on its long side, without the layers the page leaves out) as