DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge branch 'package-dialog' into package-pdf-preset
moppeeer2ddb60fa4378
diff --cc crates/engine/src/cmd/package.rsindex 8d3915a4f,de3846114..d415108c9--- a/crates/engine/src/cmd/package.rs+++ b/crates/engine/src/cmd/package.rs@@@ -445,13 -434,16 +445,14 @@@ fn package(s: &mut Session, p: &Value)root.write(&path, &designcraft_idml::export_idml_with(&packed, &opts))?;files.push(path);}- if p.get("pdf").and_then(Value::as_bool).unwrap_or(false) {+ if let Some(params) = pdf {let path = package_output_path(&dir, &title, "pdf")?;- let bytes = designcraft_pdf::export_pdf(&super::interchange::with_pdf_boxes(&packed), &s.cache, &Default::default())- .map_err(|e| EngineError::Other(e.to_string()))?;- root.write(&path, &bytes)?;+ root.write(&path, &super::export::pdf_report(&packed, &s.cache, ¶ms)?.bytes)?;files.push(path);}- // The report: fonts (missing first), links, preflight, the user's instructions.- let mut r = format!("Package report: {display_title}\n\n");+ // The printing instructions first, as the form gave them; then the report: fonts (missing+ // first), links, preflight.+ let mut r = String::new();if let Some(t) = str_param(p, "instructions").filter(|t| !t.trim().is_empty()) {r += &format!("Instructions\n{t}\n\n");}diff --cc crates/ui-egui/src/package_dialog.rsindex fbf4ba5ed,e064fd1f4..5bedef97e--- a/crates/ui-egui/src/package_dialog.rs+++ b/crates/ui-egui/src/package_dialog.rs@@@ -81,13 -75,10 +75,14 @@@ pub fn open(app: &mut DesignApp) -> Res.collect()}).unwrap_or_default();+ // The packaged PDF's preset: the one last used for Export PDF, as InDesign suggests it.+ let last = app.ui.pdf_export.preset.clone();+ let preset = crate::dialogs::pdf_presets().find(|p| *p == last).unwrap_or("Desktop Printing");+ let doc = app.session.active().map(|d| d.uid);app.ui.dialog = Some(Dialog::new(ID,- json!({"page": "summary", "fonts": fonts, "links": links, "spot": spot, "instructions": false, "idml": true, "pdf": false,- json!({"page": "summary", "doc": doc, "fonts": fonts, "links": links, "spot": spot, "instructions": false, "idml": true, "pdf": false, "problemsOnly": false}),++ json!({"page": "summary", "doc": doc, "fonts": fonts, "links": links, "spot": spot, "instructions": false, "idml": true, "pdf": false,+ "pdfPreset": preset, "problemsOnly": false}),));Ok(())}@@@ -288,16 -282,12 +304,17 @@@ pub fn show(app: &DesignApp, ui: &mut e});}+/// The `pdf` of `file.package`: false, or the options of the chosen PDF preset.+fn pdf_param(d: &Dialog) -> Value {+ if d.b("pdf") { crate::dialogs::pdf_preset_params(&d.s("pdfPreset")) } else { json!(false) }+}+/// Package…: the Printing Instructions first when asked for, else the folder.pub fn confirm(app: &mut DesignApp, d: &Dialog) -> Result<Value, String> {+ same_document(app, d)?;- let (idml, pdf) = (d.b("idml"), d.b("pdf"));+ let (idml, pdf) = (d.b("idml"), pdf_param(d));if d.b("instructions") {- app.ui.dialog = Some(Dialog::new(INSTRUCTIONS, json!({"idml": idml, "pdf": pdf})));+ app.ui.dialog = Some(Dialog::new(INSTRUCTIONS, json!({"idml": idml, "pdf": pdf, "doc": d.fields.get("doc")})));return Ok(Value::Null);}package_to_folder(app, idml, pdf, None)@@@ -345,13 -340,13 +367,14 @@@ fn instructions_text(d: &Dialog) -> Str/// Continue: the folder, with the instructions.pub fn confirm_instructions(app: &mut DesignApp, d: &Dialog) -> Result<Value, String> {+ same_document(app, d)?;let text = instructions_text(d);- package_to_folder(app, d.b("idml"), d.b("pdf"), Some(text).filter(|t| !t.is_empty()))+ package_to_folder(app, d.b("idml"), d.fields.get("pdf").cloned().unwrap_or(json!(false)), Some(text).filter(|t| !t.is_empty()))}-/// Ask for the folder to create ("<title> Folder") and package the document into it.-pub fn package_to_folder(app: &mut DesignApp, idml: bool, pdf: bool, instructions: Option<String>) -> Result<Value, String> {+/// Ask for the folder to create ("<title> Folder") and package the document into it. `pdf`:+/// false, true or the PDF's `file.exportPdf` options.+pub fn package_to_folder(app: &mut DesignApp, idml: bool, pdf: Value, instructions: Option<String>) -> Result<Value, String> {let name = app.session.active().map(|d| format!("{} Folder", d.doc.title)).unwrap_or_default();// Beside the document, or where the last file was saved (main's `pick_save`, #1653).let Some(dir) = app.pick_save(&name) else { return Ok(Value::Null) };