Save PDF: one field_set handles the flattener preset, and OK keeps the overprint option

The merge of main left two save_pdf::field_set functions, so the crate did not build. The
flattenerPreset case now sits in the function that ui.dialog.set reaches, and the unreachable
second branch in dialogs::field_set has been removed.

Custom... OK now keeps the preserveOverprints value the Save PDF options had before, instead of
the preset's value, so a stored false stays false.
This commit is contained in:
dotCooCoo
2026-11-18 14:15:51 -08:00
parent 91a361b520
commit 891da1e0b9
3 changed files with 34 additions and 21 deletions
-4
View File
@@ -716,10 +716,6 @@ pub(crate) fn field_set(app: &mut VectorcraftApp, field: &str, old: Option<&Valu
eps_options::field_set(d, field);
return Ok(());
}
if let Some(d) = app.ui.dialog.as_mut().filter(|d| d.kind == save_pdf::KIND) {
save_pdf::field_set(d, field);
return Ok(());
}
let Some(d) = app.ui.dialog.as_mut().filter(|d| d.kind == export_for_screens::KIND) else { return Ok(()) };
match field {
"exportPreset" => export_for_screens::preset_set(app),
+11 -12
View File
@@ -799,7 +799,8 @@ fn edit_bleed(d: &mut Dialog, side: usize, value: f64) {
/// `ui.dialog.set` set `field` of Save PDF or the PDF preset editor: `__bleedLinked` links or
/// unlinks the bleed as its button does, and must be true or false; every write of `bleed`, the
/// same values included, drops the link's state, so the link follows the values set.
/// same values included, drops the link's state, so the link follows the values set. A flattener
/// preset set there drops the Custom… options, as choosing it in the dropdown does.
pub(super) fn field_set(d: &mut Dialog, field: &str) -> Result<(), String> {
match field {
BLEED_LINKED => match d.fields.get(BLEED_LINKED).cloned() {
@@ -813,6 +814,10 @@ pub(super) fn field_set(d: &mut Dialog, field: &str) -> Result<(), String> {
d.fields.remove(BLEED_LINKED);
Ok(())
}
"flattenerPreset" => {
d.fields.remove("flattener");
Ok(())
}
_ => Ok(()),
}
}
@@ -953,6 +958,7 @@ fn custom_body(_app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) ->
fn custom_confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result<Value, String> {
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 base = match FlattenOptions::find_preset(&flattener_name(&parent), &app.session.prefs.flattener_presets) {
Some(base) => base,
None => {
@@ -960,11 +966,12 @@ fn custom_confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result<Value, String>
FlattenOptions::preset(pdf::DEFAULT_FLATTENER).unwrap_or_default()
}
};
// The writer sets these itself, so they take the preset's values: options that otherwise match
// the preset leave its name showing.
// 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.
o.clip_complex_regions = base.clip_complex_regions;
o.preserve_alpha = base.preserve_alpha;
o.preserve_overprints = base.preserve_overprints;
o.preserve_overprints = before.map_or(base.preserve_overprints, |b| b.preserve_overprints);
if o == base {
parent.fields.remove("flattener");
} else {
@@ -974,14 +981,6 @@ fn custom_confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result<Value, String>
Ok(Value::Null)
}
/// `ui.dialog.set` changed `field` of Save PDF `d`: a flattener preset set there drops the Custom…
/// options, as choosing it in the dropdown does.
pub(super) fn field_set(d: &mut Dialog, field: &str) {
if field == "flattenerPreset" {
d.fields.remove("flattener");
}
}
fn advanced(app: &VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) {
heading(ui, tl!("Fonts"));
let outline = get(d, "advanced.outlineText").as_bool() == Some(true);
+23 -5
View File
@@ -1049,11 +1049,15 @@ fn custom_options_are_written_until_a_preset_is_chosen() {
assert_eq!(d.fields["flattener"]["balance"].as_f64(), Some(0.0));
let saved = &app.session.prefs.flattener_presets;
assert_ne!(flattener(d, saved).ok(), FlattenOptions::preset(pdf::DEFAULT_FLATTENER), "the preset shows [Custom]");
// A preset set from outside drops the custom options.
let mut copy = d.clone();
set(&mut copy, "flattenerPreset", json!("Low Resolution"));
field_set(&mut copy, "flattenerPreset");
assert!(!copy.fields.contains_key("flattener"));
// A preset set through `ui.dialog.set` drops the custom options.
let kept = d.clone();
let dialog = app.ui.dialog.as_mut().unwrap();
assert!(super::super::accepts_field(dialog, "flattenerPreset"));
let old = dialog.fields.get("flattenerPreset").cloned();
super::super::set_field(dialog, "flattenerPreset".into(), json!("Low Resolution"));
super::super::field_set(&mut app, "flattenerPreset", old.as_ref()).unwrap();
assert!(!app.ui.dialog.as_ref().unwrap().fields.contains_key("flattener"));
app.ui.dialog = Some(kept);
super::super::confirm(&mut app).unwrap();
assert!(images(&written.borrow()[0].1) > 0, "balance 0 rasterizes the flattened art");
open_advanced(&mut app, json!({"compatibility": "1.3"}));
@@ -1075,6 +1079,20 @@ fn custom_options_equal_to_the_preset_leave_its_name() {
}
}
/// OK keeps Custom… options that drop overprints dropping them, although the preset keeps them.
#[test]
fn custom_keeps_options_that_drop_overprints() {
let (mut app, _, _) = app();
let params = json!({"compatibility": "1.3", "advanced": {"overprint": "preserve"}, "flattener": {"preserveOverprints": false}});
open_advanced(&mut app, params);
Reader::new().click_custom(&mut app);
assert!(!app.ui.dialog.as_ref().unwrap().bool("preserveOverprints"), "shown as written");
super::super::confirm(&mut app).unwrap();
assert_eq!(kind(&app), Some(KIND));
let d = app.ui.dialog.as_ref().unwrap();
assert_eq!(flattener(d, &app.session.prefs.flattener_presets).map(|o| o.preserve_overprints), Ok(false));
}
#[test]
fn custom_shows_alpha_as_the_pdf_1_3_writer_drops_it() {
let (mut app, written, _) = app();