mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 13:32:45 -05:00
Scripts: print writes level 2 PostScript when postScriptLevel is not assigned
A PrintPostScriptOptions object reads postScriptLevel as PSLEVEL2, its help page's default, but a job written to a .ps file without that property assigned sent no level to file.print, which wrote level 3. Document.print now sends level 2 for every PostScript job unless PSLEVEL3 is assigned. The print test checks the %%LanguageLevel comment of an unassigned .ps job (2) and of a job with PSLEVEL3 assigned (3). docs/mcp.md and the module notes state the default.
This commit is contained in:
1 parent
b9f9eb744b
commit
0830cd1695
3 files changed
+12
-6
No files matched your search
@@ -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() {
|
||||
|
||||
@@ -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.
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
Reference in new issue
Block a user