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\Devices; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The distiller parameters trait |
12
|
|
|
* |
13
|
|
|
* @package GravityMedia\Ghostscript\Devices |
14
|
|
|
*/ |
15
|
|
|
trait DistillerParametersTrait |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Get argument value |
19
|
|
|
* |
20
|
|
|
* @param string $name |
21
|
|
|
* |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
|
|
abstract function getArgumentValue($name); |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Set argument |
28
|
|
|
* |
29
|
|
|
* @param string $argument |
30
|
|
|
* |
31
|
|
|
* @return $this |
32
|
|
|
*/ |
33
|
|
|
abstract function setArgument($argument); |
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get always embed |
37
|
|
|
* |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
public function getAlwaysEmbed() |
41
|
|
|
{ |
42
|
|
|
$value = $this->getArgumentValue('-dAlwaysEmbed'); |
43
|
|
|
if (null === $value) { |
44
|
|
|
return []; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return explode(' /', substr($value, 2, -1)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Set always embed |
52
|
|
|
* |
53
|
|
|
* @param array $alwaysEmbed |
54
|
|
|
* |
55
|
|
|
* @return $this |
56
|
|
|
*/ |
57
|
|
|
public function setAlwaysEmbed(array $alwaysEmbed) |
58
|
|
|
{ |
59
|
|
|
$this->setArgument('-dAlwaysEmbed=[' . implode(' ', array_map(function ($fontName) { |
60
|
|
|
return '/' . ltrim($fontName, '/'); |
61
|
|
|
}, $alwaysEmbed)) . ']'); |
62
|
|
|
|
63
|
|
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Whether to anti alias color images |
68
|
|
|
* |
69
|
|
|
* @return bool |
70
|
|
|
*/ |
71
|
|
|
public function isAntiAliasColorImages() |
72
|
|
|
{ |
73
|
|
|
return filter_var($this->getArgumentValue('-dAntiAliasColorImages'), FILTER_VALIDATE_BOOLEAN); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Set anti alias color images flag |
78
|
|
|
* |
79
|
|
|
* @param bool $antiAliasColorImages |
80
|
|
|
* |
81
|
|
|
* @return $this |
82
|
|
|
*/ |
83
|
|
|
public function setAntiAliasColorImages($antiAliasColorImages) |
84
|
|
|
{ |
85
|
|
|
$this->setArgument('-dAntiAliasColorImages=' . ($antiAliasColorImages ? 'true' : 'false')); |
86
|
|
|
|
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Whether to anti alias gray images |
92
|
|
|
* |
93
|
|
|
* @return bool |
94
|
|
|
*/ |
95
|
|
|
public function isAntiAliasGrayImages() |
96
|
|
|
{ |
97
|
|
|
return filter_var($this->getArgumentValue('-dAntiAliasGrayImages'), FILTER_VALIDATE_BOOLEAN); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Set anti alias gray images flag |
102
|
|
|
* |
103
|
|
|
* @param bool $antiAliasGrayImages |
104
|
|
|
* |
105
|
|
|
* @return $this |
106
|
|
|
*/ |
107
|
|
|
public function setAntiAliasGrayImages($antiAliasGrayImages) |
108
|
|
|
{ |
109
|
|
|
$this->setArgument('-dAntiAliasGrayImages=' . ($antiAliasGrayImages ? 'true' : 'false')); |
110
|
|
|
|
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Whether to anti alias mono images |
116
|
|
|
* |
117
|
|
|
* @return bool |
118
|
|
|
*/ |
119
|
|
|
public function isAntiAliasMonoImages() |
120
|
|
|
{ |
121
|
|
|
return filter_var($this->getArgumentValue('-dAntiAliasMonoImages'), FILTER_VALIDATE_BOOLEAN); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Set anti alias mono images flag |
126
|
|
|
* |
127
|
|
|
* @param bool $antiAliasMonoImages |
128
|
|
|
* |
129
|
|
|
* @return $this |
130
|
|
|
*/ |
131
|
|
|
public function setAntiAliasMonoImages($antiAliasMonoImages) |
132
|
|
|
{ |
133
|
|
|
$this->setArgument('-dAntiAliasMonoImages=' . ($antiAliasMonoImages ? 'true' : 'false')); |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Whether ASCII85 encode pages |
140
|
|
|
* |
141
|
|
|
* @return bool |
142
|
|
|
*/ |
143
|
|
|
public function isAscii85EncodePages() |
144
|
|
|
{ |
145
|
|
|
return filter_var($this->getArgumentValue('-dASCII85EncodePages'), FILTER_VALIDATE_BOOLEAN); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Set ASCII85 encode pages flag |
150
|
|
|
* |
151
|
|
|
* @param bool $ascii85EncodePages |
152
|
|
|
* |
153
|
|
|
* @return $this |
154
|
|
|
*/ |
155
|
|
|
public function setAscii85EncodePages($ascii85EncodePages) |
156
|
|
|
{ |
157
|
|
|
$this->setArgument('-dASCII85EncodePages=' . ($ascii85EncodePages ? 'true' : 'false')); |
158
|
|
|
|
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Whether to auto filter color images |
164
|
|
|
* |
165
|
|
|
* @return bool |
166
|
|
|
*/ |
167
|
|
|
public function isAutoFilterColorImages() |
168
|
|
|
{ |
169
|
|
|
return filter_var($this->getArgumentValue('-dAutoFilterColorImages'), FILTER_VALIDATE_BOOLEAN); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Set auto filter color images flag |
174
|
|
|
* |
175
|
|
|
* @param bool $autoFilterColorImages |
176
|
|
|
* |
177
|
|
|
* @return $this |
178
|
|
|
*/ |
179
|
|
|
public function setAutoFilterColorImages($autoFilterColorImages) |
180
|
|
|
{ |
181
|
|
|
$this->setArgument('-dAutoFilterColorImages=' . ($autoFilterColorImages ? 'true' : 'false')); |
182
|
|
|
|
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Whether to auto filter gray images |
188
|
|
|
* |
189
|
|
|
* @return bool |
190
|
|
|
*/ |
191
|
|
|
public function isAutoFilterGrayImages() |
192
|
|
|
{ |
193
|
|
|
return filter_var($this->getArgumentValue('-dAutoFilterGrayImages'), FILTER_VALIDATE_BOOLEAN); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Set auto filter gray images flag |
198
|
|
|
* |
199
|
|
|
* @param bool $autoFilterGrayImages |
200
|
|
|
* |
201
|
|
|
* @return $this |
202
|
|
|
*/ |
203
|
|
|
public function setAutoFilterGrayImages($autoFilterGrayImages) |
204
|
|
|
{ |
205
|
|
|
$this->setArgument('-dAutoFilterGrayImages=' . ($autoFilterGrayImages ? 'true' : 'false')); |
206
|
|
|
|
207
|
|
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Whether to auto position EPS files |
212
|
|
|
* |
213
|
|
|
* @return bool |
214
|
|
|
*/ |
215
|
|
|
public function isAutoPositionEpsFiles() |
216
|
|
|
{ |
217
|
|
|
return filter_var($this->getArgumentValue('-dAutoPositionEPSFiles'), FILTER_VALIDATE_BOOLEAN); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Set auto position EPS files flag |
222
|
|
|
* |
223
|
|
|
* @param bool $autoPositionEpsFiles |
224
|
|
|
* |
225
|
|
|
* @return $this |
226
|
|
|
*/ |
227
|
|
|
public function setAutoPositionEpsFiles($autoPositionEpsFiles) |
228
|
|
|
{ |
229
|
|
|
$this->setArgument('-dAutoPositionEPSFiles=' . ($autoPositionEpsFiles ? 'true' : 'false')); |
230
|
|
|
|
231
|
|
|
return $this; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* Get auto rotate pages |
236
|
|
|
* |
237
|
|
|
* @return string |
238
|
|
|
*/ |
239
|
|
|
public function getAutoRotatePages() |
240
|
|
|
{ |
241
|
|
|
$value = $this->getArgumentValue('-dAutoRotatePages'); |
242
|
|
|
if (null === $value) { |
243
|
|
|
return null; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
return substr($value, 1); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Set auto rotate pages |
252
|
|
|
* |
253
|
|
|
* @param string $autoRotatePages |
254
|
|
|
* |
255
|
|
|
* @param \InvalidArgumentException |
256
|
|
|
* |
257
|
|
|
* @return $this |
258
|
|
|
*/ |
259
|
|
View Code Duplication |
public function setAutoRotatePages($autoRotatePages) |
|
|
|
|
260
|
|
|
{ |
261
|
|
|
if (!in_array($autoRotatePages, array( |
262
|
|
|
DistillerParametersInterface::AUTO_ROTATE_PAGES_NONE, |
263
|
|
|
DistillerParametersInterface::AUTO_ROTATE_PAGES_ALL, |
264
|
|
|
DistillerParametersInterface::AUTO_ROTATE_PAGES_PAGE_BY_PAGE |
265
|
|
|
)) |
266
|
|
|
) { |
267
|
|
|
throw new \InvalidArgumentException('Invalid auto rotate pages argument'); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
$this->setArgument('-dAutoRotatePages=/' . $autoRotatePages); |
271
|
|
|
|
272
|
|
|
return $this; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Get binding |
277
|
|
|
* |
278
|
|
|
* @return string |
279
|
|
|
*/ |
280
|
|
|
public function getBinding() |
281
|
|
|
{ |
282
|
|
|
$value = $this->getArgumentValue('-dBinding'); |
283
|
|
|
if (null === $value) { |
284
|
|
|
return null; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
return substr($value, 1); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* Set binding |
293
|
|
|
* |
294
|
|
|
* @param string $binding |
295
|
|
|
* |
296
|
|
|
* @param \InvalidArgumentException |
297
|
|
|
* |
298
|
|
|
* @return $this |
299
|
|
|
*/ |
300
|
|
View Code Duplication |
public function setBinding($binding) |
|
|
|
|
301
|
|
|
{ |
302
|
|
|
if (!in_array($binding, array( |
303
|
|
|
DistillerParametersInterface::BINDING_LEFT, |
304
|
|
|
DistillerParametersInterface::BINDING_RIGHT |
305
|
|
|
)) |
306
|
|
|
) { |
307
|
|
|
throw new \InvalidArgumentException('Invalid binding argument'); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
$this->setArgument('-dBinding=/' . $binding); |
311
|
|
|
|
312
|
|
|
return $this; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Get cal CMYK profile |
317
|
|
|
* |
318
|
|
|
* @return null|string |
319
|
|
|
*/ |
320
|
|
|
public function getCalCmykProfile() |
321
|
|
|
{ |
322
|
|
|
$value = $this->getArgumentValue('-dCalCMYKProfile'); |
323
|
|
|
if (null === $value) { |
324
|
|
|
return null; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
return substr($value, 1, -1); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Set cal CMYK profile |
332
|
|
|
* |
333
|
|
|
* @param string $valCmykProfile |
334
|
|
|
* |
335
|
|
|
* @return $this |
336
|
|
|
*/ |
337
|
|
|
public function setCalCmykProfile($valCmykProfile) |
338
|
|
|
{ |
339
|
|
|
$this->setArgument('-dCalCMYKProfile=(' . $valCmykProfile . ')'); |
340
|
|
|
|
341
|
|
|
return $this; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Get cal gray profile |
346
|
|
|
* |
347
|
|
|
* @return null|string |
348
|
|
|
*/ |
349
|
|
|
public function getCalGrayProfile() |
350
|
|
|
{ |
351
|
|
|
$value = $this->getArgumentValue('-dCalGrayProfile'); |
352
|
|
|
if (null === $value) { |
353
|
|
|
return null; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
return substr($value, 1, -1); |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* Set cal gray profile |
361
|
|
|
* |
362
|
|
|
* @param string $valGrayProfile |
363
|
|
|
* |
364
|
|
|
* @return $this |
365
|
|
|
*/ |
366
|
|
|
public function setCalGrayProfile($valGrayProfile) |
367
|
|
|
{ |
368
|
|
|
$this->setArgument('-dCalGrayProfile=(' . $valGrayProfile . ')'); |
369
|
|
|
|
370
|
|
|
return $this; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* Get cal RGB profile |
375
|
|
|
* |
376
|
|
|
* @return null|string |
377
|
|
|
*/ |
378
|
|
|
public function getCalRgbProfile() |
379
|
|
|
{ |
380
|
|
|
$value = $this->getArgumentValue('-dCalRGBProfile'); |
381
|
|
|
if (null === $value) { |
382
|
|
|
return null; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
return substr($value, 1, -1); |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Set cal RGB profile |
390
|
|
|
* |
391
|
|
|
* @param string $valRgbProfile |
392
|
|
|
* |
393
|
|
|
* @return $this |
394
|
|
|
*/ |
395
|
|
|
public function setCalRgbProfile($valRgbProfile) |
396
|
|
|
{ |
397
|
|
|
$this->setArgument('-dCalRGBProfile=(' . $valRgbProfile . ')'); |
398
|
|
|
|
399
|
|
|
return $this; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* Get cannot embed font policy |
404
|
|
|
* |
405
|
|
|
* @return string |
406
|
|
|
*/ |
407
|
|
|
public function getCannotEmbedFontPolicy() |
408
|
|
|
{ |
409
|
|
|
$value = $this->getArgumentValue('-dCannotEmbedFontPolicy'); |
410
|
|
|
if (null === $value) { |
411
|
|
|
return null; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
return substr($value, 1); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Set cannot embed font policy |
419
|
|
|
* |
420
|
|
|
* @param string $cannotEmbedFontPolicy |
421
|
|
|
* |
422
|
|
|
* @param \InvalidArgumentException |
423
|
|
|
* |
424
|
|
|
* @return $this |
425
|
|
|
*/ |
426
|
|
View Code Duplication |
public function setCannotEmbedFontPolicy($cannotEmbedFontPolicy) |
|
|
|
|
427
|
|
|
{ |
428
|
|
|
if (!in_array($cannotEmbedFontPolicy, array( |
429
|
|
|
DistillerParametersInterface::CANNOT_EMBED_FONT_POLICY_OK, |
430
|
|
|
DistillerParametersInterface::CANNOT_EMBED_FONT_POLICY_WARNING, |
431
|
|
|
DistillerParametersInterface::CANNOT_EMBED_FONT_POLICY_ERROR |
432
|
|
|
)) |
433
|
|
|
) { |
434
|
|
|
throw new \InvalidArgumentException('Invalid cannot embed font policy argument'); |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
$this->setArgument('-dCannotEmbedFontPolicy=/' . $cannotEmbedFontPolicy); |
438
|
|
|
|
439
|
|
|
return $this; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* Get compatibility level |
444
|
|
|
* |
445
|
|
|
* @return null|string |
446
|
|
|
*/ |
447
|
|
|
public function getCompatibilityLevel() |
448
|
|
|
{ |
449
|
|
|
return $this->getArgumentValue('-dCompatibilityLevel'); |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* Set compatibility level |
454
|
|
|
* |
455
|
|
|
* @param string $compatibilityLevel |
456
|
|
|
* |
457
|
|
|
* @return $this |
458
|
|
|
*/ |
459
|
|
|
public function setCompatibilityLevel($compatibilityLevel) |
460
|
|
|
{ |
461
|
|
|
$this->setArgument('-dCompatibilityLevel=' . $compatibilityLevel); |
462
|
|
|
|
463
|
|
|
return $this; |
464
|
|
|
} |
465
|
|
|
} |
466
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.