Save PDF: OK on Custom… keeps the overprint option of a saved preset deleted meanwhile

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.
This commit is contained in:
dotCooCoo
2026-11-18 16:01:48 -08:00
parent 6d8b6f11e2
commit 5f23bea81a
2 changed files with 29 additions and 2 deletions
+12 -2
View File
@@ -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, String> {
FlattenOptions::from_params_with(&Value::Object(d.fields.clone()), &[])
@@ -968,10 +974,14 @@ fn custom_confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result<Value, String>
};
// 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 {
@@ -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();