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