diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs index 756d2111a2..0b9f2df9fb 100644 --- a/crates/ui-egui/src/dialogs/save_pdf.rs +++ b/crates/ui-egui/src/dialogs/save_pdf.rs @@ -964,7 +964,11 @@ fn custom_body(_app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> fn custom_confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { let mut o = custom_options(d)?; let mut parent = super::parent(d).ok_or("the dialog it was opened over is no longer open")?; - let before = flattener(&parent, &app.session.prefs.flattener_presets).ok(); + let kept = d + .fields + .get(KEPT_OVERPRINTS) + .and_then(Value::as_bool) + .or_else(|| flattener(&parent, &app.session.prefs.flattener_presets).ok().map(|before| before.preserve_overprints)); let base = match FlattenOptions::find_preset(&flattener_name(&parent), &app.session.prefs.flattener_presets) { Some(base) => base, None => { @@ -974,14 +978,11 @@ 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, or the - // value they opened with when those can no longer be read. + // options and Overprint both keep them, so the options keep the value they opened with, even + // when their preset was deleted, changed or made again under its name meanwhile. o.clip_complex_regions = base.clip_complex_regions; o.preserve_alpha = base.preserve_alpha; - 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), - }; + o.preserve_overprints = kept.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 27679f771d..fbf790b7c9 100644 --- a/crates/ui-egui/src/dialogs/save_pdf/tests.rs +++ b/crates/ui-egui/src/dialogs/save_pdf/tests.rs @@ -1151,6 +1151,22 @@ fn custom_keeps_the_overprint_option_of_a_saved_preset_deleted_meanwhile() { } } +/// OK keeps the overprint option Custom… opened with when its saved preset is deleted and made +/// again under the same name with another overprint option meanwhile. +#[test] +fn custom_keeps_the_overprint_option_it_opened_with_over_a_preset_made_again() { + let (mut app, _, _) = app(); + app.run("flattener.presets.save", json!({"name": "Mine", "balance": 20, "preserveOverprints": false})).unwrap(); + open_advanced(&mut app, json!({"compatibility": "1.3", "flattenerPreset": "Mine", "advanced": {"overprint": "preserve"}})); + Reader::new().click_custom(&mut app); + assert!(!app.ui.dialog.as_ref().unwrap().bool("preserveOverprints"), "shown as the preset had it"); + app.run("flattener.presets.delete", json!({"name": "Mine"})).unwrap(); + app.run("flattener.presets.save", json!({"name": "Mine", "balance": 20, "preserveOverprints": true})).unwrap(); + super::super::confirm(&mut app).unwrap(); + let d = app.ui.dialog.as_ref().unwrap(); + assert_eq!(d.fields["flattener"]["preserveOverprints"].as_bool(), Some(false)); +} + /// Flattener preset shows a preset named in another case by its name, not as [Custom]. #[test] fn flattener_preset_shows_a_name_given_in_any_case() {