From 5f23bea81a2fb6880b773c5d358c04b3781c5c2a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 15:31:39 -0800 Subject: [PATCH] =?UTF-8?q?Save=20PDF:=20OK=20on=20Custom=E2=80=A6=20keeps?= =?UTF-8?q?=20the=20overprint=20option=20of=20a=20saved=20preset=20deleted?= =?UTF-8?q?=20meanwhile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the saved flattener preset was deleted while Custom… was open, OK set preserveOverprints to the default preset's value, so overprints the deleted preset dropped came back with Overprint set to Preserve. OK now keeps the value the options opened with, before Overprint applies to it. --- crates/ui-egui/src/dialogs/save_pdf.rs | 14 ++++++++++++-- crates/ui-egui/src/dialogs/save_pdf/tests.rs | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs index e00035708c..ba58b4d3a1 100644 --- a/crates/ui-egui/src/dialogs/save_pdf.rs +++ b/crates/ui-egui/src/dialogs/save_pdf.rs @@ -923,13 +923,19 @@ fn as_written(o: &mut FlattenOptions, parent: &Dialog) { /// (the default preset's while those are not valid). pub(super) fn over(parent: &Dialog, saved: &[FlattenerPreset]) -> Dialog { let mut o = flattener(parent, saved).unwrap_or_else(|_| FlattenOptions::preset(pdf::DEFAULT_FLATTENER).unwrap_or_default()); + let kept = o.preserve_overprints; as_written(&mut o, parent); let mut d = Dialog::new(CUSTOM_KIND, json!({})); super::flatten::put_options(&mut d.fields, &o); + d.fields.insert(KEPT_OVERPRINTS.into(), json!(kept)); d.fields.insert(super::PARENT.into(), serde_json::to_value(parent).unwrap_or_default()); d } +/// The `preserveOverprints` value of the options Custom Transparency Flattener Options opened on, +/// before Overprint applies to it. +const KEPT_OVERPRINTS: &str = "__keptOverprints"; + /// The options Custom Transparency Flattener Options `d` holds. fn custom_options(d: &Dialog) -> Result { FlattenOptions::from_params_with(&Value::Object(d.fields.clone()), &[]) @@ -968,10 +974,14 @@ fn custom_confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result }; // The writer sets the first two itself, so they take the preset's values: options that // otherwise match the preset leave its name showing. The writer keeps overprints only where the - // options and Overprint both keep them, so the options keep the value they had before. + // options and Overprint both keep them, so the options keep the value they had before, or the + // value they opened with when those can no longer be read. o.clip_complex_regions = base.clip_complex_regions; o.preserve_alpha = base.preserve_alpha; - o.preserve_overprints = before.map_or(base.preserve_overprints, |b| b.preserve_overprints); + o.preserve_overprints = match before { + Some(before) => before.preserve_overprints, + None => d.fields.get(KEPT_OVERPRINTS).and_then(Value::as_bool).unwrap_or(o.preserve_overprints), + }; if o == base { parent.fields.remove("flattener"); } else { diff --git a/crates/ui-egui/src/dialogs/save_pdf/tests.rs b/crates/ui-egui/src/dialogs/save_pdf/tests.rs index 116f33e262..23df91d541 100644 --- a/crates/ui-egui/src/dialogs/save_pdf/tests.rs +++ b/crates/ui-egui/src/dialogs/save_pdf/tests.rs @@ -1134,6 +1134,23 @@ fn custom_options_outlive_a_saved_preset_deleted_meanwhile() { assert!(written.borrow()[0].1.starts_with(b"%PDF-1.3")); } +/// OK keeps the overprint option of a saved preset deleted meanwhile, whichever value Overprint +/// shows it with, although the default preset keeps overprints. +#[test] +fn custom_keeps_the_overprint_option_of_a_saved_preset_deleted_meanwhile() { + let (mut app, _, _) = app(); + for (kept, overprint) in [(false, "preserve"), (true, "discard")] { + app.run("flattener.presets.save", json!({"name": "Mine", "balance": 20, "preserveOverprints": kept})).unwrap(); + open_advanced(&mut app, json!({"compatibility": "1.3", "flattenerPreset": "Mine", "advanced": {"overprint": overprint}})); + Reader::new().click_custom(&mut app); + assert!(!app.ui.dialog.as_ref().unwrap().bool("preserveOverprints"), "shown as written ({overprint})"); + app.run("flattener.presets.delete", json!({"name": "Mine"})).unwrap(); + super::super::confirm(&mut app).unwrap(); + let d = app.ui.dialog.as_ref().unwrap(); + assert_eq!(d.fields["flattener"]["preserveOverprints"].as_bool(), Some(kept), "{overprint}"); + } +} + #[test] fn save_preset_says_it_leaves_the_custom_flattener_options_out() { let (mut app, _, _) = app();