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.
This commit is contained in:
dotCooCoo
2026-11-16 23:16:55 -08:00
parent 47bfa3d1c5
commit 10b33033ac
5 changed files with 60 additions and 10 deletions
+1 -1
View File
@@ -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 `<document> 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 `<document> 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",
+13 -7
View File
@@ -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<Value, String> {
let (key, stamp) = summary_key(app, p);
if let Some((s, v)) = ctx.data(|m| m.get_temp::<(egui::Id, Result<Value, String>)>(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<Value, String> {
let key = "path";
@@ -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::<Vec<u8>>();
let mut bytes = cms::icc_bytes(cms::DEVICE_CMYK).unwrap().to_vec();
let (from, to) = (utf16(cms::DEVICE_CMYK), utf16(&format!("{name:<width$}", width = cms::DEVICE_CMYK.len())));
let at = bytes.windows(from.len()).position(|w| w == from).unwrap();
bytes[at..at + to.len()].copy_from_slice(&to);
let path = vectorcraft_testkit::temp_dir("save-summary-profile").join("stamp.icc");
std::fs::write(&path, bytes).unwrap();
let (mut app, written, _) = app();
assert_eq!(app.run("color.loadProfile", json!({"path": path.to_str().unwrap()})).unwrap()["name"], name);
app.run("file.export.pdf", json!({})).unwrap();
set_field(&mut app, "output.conversion", json!("destination"));
set_field(&mut app, "output.destination", json!(name));
app.ui_ctx = Some(egui::Context::default());
app.run(SAVE_SUMMARY, json!({"path": "/tmp/a.txt"})).unwrap();
app.run("color.removeProfile", json!({"name": name})).unwrap();
let e = app.run(SAVE_SUMMARY, json!({"path": "/tmp/b.txt"})).unwrap_err();
assert!(e.contains(name), "the removed profile is refused: {e}");
assert_eq!(written.borrow().len(), 1, "nothing written for the removed profile");
}
/// With the desktop's file writer: a file already at the path is replaced whole, a folder's path
/// is an error that leaves the folder as it was, and under automation write roots a path outside
/// them is refused without writing.
+1 -1
View File
@@ -1391,7 +1391,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 `<document> 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 `<document> 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",
+2 -1
View File
@@ -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 `<document> 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