|
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 font distiller parameters trait |
|
14
|
|
|
* |
|
15
|
|
|
* @package GravityMedia\Ghostscript\Devices\DistillerParameters |
|
16
|
|
|
*/ |
|
17
|
|
|
trait FontTrait |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Available cannot embed font policy values |
|
21
|
|
|
* |
|
22
|
|
|
* @var string[] |
|
23
|
|
|
*/ |
|
24
|
|
|
protected static $cannotEmbedFontPolicyValues = [ |
|
25
|
|
|
DistillerParametersInterface::CANNOT_EMBED_FONT_POLICY_OK, |
|
26
|
|
|
DistillerParametersInterface::CANNOT_EMBED_FONT_POLICY_WARNING, |
|
27
|
|
|
DistillerParametersInterface::CANNOT_EMBED_FONT_POLICY_ERROR |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Get argument value |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $name |
|
34
|
|
|
* |
|
35
|
|
|
* @return string |
|
36
|
|
|
*/ |
|
37
|
|
|
abstract protected function getArgumentValue($name); |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Set argument |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $argument |
|
43
|
|
|
* |
|
44
|
|
|
* @return $this |
|
45
|
|
|
*/ |
|
46
|
|
|
abstract protected function setArgument($argument); |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Get cannot embed font policy |
|
50
|
|
|
* |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getCannotEmbedFontPolicy() |
|
54
|
|
|
{ |
|
55
|
|
|
$value = $this->getArgumentValue('-dCannotEmbedFontPolicy'); |
|
56
|
|
|
if (null === $value) { |
|
57
|
|
|
return DistillerParametersInterface::CANNOT_EMBED_FONT_POLICY_WARNING; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return substr($value, 1); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Set cannot embed font policy |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $cannotEmbedFontPolicy |
|
67
|
|
|
* |
|
68
|
|
|
* @param \InvalidArgumentException |
|
69
|
|
|
* |
|
70
|
|
|
* @return $this |
|
71
|
|
|
*/ |
|
72
|
|
|
public function setCannotEmbedFontPolicy($cannotEmbedFontPolicy) |
|
73
|
|
|
{ |
|
74
|
|
|
if (!in_array($cannotEmbedFontPolicy, static::$cannotEmbedFontPolicyValues)) { |
|
75
|
|
|
throw new \InvalidArgumentException('Invalid cannot embed font policy argument'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$this->setArgument(sprintf('-dCannotEmbedFontPolicy=/%s', $cannotEmbedFontPolicy)); |
|
79
|
|
|
|
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Whether to embed all fonts |
|
85
|
|
|
* |
|
86
|
|
|
* @return bool |
|
87
|
|
|
*/ |
|
88
|
|
|
public function isEmbedAllFonts() |
|
89
|
|
|
{ |
|
90
|
|
|
$value = $this->getArgumentValue('-dEmbedAllFonts'); |
|
91
|
|
|
if (null === $value) { |
|
92
|
|
|
return true; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Set embed all fonts flag |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $embedAllFonts |
|
102
|
|
|
* |
|
103
|
|
|
* @return $this |
|
104
|
|
|
*/ |
|
105
|
|
|
public function setEmbedAllFonts($embedAllFonts) |
|
106
|
|
|
{ |
|
107
|
|
|
$this->setArgument(sprintf('-dEmbedAllFonts=%s', $embedAllFonts ? 'true' : 'false')); |
|
108
|
|
|
|
|
109
|
|
|
return $this; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get max subset pct |
|
114
|
|
|
* |
|
115
|
|
|
* @return int |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getMaxSubsetPct() |
|
118
|
|
|
{ |
|
119
|
|
|
$value = $this->getArgumentValue('-dMaxSubsetPct'); |
|
120
|
|
|
if (null === $value) { |
|
121
|
|
|
return 100; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
return intval($value); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Set max subset pct |
|
129
|
|
|
* |
|
130
|
|
|
* @param int $maxSubsetPct |
|
131
|
|
|
* |
|
132
|
|
|
* @return $this |
|
133
|
|
|
*/ |
|
134
|
|
|
public function setMaxSubsetPct($maxSubsetPct) |
|
135
|
|
|
{ |
|
136
|
|
|
$this->setArgument(sprintf('-dMaxSubsetPct=%s', $maxSubsetPct)); |
|
137
|
|
|
|
|
138
|
|
|
return $this; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Whether to subset fonts |
|
143
|
|
|
* |
|
144
|
|
|
* @return bool |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getSubsetFonts() |
|
147
|
|
|
{ |
|
148
|
|
|
$value = $this->getArgumentValue('-dSubsetFonts'); |
|
149
|
|
|
if (null === $value) { |
|
150
|
|
|
return true; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Set subset fonts flag |
|
158
|
|
|
* |
|
159
|
|
|
* @param bool $subsetFonts |
|
160
|
|
|
* |
|
161
|
|
|
* @return $this |
|
162
|
|
|
*/ |
|
163
|
|
|
public function setSubsetFonts($subsetFonts) |
|
164
|
|
|
{ |
|
165
|
|
|
$this->setArgument(sprintf('-dSubsetFonts=%s', $subsetFonts ? 'true' : 'false')); |
|
166
|
|
|
|
|
167
|
|
|
return $this; |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|