1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Ghostscript package |
4
|
|
|
* |
5
|
|
|
* @author Simon Schrape <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace GravityMedia\Ghostscript\Device\CommandLineParameters; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The interaction-related parameters trait |
12
|
|
|
* |
13
|
|
|
* @package GravityMedia\Ghostscript\Device\CommandLineParameters |
14
|
|
|
* @link http://ghostscript.com/doc/current/Use.htm#Interaction_related_parameters |
15
|
|
|
*/ |
16
|
|
|
trait InteractionTrait |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Whether argument is set |
20
|
|
|
* |
21
|
|
|
* @param string $name |
22
|
|
|
* |
23
|
|
|
* @return bool |
24
|
|
|
*/ |
25
|
|
|
abstract protected function hasArgument($name); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Get argument value |
29
|
|
|
* |
30
|
|
|
* @param string $name |
31
|
|
|
* |
32
|
|
|
* @return null|string |
33
|
|
|
*/ |
34
|
|
|
abstract protected function getArgumentValue($name); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Set argument |
38
|
|
|
* |
39
|
|
|
* @param string $argument |
40
|
|
|
* |
41
|
|
|
* @return $this |
42
|
|
|
*/ |
43
|
|
|
abstract protected function setArgument($argument); |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Whether BATCH flag is set |
47
|
|
|
* |
48
|
|
|
* @return bool |
49
|
|
|
*/ |
50
|
|
|
public function isBatch() |
51
|
|
|
{ |
52
|
|
|
return $this->hasArgument('-dBATCH'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Set BATCH flag |
57
|
|
|
* |
58
|
|
|
* Causes Ghostscript to exit after processing all files named on the command line, rather than going into an |
59
|
|
|
* interactive loop reading PostScript commands. Equivalent to putting -c quit at the end of the command line. |
60
|
|
|
* |
61
|
|
|
* @return $this |
62
|
|
|
*/ |
63
|
|
|
public function setBatch() |
64
|
|
|
{ |
65
|
|
|
$this->setArgument('-dBATCH'); |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Whether NOPAGEPROMPT flag is set |
72
|
|
|
* |
73
|
|
|
* @return bool |
74
|
|
|
*/ |
75
|
|
|
public function isNoPagePrompt() |
76
|
|
|
{ |
77
|
|
|
return $this->hasArgument('-dNOPAGEPROMPT'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Set NOPAGEPROMPT flag |
82
|
|
|
* |
83
|
|
|
* Disables only the prompt, but not the pause, at the end of each page. This may be useful on PC displays that get |
84
|
|
|
* confused if a program attempts to write text to the console while the display is in a graphics mode. |
85
|
|
|
* |
86
|
|
|
* @return $this |
87
|
|
|
*/ |
88
|
|
|
public function setNoPagePrompt() |
89
|
|
|
{ |
90
|
|
|
$this->setArgument('-dNOPAGEPROMPT'); |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Whether NOPAUSE flag is set |
97
|
|
|
* |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
|
|
public function isNoPause() |
101
|
|
|
{ |
102
|
|
|
return $this->hasArgument('-dNOPAUSE'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Set NOPAUSE flag |
107
|
|
|
* |
108
|
|
|
* Disables the prompt and pause at the end of each page. Normally one should use this (along with -dBATCH) when |
109
|
|
|
* producing output on a printer or to a file; it also may be desirable for applications where another program is |
110
|
|
|
* "driving" Ghostscript. |
111
|
|
|
* |
112
|
|
|
* @return $this |
113
|
|
|
*/ |
114
|
|
|
public function setNoPause() |
115
|
|
|
{ |
116
|
|
|
$this->setArgument('-dNOPAUSE'); |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Whether NOPROMPT flag is set |
123
|
|
|
* |
124
|
|
|
* @return bool |
125
|
|
|
*/ |
126
|
|
|
public function isNoPrompt() |
127
|
|
|
{ |
128
|
|
|
return $this->hasArgument('-dNOPROMPT'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Set NOPROMPT flag |
133
|
|
|
* |
134
|
|
|
* Disables the prompt printed by Ghostscript when it expects interactive input, as well as the end-of-page prompt |
135
|
|
|
* (-dNOPAGEPROMPT). This allows piping input directly into Ghostscript, as long as the data doesn't refer to |
136
|
|
|
* currentfile. |
137
|
|
|
* |
138
|
|
|
* @return $this |
139
|
|
|
*/ |
140
|
|
|
public function setNoPrompt() |
141
|
|
|
{ |
142
|
|
|
$this->setArgument('-dNOPROMPT'); |
143
|
|
|
|
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Whether QUIET flag is set |
149
|
|
|
* |
150
|
|
|
* @return bool |
151
|
|
|
*/ |
152
|
|
|
public function isQuiet() |
153
|
|
|
{ |
154
|
|
|
return $this->hasArgument('-dQUIET'); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Set QUIET flag |
159
|
|
|
* |
160
|
|
|
* Suppresses routine information comments on standard output. This is currently necessary when redirecting device |
161
|
|
|
* output to standard output. |
162
|
|
|
* |
163
|
|
|
* @return $this |
164
|
|
|
*/ |
165
|
|
|
public function setQuiet() |
166
|
|
|
{ |
167
|
|
|
$this->setArgument('-dQUIET'); |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Whether SHORTERRORS flag is set |
174
|
|
|
* |
175
|
|
|
* @return bool |
176
|
|
|
*/ |
177
|
|
|
public function isShortErrors() |
178
|
|
|
{ |
179
|
|
|
return $this->hasArgument('-dSHORTERRORS'); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Set SHORTERRORS flag |
184
|
|
|
* |
185
|
|
|
* Makes certain error and information messages more Adobe-compatible. |
186
|
|
|
* |
187
|
|
|
* @return $this |
188
|
|
|
*/ |
189
|
|
|
public function setShortErrors() |
190
|
|
|
{ |
191
|
|
|
$this->setArgument('-dSHORTERRORS'); |
192
|
|
|
|
193
|
|
|
return $this; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Get value of stdout parameter if set |
198
|
|
|
* |
199
|
|
|
* @return string|null |
200
|
|
|
*/ |
201
|
|
|
public function getStdout() |
202
|
|
|
{ |
203
|
|
|
return $this->getArgumentValue('-sstdout'); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Set stdout parameter |
208
|
|
|
* |
209
|
|
|
* Redirect PostScript %stdout to a file or stderr, to avoid it being mixed with device stdout. To redirect stdout |
210
|
|
|
* to stderr use -sstdout=%stderr. To cancel redirection of stdout use -sstdout=%stdout or -sstdout=-. |
211
|
|
|
* |
212
|
|
|
* Note that this redirects PostScript output to %stdout but does not change the destination FILE of device output |
213
|
|
|
* as with -sOutputFile=- or even -sOutputFile=%stdout since devices write directly using the stdout FILE * pointer |
214
|
|
|
* with C function calls such as fwrite or fputs. |
215
|
|
|
* |
216
|
|
|
* @param string $filename file to redirect PostScript %stdout to |
217
|
|
|
* @return $this |
218
|
|
|
*/ |
219
|
|
|
public function setStdout($filename) |
220
|
|
|
{ |
221
|
|
|
$this->setArgument(sprintf('-sstdout=%s', $filename)); |
222
|
|
|
|
223
|
|
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Whether TTYPAUSE flag is set |
228
|
|
|
* |
229
|
|
|
* @return bool |
230
|
|
|
*/ |
231
|
|
|
public function isTtyPause() |
232
|
|
|
{ |
233
|
|
|
return $this->hasArgument('-dTTYPAUSE'); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Set TTYPAUSE flag |
238
|
|
|
* |
239
|
|
|
* Causes Ghostscript to read a character from /dev/tty, rather than standard input, at the end of each page. This |
240
|
|
|
* may be useful if input is coming from a pipe. Note that -dTTYPAUSE overrides -dNOPAUSE. Also note that -dTTYPAUSE |
241
|
|
|
* requires opening the terminal device directly, and may cause problems in combination with -dSAFER. Permission |
242
|
|
|
* errors can be avoided by adding the device to the permitted reading list before invoking safer mode. For example: |
243
|
|
|
* gs -dTTYPAUSE -dDELAYSAFER -c '<< /PermitFileReading [ (/dev/tty)] >> setuserparams .locksafe' -dSAFER |
244
|
|
|
* |
245
|
|
|
* @return $this |
246
|
|
|
*/ |
247
|
|
|
public function setTtyPause() |
248
|
|
|
{ |
249
|
|
|
$this->setArgument('-dTTYPAUSE'); |
250
|
|
|
|
251
|
|
|
return $this; |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
|