|
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 other parameters trait. |
|
12
|
|
|
* |
|
13
|
|
|
* @package GravityMedia\Ghostscript\Device\CommandLineParameters |
|
14
|
|
|
* |
|
15
|
|
|
* @link http://ghostscript.com/doc/current/Use.htm#Other_parameters |
|
16
|
|
|
*/ |
|
17
|
|
|
trait OtherTrait |
|
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 FILTERIMAGE flag is set |
|
48
|
|
|
* |
|
49
|
|
|
* @return bool |
|
50
|
|
|
*/ |
|
51
|
2 |
|
public function isFilterImage() |
|
52
|
|
|
{ |
|
53
|
2 |
|
return $this->hasArgument('-dFILTERIMAGE'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Set FILTERIMAGE flag |
|
58
|
|
|
* |
|
59
|
|
|
* If set, ths will ignore all images in the input (in this context image means a bitmap), these will therefore not |
|
60
|
|
|
* be rendered. |
|
61
|
|
|
* |
|
62
|
|
|
* @return $this |
|
63
|
|
|
*/ |
|
64
|
2 |
|
public function setFilterImage() |
|
65
|
|
|
{ |
|
66
|
2 |
|
$this->setArgument('-dFILTERIMAGE'); |
|
67
|
|
|
|
|
68
|
2 |
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Whether FILTERTEXT flag is set |
|
73
|
|
|
* |
|
74
|
|
|
* @return bool |
|
75
|
|
|
*/ |
|
76
|
2 |
|
public function isFilterText() |
|
77
|
|
|
{ |
|
78
|
2 |
|
return $this->hasArgument('-dFILTERTEXT'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Set FILTERTEXT flag |
|
83
|
|
|
* |
|
84
|
|
|
* If set, ths will ignore all text in the input (just because it looks like text doesn't mean it is, it might be an |
|
85
|
|
|
* image), text will therefore not be rendered. |
|
86
|
|
|
* |
|
87
|
|
|
* @return $this |
|
88
|
|
|
*/ |
|
89
|
2 |
|
public function setFilterText() |
|
90
|
|
|
{ |
|
91
|
2 |
|
$this->setArgument('-dFILTERTEXT'); |
|
92
|
|
|
|
|
93
|
2 |
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Whether FILTERVECTOR flag is set |
|
98
|
|
|
* |
|
99
|
|
|
* @return bool |
|
100
|
|
|
*/ |
|
101
|
2 |
|
public function isFilterVector() |
|
102
|
|
|
{ |
|
103
|
2 |
|
return $this->hasArgument('-dFILTERVECTOR'); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Set FILTERVECTOR flag |
|
108
|
|
|
* |
|
109
|
|
|
* If set, ths will ignore anything whch is neither text nor an image. |
|
110
|
|
|
* |
|
111
|
|
|
* @return $this |
|
112
|
|
|
*/ |
|
113
|
2 |
|
public function setFilterVector() |
|
114
|
|
|
{ |
|
115
|
2 |
|
$this->setArgument('-dFILTERVECTOR'); |
|
116
|
|
|
|
|
117
|
2 |
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Whether DELAYBIND flag is set |
|
122
|
|
|
* |
|
123
|
|
|
* @return bool |
|
124
|
|
|
*/ |
|
125
|
2 |
|
public function isDelayBind() |
|
126
|
|
|
{ |
|
127
|
2 |
|
return $this->hasArgument('-dDELAYBIND'); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Set DELAYBIND flag |
|
132
|
|
|
* |
|
133
|
|
|
* Causes bind to remember all its invocations, but not actually execute them until the .bindnow procedure is |
|
134
|
|
|
* called. Useful only for certain specialized packages like pstotext that redefine operators. See the documentation |
|
135
|
|
|
* for .bindnow for more information on using this feature. |
|
136
|
|
|
* |
|
137
|
|
|
* @return $this |
|
138
|
|
|
*/ |
|
139
|
2 |
|
public function setDelayBind() |
|
140
|
|
|
{ |
|
141
|
2 |
|
$this->setArgument('-dDELAYBIND'); |
|
142
|
|
|
|
|
143
|
2 |
|
return $this; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Whether DOPDFMARKS flag is set |
|
148
|
|
|
* |
|
149
|
|
|
* @return bool |
|
150
|
|
|
*/ |
|
151
|
2 |
|
public function isDoPdfMarks() |
|
152
|
|
|
{ |
|
153
|
2 |
|
return $this->hasArgument('-dDOPDFMARKS'); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Set DOPDFMARKS flag |
|
158
|
|
|
* |
|
159
|
|
|
* Causes pdfmark to be called for bookmarks, annotations, links and cropbox when processing PDF files. Normally, |
|
160
|
|
|
* pdfmark is only called for these types for PostScript files or when the output device requests it (e.g. pdfwrite |
|
161
|
|
|
* device). |
|
162
|
|
|
* |
|
163
|
|
|
* @return $this |
|
164
|
|
|
*/ |
|
165
|
2 |
|
public function setDoPdfMarks() |
|
166
|
|
|
{ |
|
167
|
2 |
|
$this->setArgument('-dDOPDFMARKS'); |
|
168
|
|
|
|
|
169
|
2 |
|
return $this; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Whether JOBSERVER flag is set |
|
174
|
|
|
* |
|
175
|
|
|
* @return bool |
|
176
|
|
|
*/ |
|
177
|
2 |
|
public function isJobServer() |
|
178
|
|
|
{ |
|
179
|
2 |
|
return $this->hasArgument('-dJOBSERVER'); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Set JOBSERVER flag |
|
184
|
|
|
* |
|
185
|
|
|
* Define \004 (^D) to start a new encapsulated job used for compatibility with Adobe PS Interpreters that |
|
186
|
|
|
* ordinarily run under a job server. The -dNOOUTERSAVE switch is ignored if -dJOBSERVER is specified since job |
|
187
|
|
|
* servers always execute the input PostScript under a save level, although the exitserver operator can be used to |
|
188
|
|
|
* escape from the encapsulated job and execute as if the -dNOOUTERSAVE was specified. |
|
189
|
|
|
* |
|
190
|
|
|
* This also requires that the input be from stdin, otherwise an error will result |
|
191
|
|
|
* (Error: /invalidrestore in --restore--). |
|
192
|
|
|
* |
|
193
|
|
|
* Example usage is: |
|
194
|
|
|
* |
|
195
|
|
|
* gs ... -dJOBSERVER - < inputfile.ps |
|
196
|
|
|
* -or- |
|
197
|
|
|
* cat inputfile.ps | gs ... -dJOBSERVER - |
|
198
|
|
|
* |
|
199
|
|
|
* Note: The ^D does not result in an end-of-file action on stdin as it may on some PostScript printers that rely on |
|
200
|
|
|
* TBCP (Tagged Binary Communication Protocol) to cause an out-of-band ^D to signal EOF in a stream input data. This |
|
201
|
|
|
* means that direct file actions on stdin such as flushfile and closefile will affect processing of data beyond the |
|
202
|
|
|
* ^D in the stream. |
|
203
|
|
|
* |
|
204
|
|
|
* @return $this |
|
205
|
|
|
*/ |
|
206
|
2 |
|
public function setJobServer() |
|
207
|
|
|
{ |
|
208
|
2 |
|
$this->setArgument('-dJOBSERVER'); |
|
209
|
|
|
|
|
210
|
2 |
|
return $this; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Whether NOBIND flag is set |
|
215
|
|
|
* |
|
216
|
|
|
* @return bool |
|
217
|
|
|
*/ |
|
218
|
2 |
|
public function isNoBind() |
|
219
|
|
|
{ |
|
220
|
2 |
|
return $this->hasArgument('-dNOBIND'); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* Set NOBIND flag |
|
225
|
|
|
* |
|
226
|
|
|
* Disables the bind operator. Useful only for debugging. |
|
227
|
|
|
* |
|
228
|
|
|
* @return $this |
|
229
|
|
|
*/ |
|
230
|
2 |
|
public function setNoBind() |
|
231
|
|
|
{ |
|
232
|
2 |
|
$this->setArgument('-dNOBIND'); |
|
233
|
|
|
|
|
234
|
2 |
|
return $this; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* Whether NOCACHE flag is set |
|
239
|
|
|
* |
|
240
|
|
|
* @return bool |
|
241
|
|
|
*/ |
|
242
|
2 |
|
public function isNoCache() |
|
243
|
|
|
{ |
|
244
|
2 |
|
return $this->hasArgument('-dNOCACHE'); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* Set NOCACHE flag |
|
249
|
|
|
* |
|
250
|
|
|
* Disables character caching. Useful only for debugging. |
|
251
|
|
|
* |
|
252
|
|
|
* @return $this |
|
253
|
|
|
*/ |
|
254
|
2 |
|
public function setNoCache() |
|
255
|
|
|
{ |
|
256
|
2 |
|
$this->setArgument('-dNOCACHE'); |
|
257
|
|
|
|
|
258
|
2 |
|
return $this; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Whether NOGC flag is set |
|
263
|
|
|
* |
|
264
|
|
|
* @return bool |
|
265
|
|
|
*/ |
|
266
|
2 |
|
public function isNoGc() |
|
267
|
|
|
{ |
|
268
|
2 |
|
return $this->hasArgument('-dNOGC'); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* Set NOGC flag |
|
273
|
|
|
* |
|
274
|
|
|
* Suppresses the initial automatic enabling of the garbage collector in Level 2 systems. (The vmreclaim operator is |
|
275
|
|
|
* not disabled.) Useful only for debugging. |
|
276
|
|
|
* |
|
277
|
|
|
* @return $this |
|
278
|
|
|
*/ |
|
279
|
2 |
|
public function setNoGc() |
|
280
|
|
|
{ |
|
281
|
2 |
|
$this->setArgument('-dNOGC'); |
|
282
|
|
|
|
|
283
|
2 |
|
return $this; |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* Whether NOOUTERSAVE flag is set |
|
288
|
|
|
* |
|
289
|
|
|
* @return bool |
|
290
|
|
|
*/ |
|
291
|
2 |
|
public function isNoOuterSave() |
|
292
|
|
|
{ |
|
293
|
2 |
|
return $this->hasArgument('-dNOOUTERSAVE'); |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* Set NOOUTERSAVE flag |
|
298
|
|
|
* |
|
299
|
|
|
* Suppresses the initial save that is used for compatibility with Adobe PS Interpreters that ordinarily run under a |
|
300
|
|
|
* job server. If a job server is going to be used to set up the outermost save level, then -dNOOUTERSAVE should be |
|
301
|
|
|
* used so that the restore between jobs will restore global VM as expected. |
|
302
|
|
|
* |
|
303
|
|
|
* @return $this |
|
304
|
|
|
*/ |
|
305
|
2 |
|
public function setNoOuterSave() |
|
306
|
|
|
{ |
|
307
|
2 |
|
$this->setArgument('-dNOOUTERSAVE'); |
|
308
|
|
|
|
|
309
|
2 |
|
return $this; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* Whether NOSAFER flag is set |
|
314
|
|
|
* |
|
315
|
|
|
* @return bool |
|
316
|
|
|
*/ |
|
317
|
2 |
|
public function isNoSafer() |
|
318
|
|
|
{ |
|
319
|
2 |
|
return $this->hasArgument('-dNOSAFER'); |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* Set NOSAFER flag (equivalent to DELAYSAFER) |
|
324
|
|
|
* |
|
325
|
|
|
* This flag disables SAFER mode until the .setsafe procedure is run. This is intended for clients or scripts that |
|
326
|
|
|
* cannot operate in SAFER mode. If Ghostscript is started with -dNOSAFER or -dDELAYSAFER, PostScript programs are |
|
327
|
|
|
* allowed to read, write, rename or delete any files in the system that are not protected by operating system |
|
328
|
|
|
* permissions. |
|
329
|
|
|
* |
|
330
|
|
|
* This mode should be used with caution, and .setsafe should be run prior to running any PostScript file with |
|
331
|
|
|
* unknown contents. |
|
332
|
|
|
* |
|
333
|
|
|
* @return $this |
|
334
|
|
|
*/ |
|
335
|
2 |
|
public function setNoSafer() |
|
336
|
|
|
{ |
|
337
|
2 |
|
$this->setArgument('-dNOSAFER'); |
|
338
|
|
|
|
|
339
|
2 |
|
return $this; |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
/** |
|
343
|
|
|
* Whether SAFER flag is set |
|
344
|
|
|
* |
|
345
|
|
|
* @return bool |
|
346
|
|
|
*/ |
|
347
|
2 |
|
public function isSafer() |
|
348
|
|
|
{ |
|
349
|
2 |
|
return $this->hasArgument('-dSAFER'); |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
/** |
|
353
|
|
|
* Set SAFER flag |
|
354
|
|
|
* |
|
355
|
|
|
* Disables the deletefile and renamefile operators, and the ability to open piped commands (%pipe%cmd) at all. Only |
|
356
|
|
|
* %stdout and %stderr can be opened for writing. Disables reading of files other than %stdin, those given as a |
|
357
|
|
|
* command line argument, or those contained on one of the paths given by LIBPATH and FONTPATH and specified by the |
|
358
|
|
|
* system params /FontResourceDir and /GenericResourceDir. |
|
359
|
|
|
* |
|
360
|
|
|
* This mode also sets the .LockSafetyParams parameter of the default device, or the device specified with the |
|
361
|
|
|
* -sDEVICE= switch to protect against programs that attempt to write to files using the OutputFile device |
|
362
|
|
|
* parameter. Note that since the device parameters specified on the command line (including OutputFile) are set |
|
363
|
|
|
* prior to SAFER mode, the -sOutputFile=... on the command line is unrestricted. |
|
364
|
|
|
* |
|
365
|
|
|
* SAFER mode also prevents changing the /GenericResourceDir, /FontResourceDir and either the /SystemParamsPassword |
|
366
|
|
|
* or the /StartJobPassword. |
|
367
|
|
|
* |
|
368
|
|
|
* Note: While SAFER mode is not the default, in a subsequent release of Ghostscript, SAFER mode will be the default |
|
369
|
|
|
* thus scripts or programs that need to open files or set restricted parameters will require the -dNOSAFER command |
|
370
|
|
|
* line option. |
|
371
|
|
|
* |
|
372
|
|
|
* When running -dNOSAFER it is possible to perform a save, followed by .setsafe, execute a file or procedure in |
|
373
|
|
|
* SAFER mode, then use restore to return to NOSAFER mode. In order to prevent the save object from being restored |
|
374
|
|
|
* by the foreign file or procedure, the .runandhide operator should be used to hide the save object from the |
|
375
|
|
|
* restricted procedure. |
|
376
|
|
|
* |
|
377
|
|
|
* @return $this |
|
378
|
|
|
*/ |
|
379
|
2 |
|
public function setSafer() |
|
380
|
|
|
{ |
|
381
|
2 |
|
$this->setArgument('-dSAFER'); |
|
382
|
|
|
|
|
383
|
2 |
|
return $this; |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
/** |
|
387
|
|
|
* Whether PreBandThreshold flag is true |
|
388
|
|
|
* |
|
389
|
|
|
* @return bool |
|
390
|
|
|
*/ |
|
391
|
2 |
|
public function isPreBandThreshold() |
|
392
|
|
|
{ |
|
393
|
2 |
|
$value = $this->getArgumentValue('-dPreBandThreshold'); |
|
394
|
2 |
|
if (null === $value) { |
|
395
|
2 |
|
return false; |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
2 |
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
/** |
|
402
|
|
|
* Set PreBandThreshold flag |
|
403
|
|
|
* |
|
404
|
|
|
* If the target device is a halftone device, then images that are normally stored in the command list during banded |
|
405
|
|
|
* output will be halftoned during the command list writing phase, if the resulting image will result in a smaller |
|
406
|
|
|
* command list. The decision to halftone depends upon the output and source resolution as well as the output and |
|
407
|
|
|
* source color space. |
|
408
|
|
|
* |
|
409
|
|
|
* @param bool $preBandThreshold |
|
410
|
|
|
* |
|
411
|
|
|
* @return $this |
|
412
|
|
|
*/ |
|
413
|
2 |
|
public function setPreBandThreshold($preBandThreshold) |
|
414
|
|
|
{ |
|
415
|
2 |
|
$this->setArgument(sprintf('-dPreBandThreshold=%s', $preBandThreshold ? 'true' : 'false')); |
|
416
|
|
|
|
|
417
|
2 |
|
return $this; |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
/** |
|
421
|
|
|
* Whether STRICT flag is set |
|
422
|
|
|
* |
|
423
|
|
|
* @return bool |
|
424
|
|
|
*/ |
|
425
|
2 |
|
public function isStrict() |
|
426
|
|
|
{ |
|
427
|
2 |
|
return $this->hasArgument('-dSTRICT'); |
|
428
|
|
|
} |
|
429
|
|
|
|
|
430
|
|
|
/** |
|
431
|
|
|
* Set STRICT flag |
|
432
|
|
|
* |
|
433
|
|
|
* Disables as many Ghostscript extensions as feasible, to be more helpful in debugging applications that produce |
|
434
|
|
|
* output for Adobe and other RIPs. |
|
435
|
|
|
* |
|
436
|
|
|
* @return $this |
|
437
|
|
|
*/ |
|
438
|
2 |
|
public function setStrict() |
|
439
|
|
|
{ |
|
440
|
2 |
|
$this->setArgument('-dSTRICT'); |
|
441
|
|
|
|
|
442
|
2 |
|
return $this; |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
/** |
|
446
|
|
|
* Whether WRITESYSTEMDICT flag is set |
|
447
|
|
|
* |
|
448
|
|
|
* @return bool |
|
449
|
|
|
*/ |
|
450
|
2 |
|
public function isWriteSystemDict() |
|
451
|
|
|
{ |
|
452
|
2 |
|
return $this->hasArgument('-dWRITESYSTEMDICT'); |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
/** |
|
456
|
|
|
* Set WRITESYSTEMDICT flag |
|
457
|
|
|
* |
|
458
|
|
|
* Leaves systemdict writable. This is necessary when running special utility programs such as font2c and pcharstr, |
|
459
|
|
|
* which must bypass normal PostScript access protection. |
|
460
|
|
|
* |
|
461
|
|
|
* @return $this |
|
462
|
|
|
*/ |
|
463
|
2 |
|
public function setWriteSystemDict() |
|
464
|
|
|
{ |
|
465
|
2 |
|
$this->setArgument('-dWRITESYSTEMDICT'); |
|
466
|
|
|
|
|
467
|
2 |
|
return $this; |
|
468
|
|
|
} |
|
469
|
|
|
} |
|
470
|
|
|
|