mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 04:52:54 -05:00
Scripts: addDocument and addDocumentNoUI count for print, docs name the preset base
The script checker reports `print` on a document that `documents.addDocument()` or `documents.addDocumentNoUI()` returns, with or without `app.`, as a file write, as it does for `documents.add()`. Both methods return a Document on the Documents help page. docs/mcp.md and the print module's notes say that with `printPreset` assigned, `print` starts from the preset's settings: an assigned `artboardRange` replaces that range, and an unassigned scale factor keeps the preset's value.
This commit is contained in:
1 parent
42409dc6ee
commit
141dc48e1a
4 files changed
+33
-15
No files matched your search
@@ -22,7 +22,8 @@
|
||||
//! ([`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
|
||||
//! 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 document's print settings
|
||||
//! - 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
|
||||
//! (`print.setup`), which `print` leaves as they are. A property that was not assigned reads as
|
||||
//! the default its help page gives.
|
||||
//! - A property the help pages list that is not mapped accepts the default its help page gives
|
||||
@@ -30,12 +31,14 @@
|
||||
//! - `fitToPage` set to true wins over the scale factors and the tiling mode.
|
||||
//! - With `printAllArtboards` set to false, `artboardRange` picks the artboards; without a range
|
||||
//! every artboard prints. With `printAllArtboards` not assigned, an assigned `artboardRange`
|
||||
//! replaces the saved range, which prints when the saved settings print a range.
|
||||
//! - An assigned `printArea` prints by artboard when the saved settings, or the preset's, ignore
|
||||
//! the artboards: the artboards an assigned `artboardRange` names, otherwise each artboard.
|
||||
//! replaces the range of the settings `print` starts from, which prints when those settings
|
||||
//! print a range.
|
||||
//! - An assigned `printArea` prints by artboard when the settings `print` starts from ignore the
|
||||
//! artboards: the artboards an assigned `artboardRange` names, otherwise each artboard.
|
||||
//! - The format follows the name `jobOptions.file` gives, also when that name is a link to a file
|
||||
//! with another extension.
|
||||
//! - With one of `horizontalScale` and `verticalScale` assigned, the other keeps the saved value.
|
||||
//! - With one of `horizontalScale` and `verticalScale` assigned, the other keeps its value in the
|
||||
//! settings `print` starts from.
|
||||
//! - `print` throws, before anything is written, when an assigned `artboardRange` names an artboard
|
||||
//! the document does not have, also with `printAllArtboards` true; when `printPreset` or
|
||||
//! `flattenerPreset` is not the name of a preset (any case); when `colorManagementOptions.name` is
|
||||
@@ -715,7 +718,8 @@ fn map_coordinate(h: &Host, slot: usize, job: &mut Job) -> std::result::Result<(
|
||||
job.top.insert("scaling".into(), json!(scaling));
|
||||
}
|
||||
if scaled && fit != Some(true) {
|
||||
// Only the assigned factors are sent; with one of them, the other keeps the saved value.
|
||||
// Only the assigned factors are sent; with one of them, the other keeps its value in the
|
||||
// base settings (the preset's or the saved ones).
|
||||
let g = job.group("scale");
|
||||
if let Some(w) = hs {
|
||||
g.insert("width".into(), json!(w));
|
||||
|
||||
@@ -83,7 +83,8 @@ pub(crate) const DOM_PRINT: &str = "print";
|
||||
|
||||
// The member chains that give a document, whole and as the chains are written (`[]` for an index,
|
||||
// `()` for a call): https://ai-scripting.docsforadobe.dev/jsobjref/Application/ (`activeDocument`,
|
||||
// `documents`, `open`) and https://ai-scripting.docsforadobe.dev/jsobjref/Documents/ (`add`, `getByName`).
|
||||
// `documents`, `open`) and https://ai-scripting.docsforadobe.dev/jsobjref/Documents/ (`add`, `addDocument`,
|
||||
// `addDocumentNoUI`, `getByName`).
|
||||
pub(crate) const DOM_DOCUMENTS: &[&str] = &[
|
||||
"activeDocument",
|
||||
"app.activeDocument",
|
||||
@@ -91,6 +92,10 @@ pub(crate) const DOM_DOCUMENTS: &[&str] = &[
|
||||
"app.documents[]",
|
||||
"documents.add()",
|
||||
"app.documents.add()",
|
||||
"documents.addDocument()",
|
||||
"app.documents.addDocument()",
|
||||
"documents.addDocumentNoUI()",
|
||||
"app.documents.addDocumentNoUI()",
|
||||
"documents.getByName()",
|
||||
"app.documents.getByName()",
|
||||
"app.open()",
|
||||
|
||||
@@ -559,7 +559,8 @@ fn save_as_and_export_file_in_brackets_write_a_file() {
|
||||
}
|
||||
|
||||
/// A document's `print` writes the file its options' `jobOptions.file` names, called with a dot or
|
||||
/// with its name in brackets, on a document or a variable that holds one; reading the method without
|
||||
/// with its name in brackets, on a document (also one `add`, `addDocument` or `addDocumentNoUI`
|
||||
/// returns) or a variable that holds one; reading the method without
|
||||
/// calling it, and a `print` method of another object, do not.
|
||||
#[test]
|
||||
fn print_writes_a_file() {
|
||||
@@ -572,10 +573,16 @@ fn print_writes_a_file() {
|
||||
"logger.print('hello'); logger['print']('hello');\n",
|
||||
"app.activeDocument.name.concat(logger.print('x'));\n",
|
||||
"app.print(o); app.activeDocument.layers[0]['print'](o); app.documents['print'](o); app.preferences.activeDocument.print(o);\n",
|
||||
"var e = app.open(new File(p)); e.print(o); activeDocument.print(o);\n",
|
||||
"var e = app.open(new File(p)); e.print(o);\n",
|
||||
"activeDocument.print(o);\n",
|
||||
"documents.addDocument('Print').print(o);\n",
|
||||
"app.documents.addDocument('Print', s, false).print(o);\n",
|
||||
"documents.addDocumentNoUI('Print').print(o);\n",
|
||||
"app.documents.addDocumentNoUI('Print').print(o);\n",
|
||||
));
|
||||
assert_eq!(feature(&r, "file.write").map(|f| f.lines.as_slice()), Some(&[2, 3, 5, 9][..]));
|
||||
assert_eq!(r.outside.iter().map(|o| (o.id, o.lines.as_slice())).collect::<Vec<_>>(), [("filesWritten", &[2, 3, 5, 9][..])]);
|
||||
let lines = &[2, 3, 5, 9, 10, 11, 12, 13, 14][..];
|
||||
assert_eq!(feature(&r, "file.write").map(|f| f.lines.as_slice()), Some(lines));
|
||||
assert_eq!(r.outside.iter().map(|o| (o.id, o.lines.as_slice())).collect::<Vec<_>>(), [("filesWritten", lines)]);
|
||||
}
|
||||
|
||||
/// Setting a File object's length, hidden or read-only flag changes the file; reading them, comparing
|
||||
|
||||
+6
-4
@@ -2736,7 +2736,8 @@ app through the global object `vc`, and writes to the Script Console and runs ot
|
||||
pages do not list are left out. With `pDFPreset` named, a `PDFSaveOptions` option still at a new object's default
|
||||
keeps the preset's value. A bad value throws an error before anything is written.
|
||||
- `Document.print(options?)` runs `file.print` on the document, with the options a script assigned over the
|
||||
document's print settings, which stay as they are, and adds no undo step
|
||||
document's print settings, or over the preset's when `printPreset` is assigned. The document's print settings
|
||||
stay as they are, and `print` adds no undo step
|
||||
(https://ai-scripting.docsforadobe.dev/jsobjref/Document/, https://ai-scripting.docsforadobe.dev/jsobjref/PrintOptions/).
|
||||
`options` is a `new PrintOptions()`, whose `jobOptions`, `colorManagementOptions`, `colorSeparationOptions`,
|
||||
`coordinateOptions`, `flattenerOptions`, `fontOptions`, `pageMarksOptions`, `paperOptions` and `postScriptOptions`
|
||||
@@ -2763,10 +2764,11 @@ app through the global object `vc`, and writes to the Script Console and runs ot
|
||||
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 saved range, which prints when the
|
||||
saved settings print a range. When the saved settings, or the preset's, ignore the artboards, an assigned
|
||||
`printAllArtboards` not assigned, an assigned `artboardRange` replaces the range of the settings `print` starts
|
||||
from, which prints when those settings print a range. `print` starts from the preset's settings when `printPreset`
|
||||
is assigned, otherwise from the document's saved settings. When those settings ignore the artboards, an assigned
|
||||
`printArea` prints the artboards an assigned `artboardRange` names, or each artboard without a range. With one of
|
||||
`horizontalScale` and `verticalScale` assigned, the other keeps the document's saved value. `print` throws before anything is written when an assigned `artboardRange` names an
|
||||
`horizontalScale` and `verticalScale` assigned, the other keeps its value in the settings `print` starts from. `print` throws before anything is written when an assigned `artboardRange` names an
|
||||
artboard the document does not have, also with `printAllArtboards` true, when `printPreset` or `flattenerPreset`
|
||||
is not a preset's name (any case), when `colorManagementOptions.name` is not an RGB or CMYK profile's name (any
|
||||
case), when `paperOptions.name` is not a paper `file.print` knows, or when it names a paper other than `custom`
|
||||
|
||||
Reference in new issue
Block a user