Completed
Push — master ( cefa14...785c06 )
by Daniel
03:06
created

PageCompressionTrait::getArgumentValue()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 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\Devices\DistillerParameters;
9
10
/**
11
 * The page compression distiller parameters trait
12
 *
13
 * @package GravityMedia\Ghostscript\Devices\DistillerParameters
14
 */
15
trait PageCompressionTrait
16
{
17
    /**
18
     * Get argument value
19
     *
20
     * @param string $name
21
     *
22
     * @return string
23
     */
24
    abstract protected function getArgumentValue($name);
25
26
    /**
27
     * Set argument
28
     *
29
     * @param string $argument
30
     *
31
     * @return $this
32
     */
33
    abstract protected function setArgument($argument);
34
35
    /**
36
     * Whether to compress pages
37
     *
38
     * @return bool
39
     */
40
    public function getCompressPages()
41
    {
42
        $value = $this->getArgumentValue('-dCompressPages');
43
        if (null === $value) {
44
            return true;
45
        }
46
47
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
48
    }
49
50
    /**
51
     * Set compress pages flag
52
     *
53
     * @param true $compressPages
54
     *
55
     * @return $this
56
     */
57
    public function setCompressPages($compressPages)
58
    {
59
        $this->setArgument(sprintf('-dCompressPages=%s', $compressPages ? 'true' : 'false'));
60
61
        return $this;
62
    }
63
64
    /**
65
     * Whether to LZW encode pages
66
     *
67
     * @return bool
68
     */
69
    public function isLzwEncodePages()
70
    {
71
        $value = $this->getArgumentValue('-dLZWEncodePages');
72
        if (null === $value) {
73
            return false;
74
        }
75
76
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
77
    }
78
79
    /**
80
     * Set LZW encode pages flag
81
     *
82
     * @param string $lzwEncodePages
83
     *
84
     * @return $this
85
     */
86
    public function setLzwEncodePages($lzwEncodePages)
87
    {
88
        $this->setArgument(sprintf('-dLZWEncodePages=%s', $lzwEncodePages ? 'true' : 'false'));
89
90
        return $this;
91
    }
92
}
93