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