1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Ghostscript package |
4
|
|
|
* |
5
|
|
|
* @author Daniel Schröder <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace GravityMedia\Ghostscript\Device\DistillerParameters; |
9
|
|
|
|
10
|
|
|
use GravityMedia\Ghostscript\Enum\PdfSettings; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* The advanced distiller parameters trait. |
14
|
|
|
* |
15
|
|
|
* @package GravityMedia\Ghostscript\Device\DistillerParameters |
16
|
|
|
* |
17
|
|
|
* @link http://ghostscript.com/doc/current/Ps2pdf.htm |
18
|
|
|
*/ |
19
|
|
|
trait AdvancedTrait |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Get argument value |
23
|
|
|
* |
24
|
|
|
* @param string $name |
25
|
|
|
* |
26
|
|
|
* @return null|string |
27
|
|
|
*/ |
28
|
|
|
abstract protected function getArgumentValue($name); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Set argument |
32
|
|
|
* |
33
|
|
|
* @param string $argument |
34
|
|
|
* |
35
|
|
|
* @return $this |
36
|
|
|
*/ |
37
|
|
|
abstract protected function setArgument($argument); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get PDF settings |
41
|
|
|
* |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
abstract public function getPdfSettings(); |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Whether ASCII85 encode pages |
48
|
|
|
* |
49
|
|
|
* @return bool |
50
|
|
|
*/ |
51
|
2 |
|
public function isAscii85EncodePages() |
52
|
|
|
{ |
53
|
2 |
|
$value = $this->getArgumentValue('-dASCII85EncodePages'); |
54
|
2 |
|
if (null === $value) { |
55
|
2 |
|
return false; |
56
|
|
|
} |
57
|
|
|
|
58
|
2 |
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Set ASCII85 encode pages flag |
63
|
|
|
* |
64
|
|
|
* @param bool $ascii85EncodePages |
65
|
|
|
* |
66
|
|
|
* @return $this |
67
|
|
|
*/ |
68
|
2 |
|
public function setAscii85EncodePages($ascii85EncodePages) |
69
|
|
|
{ |
70
|
2 |
|
$this->setArgument(sprintf('-dASCII85EncodePages=%s', $ascii85EncodePages ? 'true' : 'false')); |
71
|
|
|
|
72
|
2 |
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Whether to auto position EPS files |
77
|
|
|
* |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
2 |
|
public function isAutoPositionEpsFiles() |
81
|
|
|
{ |
82
|
2 |
|
$value = $this->getArgumentValue('-dAutoPositionEPSFiles'); |
83
|
2 |
|
if (null === $value) { |
84
|
2 |
|
return false; |
85
|
|
|
} |
86
|
|
|
|
87
|
2 |
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Set auto position EPS files flag |
92
|
|
|
* |
93
|
|
|
* @param bool $autoPositionEpsFiles |
94
|
|
|
* |
95
|
|
|
* @return $this |
96
|
|
|
*/ |
97
|
2 |
|
public function setAutoPositionEpsFiles($autoPositionEpsFiles) |
98
|
|
|
{ |
99
|
2 |
|
$this->setArgument(sprintf('-dAutoPositionEPSFiles=%s', $autoPositionEpsFiles ? 'true' : 'false')); |
100
|
|
|
|
101
|
2 |
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Whether to create job ticket |
106
|
|
|
* |
107
|
|
|
* @return bool |
108
|
|
|
*/ |
109
|
10 |
|
public function isCreateJobTicket() |
110
|
|
|
{ |
111
|
10 |
|
$value = $this->getArgumentValue('-dCreateJobTicket'); |
112
|
10 |
|
if (null === $value) { |
113
|
10 |
|
switch ($this->getPdfSettings()) { |
114
|
10 |
|
case PdfSettings::PRINTER: |
115
|
9 |
|
case PdfSettings::PREPRESS: |
116
|
4 |
|
return true; |
117
|
3 |
|
default: |
118
|
6 |
|
return false; |
119
|
3 |
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
10 |
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Set create job ticket flag |
127
|
|
|
* |
128
|
|
|
* @param bool $createJobTicket |
129
|
|
|
* |
130
|
|
|
* @return $this |
131
|
|
|
*/ |
132
|
10 |
|
public function setCreateJobTicket($createJobTicket) |
133
|
|
|
{ |
134
|
10 |
|
$this->setArgument(sprintf('-dCreateJobTicket=%s', $createJobTicket ? 'true' : 'false')); |
135
|
|
|
|
136
|
10 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Whether to detect blends |
141
|
|
|
* |
142
|
|
|
* @return bool |
143
|
|
|
*/ |
144
|
2 |
|
public function isDetectBlends() |
145
|
|
|
{ |
146
|
2 |
|
$value = $this->getArgumentValue('-dDetectBlends'); |
147
|
2 |
|
if (null === $value) { |
148
|
2 |
|
return true; |
149
|
|
|
} |
150
|
|
|
|
151
|
2 |
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Set detect blends flag |
156
|
|
|
* |
157
|
|
|
* @param bool $detectBlends |
158
|
|
|
* |
159
|
|
|
* @return $this |
160
|
|
|
*/ |
161
|
2 |
|
public function setDetectBlends($detectBlends) |
162
|
|
|
{ |
163
|
2 |
|
$this->setArgument(sprintf('-dDetectBlends=%s', $detectBlends ? 'true' : 'false')); |
164
|
|
|
|
165
|
2 |
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Whether to emit DSC warnings |
170
|
|
|
* |
171
|
|
|
* @return bool |
172
|
|
|
*/ |
173
|
2 |
|
public function isEmitDscWarnings() |
174
|
|
|
{ |
175
|
2 |
|
$value = $this->getArgumentValue('-dEmitDSCWarnings'); |
176
|
2 |
|
if (null === $value) { |
177
|
2 |
|
return false; |
178
|
|
|
} |
179
|
|
|
|
180
|
2 |
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Set emit DSC warnings flag |
185
|
|
|
* |
186
|
|
|
* @param bool $emitDscWarnings |
187
|
|
|
* |
188
|
|
|
* @return $this |
189
|
|
|
*/ |
190
|
2 |
|
public function setEmitDscWarnings($emitDscWarnings) |
191
|
|
|
{ |
192
|
2 |
|
$this->setArgument(sprintf('-dEmitDSCWarnings=%s', $emitDscWarnings ? 'true' : 'false')); |
193
|
|
|
|
194
|
2 |
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Whether to lock distiller params |
199
|
|
|
* |
200
|
|
|
* @return bool |
201
|
|
|
*/ |
202
|
2 |
|
public function isLockDistillerParams() |
203
|
|
|
{ |
204
|
2 |
|
$value = $this->getArgumentValue('-dLockDistillerParams'); |
205
|
2 |
|
if (null === $value) { |
206
|
2 |
|
return false; |
207
|
|
|
} |
208
|
|
|
|
209
|
2 |
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Set lock distiller params flag |
214
|
|
|
* |
215
|
|
|
* @param bool $lockDistillerParams |
216
|
|
|
* |
217
|
|
|
* @return $this |
218
|
|
|
*/ |
219
|
2 |
|
public function setLockDistillerParams($lockDistillerParams) |
220
|
|
|
{ |
221
|
2 |
|
$this->setArgument(sprintf('-dLockDistillerParams=%s', $lockDistillerParams ? 'true' : 'false')); |
222
|
|
|
|
223
|
2 |
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Get OPM |
228
|
|
|
* |
229
|
|
|
* @return int |
230
|
|
|
*/ |
231
|
2 |
|
public function getOpm() |
232
|
|
|
{ |
233
|
2 |
|
$value = $this->getArgumentValue('-dOPM'); |
234
|
2 |
|
if (null === $value) { |
235
|
2 |
|
return 1; |
236
|
|
|
} |
237
|
|
|
|
238
|
2 |
|
return intval($value); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Set OPM |
243
|
|
|
* |
244
|
|
|
* @param int $opm |
245
|
|
|
* |
246
|
|
|
* @return $this |
247
|
|
|
*/ |
248
|
2 |
|
public function setOpm($opm) |
249
|
|
|
{ |
250
|
2 |
|
$this->setArgument(sprintf('-dOPM=%s', $opm)); |
251
|
|
|
|
252
|
2 |
|
return $this; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Whether to parse DSC comments |
257
|
|
|
* |
258
|
|
|
* @return bool |
259
|
|
|
*/ |
260
|
2 |
|
public function isParseDscComments() |
261
|
|
|
{ |
262
|
2 |
|
$value = $this->getArgumentValue('-dParseDSCComments'); |
263
|
2 |
|
if (null === $value) { |
264
|
2 |
|
return true; |
265
|
|
|
} |
266
|
|
|
|
267
|
2 |
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Set parse DSC comments flag |
272
|
|
|
* |
273
|
|
|
* @param bool $parseDscComments |
274
|
|
|
* |
275
|
|
|
* @return $this |
276
|
|
|
*/ |
277
|
2 |
|
public function setParseDscComments($parseDscComments) |
278
|
|
|
{ |
279
|
2 |
|
$this->setArgument(sprintf('-dParseDSCComments=%s', $parseDscComments ? 'true' : 'false')); |
280
|
|
|
|
281
|
2 |
|
return $this; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Whether to parse DSC comments for doc info |
286
|
|
|
* |
287
|
|
|
* @return bool |
288
|
|
|
*/ |
289
|
2 |
|
public function isParseDscCommentsForDocInfo() |
290
|
|
|
{ |
291
|
2 |
|
$value = $this->getArgumentValue('-dParseDSCCommentsForDocInfo'); |
292
|
2 |
|
if (null === $value) { |
293
|
2 |
|
return true; |
294
|
|
|
} |
295
|
|
|
|
296
|
2 |
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Set parse DSC comments for doc info flag |
301
|
|
|
* |
302
|
|
|
* @param bool $parseDscCommentsForDocInfo |
303
|
|
|
* |
304
|
|
|
* @return $this |
305
|
|
|
*/ |
306
|
2 |
|
public function setParseDscCommentsForDocInfo($parseDscCommentsForDocInfo) |
307
|
|
|
{ |
308
|
2 |
|
$this->setArgument(sprintf('-dParseDSCCommentsForDocInfo=%s', $parseDscCommentsForDocInfo ? 'true' : 'false')); |
309
|
|
|
|
310
|
2 |
|
return $this; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* Whether to preserve copy page |
315
|
|
|
* |
316
|
|
|
* @return bool |
317
|
|
|
*/ |
318
|
2 |
|
public function isPreserveCopyPage() |
319
|
|
|
{ |
320
|
2 |
|
$value = $this->getArgumentValue('-dPreserveCopyPage'); |
321
|
2 |
|
if (null === $value) { |
322
|
2 |
|
return true; |
323
|
|
|
} |
324
|
|
|
|
325
|
2 |
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Set preserve copy page flag |
330
|
|
|
* |
331
|
|
|
* @param bool $preserveCopyPage |
332
|
|
|
* |
333
|
|
|
* @return $this |
334
|
|
|
*/ |
335
|
2 |
|
public function setPreserveCopyPage($preserveCopyPage) |
336
|
|
|
{ |
337
|
2 |
|
$this->setArgument(sprintf('-dPreserveCopyPage=%s', $preserveCopyPage ? 'true' : 'false')); |
338
|
|
|
|
339
|
2 |
|
return $this; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* Whether to preserve EPS info |
344
|
|
|
* |
345
|
|
|
* @return bool |
346
|
|
|
*/ |
347
|
2 |
|
public function isPreserveEpsInfo() |
348
|
|
|
{ |
349
|
2 |
|
$value = $this->getArgumentValue('-dPreserveEPSInfo'); |
350
|
2 |
|
if (null === $value) { |
351
|
2 |
|
return true; |
352
|
|
|
} |
353
|
|
|
|
354
|
2 |
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Set preserve EPS info flag |
359
|
|
|
* |
360
|
|
|
* @param bool $preserveEpsInfo |
361
|
|
|
* |
362
|
|
|
* @return $this |
363
|
|
|
*/ |
364
|
2 |
|
public function setPreserveEpsInfo($preserveEpsInfo) |
365
|
|
|
{ |
366
|
2 |
|
$this->setArgument(sprintf('-dPreserveEPSInfo=%s', $preserveEpsInfo ? 'true' : 'false')); |
367
|
|
|
|
368
|
2 |
|
return $this; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* Whether to preserve OPI comments |
373
|
|
|
* |
374
|
|
|
* @return bool |
375
|
|
|
*/ |
376
|
10 |
|
public function isPreserveOpiComments() |
377
|
|
|
{ |
378
|
10 |
|
$value = $this->getArgumentValue('-dPreserveOPIComments'); |
379
|
10 |
|
if (null === $value) { |
380
|
10 |
|
switch ($this->getPdfSettings()) { |
381
|
10 |
|
case PdfSettings::PRINTER: |
382
|
9 |
|
case PdfSettings::PREPRESS: |
383
|
4 |
|
return true; |
384
|
3 |
|
default: |
385
|
6 |
|
return false; |
386
|
3 |
|
} |
387
|
|
|
} |
388
|
|
|
|
389
|
10 |
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Set preserve OPI comments flag |
394
|
|
|
* |
395
|
|
|
* @param bool $preserveOpiComments |
396
|
|
|
* |
397
|
|
|
* @return $this |
398
|
|
|
*/ |
399
|
10 |
|
public function setPreserveOpiComments($preserveOpiComments) |
400
|
|
|
{ |
401
|
10 |
|
$this->setArgument(sprintf('-dPreserveOPIComments=%s', $preserveOpiComments ? 'true' : 'false')); |
402
|
|
|
|
403
|
10 |
|
return $this; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* Whether to use prologue |
408
|
|
|
* |
409
|
|
|
* @return bool |
410
|
|
|
*/ |
411
|
2 |
|
public function isUsePrologue() |
412
|
|
|
{ |
413
|
2 |
|
$value = $this->getArgumentValue('-dUsePrologue'); |
414
|
2 |
|
if (null === $value) { |
415
|
2 |
|
return false; |
416
|
|
|
} |
417
|
|
|
|
418
|
2 |
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Set use prologue flag |
423
|
|
|
* |
424
|
|
|
* @param bool $usePrologue |
425
|
|
|
* |
426
|
|
|
* @return $this |
427
|
|
|
*/ |
428
|
2 |
|
public function setUsePrologue($usePrologue) |
429
|
|
|
{ |
430
|
2 |
|
$this->setArgument(sprintf('-dUsePrologue=%s', $usePrologue ? 'true' : 'false')); |
431
|
|
|
|
432
|
2 |
|
return $this; |
433
|
|
|
} |
434
|
|
|
} |
435
|
|
|
|