diff --git a/crates/engine/src/script/dom/print.rs b/crates/engine/src/script/dom/print.rs index 29d09da58c..2332739c85 100644 --- a/crates/engine/src/script/dom/print.rs +++ b/crates/engine/src/script/dom/print.rs @@ -20,7 +20,8 @@ //! VectorCraft's own rules, which the help pages do not state: //! - `print` writes a file: `jobOptions.file` names it, a `File` the script may write //! ([`super::super::files`]). PostScript is written when the name ends with `.ps` or -//! `postScriptOptions.postScriptLevel` is set, a print-ready PDF otherwise. Printing to a printer +//! `postScriptOptions.postScriptLevel` is set, a print-ready PDF otherwise. The PostScript is +//! level 2 when `postScriptLevel` is not assigned, the default it reads as. Printing to a printer //! from a script is not available yet, so `print` without a file throws an error. //! - Only the properties a script assigned apply; the others keep the settings `print` starts //! from: the preset's when `printPreset` is assigned, otherwise the document's print settings @@ -850,8 +851,9 @@ fn doc_print(h: &Host, a: &[Data]) -> Answer { // The format follows the name `jobOptions.file` gives, not the real path a link leads to. let postscript = job.level.is_some() || crate::cmd::fileio::extension(path) == "ps"; p.insert("format".into(), json!(if postscript { "postscript" } else { "pdf" })); - if let Some(level) = job.level { - p.insert("level".into(), json!(level)); + // PostScript prints at the level the options read as: an unassigned `postScriptLevel` is `PSLEVEL2`. + if postscript { + p.insert("level".into(), json!(job.level.unwrap_or(2))); } let settings = job.settings(); if !settings.is_empty() { diff --git a/crates/engine/src/tests/script_print.rs b/crates/engine/src/tests/script_print.rs index a9eb84b75d..e115c60aae 100644 --- a/crates/engine/src/tests/script_print.rs +++ b/crates/engine/src/tests/script_print.rs @@ -84,6 +84,8 @@ fn print_writes_the_file_with_the_assigned_options_over_the_saved_settings() { j.file = new File(dir + '/c.ps'); doc.print(o);\n\ o.postScriptOptions.postScriptLevel = PrinterPostScriptLevelEnum.PSLEVEL2; j.file = new File(dir + '/level2.prn');\n\ doc.print(o);\n\ + o.postScriptOptions.postScriptLevel = PrinterPostScriptLevelEnum.PSLEVEL3; j.file = new File(dir + '/level3.ps');\n\ + doc.print(o);\n\ vc.log([app.printPresetsList[0], app.PPDFileList.length]);" ), ); @@ -96,9 +98,11 @@ fn print_writes_the_file_with_the_assigned_options_over_the_saved_settings() { assert_eq!(pages(&dir.join("a.pdf")).len(), 6, "two artboards, three copies"); assert_eq!(pages(&dir.join("b.pdf")), vec![(595.0, 842.0)], "artboard 2 only, on upright A4"); let ps = std::fs::read_to_string(dir.join("c.ps")).unwrap(); - assert!(ps.starts_with("%!PS") && !ps.contains("%%LanguageLevel: 2"), "a .ps name alone: {}", &ps[..ps.len().min(200)]); + assert!(ps.starts_with("%!PS") && ps.contains("%%LanguageLevel: 2"), "a .ps name alone prints at PSLEVEL2: {}", &ps[..ps.len().min(200)]); let ps = std::fs::read_to_string(dir.join("level2.prn")).unwrap(); assert!(ps.starts_with("%!PS") && ps.contains("%%LanguageLevel: 2"), "a level alone: {}", &ps[..ps.len().min(200)]); + let ps = std::fs::read_to_string(dir.join("level3.ps")).unwrap(); + assert!(ps.starts_with("%!PS") && ps.contains("%%LanguageLevel: 3"), "an assigned PSLEVEL3: {}", &ps[..ps.len().min(200)]); assert_eq!(s.execute("print.setup", &json!({})).unwrap()["settings"], saved, "printing leaves the saved settings as they are"); assert_eq!(s.active().unwrap().history.undo.len(), undo, "and adds no undo step"); // The commands stay closed to vc.run, before and after a print. diff --git a/docs/mcp.md b/docs/mcp.md index f518963b46..474f7a1897 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2761,8 +2761,8 @@ app through the global object `vc`, and writes to the Script Console and runs ot `FontSubstitutionPolicy`, `PageMarksTypes`, `PostScriptImageCompressionType` and `PrinterPostScriptLevelEnum` hold strings such as `"PrintTiling.TILEFULLPAGES"`. VectorCraft's own rules: `print` writes the file `jobOptions.file` names, checked as `saveAs` checks its file: PostScript when the name ends with `.ps` or `postScriptLevel` is - assigned, a print-ready PDF otherwise, also when that name is a link to a file with another extension. Without a - file it throws `Printing to a printer is not available to scripts yet`, and `app.printerList` throws an error + assigned, a print-ready PDF otherwise, also when that name is a link to a file with another extension. The + PostScript is level 2 when `postScriptLevel` is not assigned, the default it reads as. Without a file it throws `Printing to a printer is not available to scripts yet`, and `app.printerList` throws an error that says it is not available yet. `fitToPage` set to true wins over the scale factors and the tiling mode. With `printAllArtboards` false, `artboardRange` picks the artboards, and without a range every artboard prints. With `printAllArtboards` not assigned, an assigned `artboardRange` replaces the range of the settings `print` starts