Completed
Push — master ( 7db5b7...e686f3 )
by Daniel
03:06
created

AdvancedTrait::setOpm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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