1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Worksheet\Drawing; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\IComparable; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Color; |
7
|
|
|
|
8
|
|
|
class Shadow implements IComparable |
9
|
|
|
{ |
10
|
|
|
// Shadow alignment |
11
|
|
|
const SHADOW_BOTTOM = 'b'; |
12
|
|
|
const SHADOW_BOTTOM_LEFT = 'bl'; |
13
|
|
|
const SHADOW_BOTTOM_RIGHT = 'br'; |
14
|
|
|
const SHADOW_CENTER = 'ctr'; |
15
|
|
|
const SHADOW_LEFT = 'l'; |
16
|
|
|
const SHADOW_TOP = 't'; |
17
|
|
|
const SHADOW_TOP_LEFT = 'tl'; |
18
|
|
|
const SHADOW_TOP_RIGHT = 'tr'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Visible. |
22
|
|
|
* |
23
|
|
|
* @var bool |
24
|
|
|
*/ |
25
|
|
|
private $visible; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Blur radius. |
29
|
|
|
* |
30
|
|
|
* Defaults to 6 |
31
|
|
|
* |
32
|
|
|
* @var int |
33
|
|
|
*/ |
34
|
|
|
private $blurRadius; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Shadow distance. |
38
|
|
|
* |
39
|
|
|
* Defaults to 2 |
40
|
|
|
* |
41
|
|
|
* @var int |
42
|
|
|
*/ |
43
|
|
|
private $distance; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Shadow direction (in degrees). |
47
|
|
|
* |
48
|
|
|
* @var int |
49
|
|
|
*/ |
50
|
|
|
private $direction; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Shadow alignment. |
54
|
|
|
* |
55
|
|
|
* @var int |
56
|
|
|
*/ |
57
|
|
|
private $alignment; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Color. |
61
|
|
|
* |
62
|
|
|
* @var Color |
63
|
|
|
*/ |
64
|
|
|
private $color; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Alpha. |
68
|
|
|
* |
69
|
|
|
* @var int |
70
|
|
|
*/ |
71
|
|
|
private $alpha; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Create a new Shadow. |
75
|
|
|
*/ |
76
|
24 |
|
public function __construct() |
77
|
|
|
{ |
78
|
|
|
// Initialise values |
79
|
24 |
|
$this->visible = false; |
80
|
24 |
|
$this->blurRadius = 6; |
81
|
24 |
|
$this->distance = 2; |
82
|
24 |
|
$this->direction = 0; |
83
|
24 |
|
$this->alignment = self::SHADOW_BOTTOM_RIGHT; |
|
|
|
|
84
|
24 |
|
$this->color = new Color(Color::COLOR_BLACK); |
85
|
24 |
|
$this->alpha = 50; |
86
|
24 |
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get Visible. |
90
|
|
|
* |
91
|
|
|
* @return bool |
92
|
|
|
*/ |
93
|
12 |
|
public function getVisible() |
94
|
|
|
{ |
95
|
12 |
|
return $this->visible; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Set Visible. |
100
|
|
|
* |
101
|
|
|
* @param bool $pValue |
102
|
|
|
* |
103
|
|
|
* @return Shadow |
104
|
|
|
*/ |
105
|
12 |
|
public function setVisible($pValue) |
106
|
|
|
{ |
107
|
12 |
|
$this->visible = $pValue; |
108
|
|
|
|
109
|
12 |
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Get Blur radius. |
114
|
|
|
* |
115
|
|
|
* @return int |
116
|
|
|
*/ |
117
|
5 |
|
public function getBlurRadius() |
118
|
|
|
{ |
119
|
5 |
|
return $this->blurRadius; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Set Blur radius. |
124
|
|
|
* |
125
|
|
|
* @param int $pValue |
126
|
|
|
* |
127
|
|
|
* @return Shadow |
128
|
|
|
*/ |
129
|
2 |
|
public function setBlurRadius($pValue) |
130
|
|
|
{ |
131
|
2 |
|
$this->blurRadius = $pValue; |
132
|
|
|
|
133
|
2 |
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Get Shadow distance. |
138
|
|
|
* |
139
|
|
|
* @return int |
140
|
|
|
*/ |
141
|
5 |
|
public function getDistance() |
142
|
|
|
{ |
143
|
5 |
|
return $this->distance; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Set Shadow distance. |
148
|
|
|
* |
149
|
|
|
* @param int $pValue |
150
|
|
|
* |
151
|
|
|
* @return Shadow |
152
|
|
|
*/ |
153
|
2 |
|
public function setDistance($pValue) |
154
|
|
|
{ |
155
|
2 |
|
$this->distance = $pValue; |
156
|
|
|
|
157
|
2 |
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Get Shadow direction (in degrees). |
162
|
|
|
* |
163
|
|
|
* @return int |
164
|
|
|
*/ |
165
|
5 |
|
public function getDirection() |
166
|
|
|
{ |
167
|
5 |
|
return $this->direction; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Set Shadow direction (in degrees). |
172
|
|
|
* |
173
|
|
|
* @param int $pValue |
174
|
|
|
* |
175
|
|
|
* @return Shadow |
176
|
|
|
*/ |
177
|
12 |
|
public function setDirection($pValue) |
178
|
|
|
{ |
179
|
12 |
|
$this->direction = $pValue; |
180
|
|
|
|
181
|
12 |
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Get Shadow alignment. |
186
|
|
|
* |
187
|
|
|
* @return int |
188
|
|
|
*/ |
189
|
5 |
|
public function getAlignment() |
190
|
|
|
{ |
191
|
5 |
|
return $this->alignment; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Set Shadow alignment. |
196
|
|
|
* |
197
|
|
|
* @param int $pValue |
198
|
|
|
* |
199
|
|
|
* @return Shadow |
200
|
|
|
*/ |
201
|
2 |
|
public function setAlignment($pValue) |
202
|
|
|
{ |
203
|
2 |
|
$this->alignment = $pValue; |
204
|
|
|
|
205
|
2 |
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Get Color. |
210
|
|
|
* |
211
|
|
|
* @return Color |
212
|
|
|
*/ |
213
|
5 |
|
public function getColor() |
214
|
|
|
{ |
215
|
5 |
|
return $this->color; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Set Color. |
220
|
|
|
* |
221
|
|
|
* @param Color $pValue |
222
|
|
|
* |
223
|
|
|
* @return Shadow |
224
|
|
|
*/ |
225
|
|
|
public function setColor(Color $pValue = null) |
226
|
|
|
{ |
227
|
|
|
$this->color = $pValue; |
228
|
|
|
|
229
|
|
|
return $this; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Get Alpha. |
234
|
|
|
* |
235
|
|
|
* @return int |
236
|
|
|
*/ |
237
|
5 |
|
public function getAlpha() |
238
|
|
|
{ |
239
|
5 |
|
return $this->alpha; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Set Alpha. |
244
|
|
|
* |
245
|
|
|
* @param int $pValue |
246
|
|
|
* |
247
|
|
|
* @return Shadow |
248
|
|
|
*/ |
249
|
2 |
|
public function setAlpha($pValue) |
250
|
|
|
{ |
251
|
2 |
|
$this->alpha = $pValue; |
252
|
|
|
|
253
|
2 |
|
return $this; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Get hash code. |
258
|
|
|
* |
259
|
|
|
* @return string Hash code |
260
|
|
|
*/ |
261
|
12 |
|
public function getHashCode() |
262
|
|
|
{ |
263
|
12 |
|
return md5( |
264
|
12 |
|
($this->visible ? 't' : 'f') . |
265
|
12 |
|
$this->blurRadius . |
266
|
12 |
|
$this->distance . |
267
|
12 |
|
$this->direction . |
268
|
12 |
|
$this->alignment . |
269
|
12 |
|
$this->color->getHashCode() . |
270
|
12 |
|
$this->alpha . |
271
|
12 |
|
__CLASS__ |
272
|
|
|
); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
277
|
|
|
*/ |
278
|
1 |
|
public function __clone() |
279
|
|
|
{ |
280
|
1 |
|
$vars = get_object_vars($this); |
281
|
1 |
|
foreach ($vars as $key => $value) { |
282
|
1 |
|
if (is_object($value)) { |
283
|
1 |
|
$this->$key = clone $value; |
284
|
|
|
} else { |
285
|
1 |
|
$this->$key = $value; |
286
|
|
|
} |
287
|
|
|
} |
288
|
1 |
|
} |
289
|
|
|
} |
290
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.