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\DistillerParameters; |
9
|
|
|
|
10
|
|
|
use GravityMedia\Ghostscript\Devices\DistillerParametersInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* The color conversion distiller parameters trait |
14
|
|
|
* |
15
|
|
|
* @package GravityMedia\Ghostscript\Devices\DistillerParameters |
16
|
|
|
*/ |
17
|
|
|
trait ColorConversionTrait |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Available color conversion strategy values |
21
|
|
|
* |
22
|
|
|
* @var string[] |
23
|
|
|
*/ |
24
|
|
|
protected static $colorConversionStrategyValues = [ |
25
|
|
|
DistillerParametersInterface::COLOR_CONVERSION_STRATEGY_LEAVE_COLOR_UNCHANGED, |
26
|
|
|
DistillerParametersInterface::COLOR_CONVERSION_STRATEGY_USE_DEVICE_INDEPENDENT_COLOR, |
27
|
|
|
DistillerParametersInterface::COLOR_CONVERSION_STRATEGY_GRAY, |
28
|
|
|
DistillerParametersInterface::COLOR_CONVERSION_STRATEGY_RGB, |
29
|
|
|
DistillerParametersInterface::COLOR_CONVERSION_STRATEGY_CMYK |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Available default rendering intent values |
34
|
|
|
* |
35
|
|
|
* @var string[] |
36
|
|
|
*/ |
37
|
|
|
protected static $defaultRenderingIntentValues = [ |
38
|
|
|
DistillerParametersInterface::DEFAULT_RENDERING_INTENT_DEFAULT, |
39
|
|
|
DistillerParametersInterface::DEFAULT_RENDERING_INTENT_PERCEPTUAL, |
40
|
|
|
DistillerParametersInterface::DEFAULT_RENDERING_INTENT_SATURATION, |
41
|
|
|
DistillerParametersInterface::DEFAULT_RENDERING_INTENT_RELATIVE_COLORIMETRIC, |
42
|
|
|
DistillerParametersInterface::DEFAULT_RENDERING_INTENT_ABSOLUTE_COLORIMETRIC |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Available transfer function info values |
47
|
|
|
* |
48
|
|
|
* @var string[] |
49
|
|
|
*/ |
50
|
|
|
protected static $transferFunctionInfoValues = [ |
51
|
|
|
DistillerParametersInterface::TRANSFER_FUNCTION_INFO_PRESERVE, |
52
|
|
|
DistillerParametersInterface::TRANSFER_FUNCTION_INFO_REMOVE, |
53
|
|
|
DistillerParametersInterface::TRANSFER_FUNCTION_INFO_APPLY |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Available UCR and BG info values |
58
|
|
|
* |
59
|
|
|
* @var string[] |
60
|
|
|
*/ |
61
|
|
|
protected static $ucrAndBgInfoValues = [ |
62
|
|
|
DistillerParametersInterface::UCR_AND_BG_INFO_PRESERVE, |
63
|
|
|
DistillerParametersInterface::UCR_AND_BG_INFO_REMOVE |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get argument value |
68
|
|
|
* |
69
|
|
|
* @param string $name |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
abstract protected function getArgumentValue($name); |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Set argument |
77
|
|
|
* |
78
|
|
|
* @param string $argument |
79
|
|
|
* |
80
|
|
|
* @return $this |
81
|
|
|
*/ |
82
|
|
|
abstract protected function setArgument($argument); |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get cal CMYK profile |
86
|
|
|
* |
87
|
|
|
* @return null|string |
88
|
|
|
*/ |
89
|
|
|
public function getCalCmykProfile() |
90
|
|
|
{ |
91
|
|
|
$value = $this->getArgumentValue('-dCalCMYKProfile'); |
92
|
|
|
if (null === $value) { |
93
|
|
|
return null; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return substr($value, 1, -1); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Set cal CMYK profile |
101
|
|
|
* |
102
|
|
|
* @param string $valCmykProfile |
103
|
|
|
* |
104
|
|
|
* @return $this |
105
|
|
|
*/ |
106
|
|
|
public function setCalCmykProfile($valCmykProfile) |
107
|
|
|
{ |
108
|
|
|
$this->setArgument(sprintf('-dCalCMYKProfile=(%s)', $valCmykProfile)); |
109
|
|
|
|
110
|
|
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Get cal gray profile |
115
|
|
|
* |
116
|
|
|
* @return null|string |
117
|
|
|
*/ |
118
|
|
|
public function getCalGrayProfile() |
119
|
|
|
{ |
120
|
|
|
$value = $this->getArgumentValue('-dCalGrayProfile'); |
121
|
|
|
if (null === $value) { |
122
|
|
|
return null; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return substr($value, 1, -1); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Set cal gray profile |
130
|
|
|
* |
131
|
|
|
* @param string $valGrayProfile |
132
|
|
|
* |
133
|
|
|
* @return $this |
134
|
|
|
*/ |
135
|
|
|
public function setCalGrayProfile($valGrayProfile) |
136
|
|
|
{ |
137
|
|
|
$this->setArgument(sprintf('-dCalGrayProfile=(%s)', $valGrayProfile)); |
138
|
|
|
|
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Get cal RGB profile |
144
|
|
|
* |
145
|
|
|
* @return null|string |
146
|
|
|
*/ |
147
|
|
|
public function getCalRgbProfile() |
148
|
|
|
{ |
149
|
|
|
$value = $this->getArgumentValue('-dCalRGBProfile'); |
150
|
|
|
if (null === $value) { |
151
|
|
|
return null; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return substr($value, 1, -1); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Set cal RGB profile |
159
|
|
|
* |
160
|
|
|
* @param string $valRgbProfile |
161
|
|
|
* |
162
|
|
|
* @return $this |
163
|
|
|
*/ |
164
|
|
|
public function setCalRgbProfile($valRgbProfile) |
165
|
|
|
{ |
166
|
|
|
$this->setArgument(sprintf('-dCalRGBProfile=(%s)', $valRgbProfile)); |
167
|
|
|
|
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Get color conversion strategy |
173
|
|
|
* |
174
|
|
|
* @return string |
175
|
|
|
*/ |
176
|
|
|
public function getColorConversionStrategy() |
177
|
|
|
{ |
178
|
|
|
$value = $this->getArgumentValue('-dColorConversionStrategy'); |
179
|
|
|
if (null === $value) { |
180
|
|
|
return DistillerParametersInterface::COLOR_CONVERSION_STRATEGY_LEAVE_COLOR_UNCHANGED; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
return substr($value, 1); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Set color conversion strategy |
188
|
|
|
* |
189
|
|
|
* @param string $colorConversionStrategy |
190
|
|
|
* |
191
|
|
|
* @throws \InvalidArgumentException |
192
|
|
|
* |
193
|
|
|
* @return $this |
194
|
|
|
*/ |
195
|
|
|
public function setColorConversionStrategy($colorConversionStrategy) |
196
|
|
|
{ |
197
|
|
|
if (!in_array($colorConversionStrategy, static::$colorConversionStrategyValues)) { |
198
|
|
|
throw new \InvalidArgumentException('Invalid color conversion strategy argument'); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
$this->setArgument(sprintf('-dColorConversionStrategy=/%s', $colorConversionStrategy)); |
202
|
|
|
|
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Whether to convert CMYK images to RGB |
208
|
|
|
* |
209
|
|
|
* @return bool |
210
|
|
|
*/ |
211
|
|
|
public function isConvertCmykImagesToRgb() |
212
|
|
|
{ |
213
|
|
|
$value = $this->getArgumentValue('-dConvertCMYKImagesToRGB'); |
214
|
|
|
if (null === $value) { |
215
|
|
|
return false; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Set convert convert CMYK images to RGB flag |
223
|
|
|
* |
224
|
|
|
* @param bool $convertCmykImagesToRgb |
225
|
|
|
* |
226
|
|
|
* @return $this |
227
|
|
|
*/ |
228
|
|
|
public function setConvertCmykImagesToRgb($convertCmykImagesToRgb) |
229
|
|
|
{ |
230
|
|
|
$this->setArgument(sprintf('-dConvertCMYKImagesToRGB=%s', $convertCmykImagesToRgb ? 'true' : 'false')); |
231
|
|
|
|
232
|
|
|
return $this; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Whether to convert images to indexed |
237
|
|
|
* |
238
|
|
|
* @return bool |
239
|
|
|
*/ |
240
|
|
|
public function isConvertImagesToIndexed() |
241
|
|
|
{ |
242
|
|
|
$value = $this->getArgumentValue('-dConvertImagesToIndexed'); |
243
|
|
|
if (null === $value) { |
244
|
|
|
return false; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Set convert images to indexed flag |
252
|
|
|
* |
253
|
|
|
* @param bool $convertImagesToIndexed |
254
|
|
|
* |
255
|
|
|
* @return $this |
256
|
|
|
*/ |
257
|
|
|
public function setConvertImagesToIndexed($convertImagesToIndexed) |
258
|
|
|
{ |
259
|
|
|
$this->setArgument(sprintf('-dConvertImagesToIndexed=%s', $convertImagesToIndexed ? 'true' : 'false')); |
260
|
|
|
|
261
|
|
|
return $this; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Get default rendering intent |
266
|
|
|
* |
267
|
|
|
* @return string |
268
|
|
|
*/ |
269
|
|
|
public function getDefaultRenderingIntent() |
270
|
|
|
{ |
271
|
|
|
$value = $this->getArgumentValue('-dDefaultRenderingIntent'); |
272
|
|
|
if (null === $value) { |
273
|
|
|
return DistillerParametersInterface::DEFAULT_RENDERING_INTENT_DEFAULT; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
return substr($value, 1); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Set default rendering intent |
281
|
|
|
* |
282
|
|
|
* @param string $defaultRenderingIntent |
283
|
|
|
* |
284
|
|
|
* @throws \InvalidArgumentException |
285
|
|
|
* |
286
|
|
|
* @return $this |
287
|
|
|
*/ |
288
|
|
|
public function setDefaultRenderingIntent($defaultRenderingIntent) |
289
|
|
|
{ |
290
|
|
|
if (!in_array($defaultRenderingIntent, static::$defaultRenderingIntentValues)) { |
291
|
|
|
throw new \InvalidArgumentException('Invalid default rendering intent argument'); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
$this->setArgument(sprintf('-dDefaultRenderingIntent=/%s', $defaultRenderingIntent)); |
295
|
|
|
|
296
|
|
|
return $this; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Get sRGB profile |
301
|
|
|
* |
302
|
|
|
* @return null|string |
303
|
|
|
*/ |
304
|
|
|
public function getsRgbProfile() |
305
|
|
|
{ |
306
|
|
|
$value = $this->getArgumentValue('-dsRGBProfile'); |
307
|
|
|
if (null === $value) { |
308
|
|
|
return null; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
return substr($value, 1, -1); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Set sRGB profile |
316
|
|
|
* |
317
|
|
|
* @param string $sRgbProfile |
318
|
|
|
* |
319
|
|
|
* @return $this |
320
|
|
|
*/ |
321
|
|
|
public function setsRgbProfile($sRgbProfile) |
322
|
|
|
{ |
323
|
|
|
$this->setArgument(sprintf('-dsRGBProfile=(%s)', $sRgbProfile)); |
324
|
|
|
|
325
|
|
|
return $this; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Whether to preserve halftone info |
330
|
|
|
* |
331
|
|
|
* @return bool |
332
|
|
|
*/ |
333
|
|
|
public function isPreserveHalftoneInfo() |
334
|
|
|
{ |
335
|
|
|
$value = $this->getArgumentValue('-dPreserveHalftoneInfo'); |
336
|
|
|
if (null === $value) { |
337
|
|
|
return false; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* Set preserve halftone info flag |
345
|
|
|
* |
346
|
|
|
* @param bool $preserveHalftoneInfo |
347
|
|
|
* |
348
|
|
|
* @return $this |
349
|
|
|
*/ |
350
|
|
|
public function setPreserveHalftoneInfo($preserveHalftoneInfo) |
351
|
|
|
{ |
352
|
|
|
$this->setArgument(sprintf('-dPreserveHalftoneInfo=%s', $preserveHalftoneInfo ? 'true' : 'false')); |
353
|
|
|
|
354
|
|
|
return $this; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Whether to preserve overprint settings |
359
|
|
|
* |
360
|
|
|
* @return bool |
361
|
|
|
*/ |
362
|
|
|
public function isPreserveOverprintSettings() |
363
|
|
|
{ |
364
|
|
|
$value = $this->getArgumentValue('-dPreserveOverprintSettings'); |
365
|
|
|
if (null === $value) { |
366
|
|
|
return false; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* Set preserve overprint settings flag |
374
|
|
|
* |
375
|
|
|
* @param bool $preserveOverprintSettings |
376
|
|
|
* |
377
|
|
|
* @return $this |
378
|
|
|
*/ |
379
|
|
|
public function setPreserveOverprintSettings($preserveOverprintSettings) |
380
|
|
|
{ |
381
|
|
|
$this->setArgument(sprintf('-dPreserveOverprintSettings=%s', $preserveOverprintSettings ? 'true' : 'false')); |
382
|
|
|
|
383
|
|
|
return $this; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* Get transfer function info |
388
|
|
|
* |
389
|
|
|
* @return string |
390
|
|
|
*/ |
391
|
|
|
public function getTransferFunctionInfo() |
392
|
|
|
{ |
393
|
|
|
$value = $this->getArgumentValue('-dTransferFunctionInfo'); |
394
|
|
|
if (null === $value) { |
395
|
|
|
return DistillerParametersInterface::DEFAULT_RENDERING_INTENT_DEFAULT; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
return substr($value, 1); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Set transfer function info |
403
|
|
|
* |
404
|
|
|
* @param string $transferFunctionInfo |
405
|
|
|
* |
406
|
|
|
* @throws \InvalidArgumentException |
407
|
|
|
* |
408
|
|
|
* @return $this |
409
|
|
|
*/ |
410
|
|
|
public function setTransferFunctionInfo($transferFunctionInfo) |
411
|
|
|
{ |
412
|
|
|
if (!in_array($transferFunctionInfo, static::$transferFunctionInfoValues)) { |
413
|
|
|
throw new \InvalidArgumentException('Invalid transfer function info argument'); |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
$this->setArgument(sprintf('-dTransferFunctionInfo=/%s', $transferFunctionInfo)); |
417
|
|
|
|
418
|
|
|
return $this; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Get UCR and BG info |
423
|
|
|
* |
424
|
|
|
* @return string |
425
|
|
|
*/ |
426
|
|
|
public function getUcrAndBgInfo() |
427
|
|
|
{ |
428
|
|
|
$value = $this->getArgumentValue('-dUCRandBGInfo'); |
429
|
|
|
if (null === $value) { |
430
|
|
|
return DistillerParametersInterface::UCR_AND_BG_INFO_REMOVE; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
return substr($value, 1); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Set UCR and BG info |
438
|
|
|
* |
439
|
|
|
* @param string $ucrAndBgInfo |
440
|
|
|
* |
441
|
|
|
* @throws \InvalidArgumentException |
442
|
|
|
* |
443
|
|
|
* @return $this |
444
|
|
|
*/ |
445
|
|
|
public function setUcrAndBgInfo($ucrAndBgInfo) |
446
|
|
|
{ |
447
|
|
|
if (!in_array($ucrAndBgInfo, static::$ucrAndBgInfoValues)) { |
448
|
|
|
throw new \InvalidArgumentException('Invalid UCR and BG info argument'); |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
$this->setArgument(sprintf('-dUCRandBGInfo=/%s', $ucrAndBgInfo)); |
452
|
|
|
|
453
|
|
|
return $this; |
454
|
|
|
} |
455
|
|
|
} |
456
|
|
|
|