1<?php
2
3namespace PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
4
5use PhpOffice\PhpSpreadsheet\IComparable;
6use PhpOffice\PhpSpreadsheet\Style\Color;
7
8class 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    public function __construct()
77    {
78        // Initialise values
79        $this->visible = false;
80        $this->blurRadius = 6;
81        $this->distance = 2;
82        $this->direction = 0;
83        $this->alignment = self::SHADOW_BOTTOM_RIGHT;
84        $this->color = new Color(Color::COLOR_BLACK);
85        $this->alpha = 50;
86    }
87
88    /**
89     * Get Visible.
90     *
91     * @return bool
92     */
93    public function getVisible()
94    {
95        return $this->visible;
96    }
97
98    /**
99     * Set Visible.
100     *
101     * @param bool $pValue
102     *
103     * @return $this
104     */
105    public function setVisible($pValue)
106    {
107        $this->visible = $pValue;
108
109        return $this;
110    }
111
112    /**
113     * Get Blur radius.
114     *
115     * @return int
116     */
117    public function getBlurRadius()
118    {
119        return $this->blurRadius;
120    }
121
122    /**
123     * Set Blur radius.
124     *
125     * @param int $pValue
126     *
127     * @return $this
128     */
129    public function setBlurRadius($pValue)
130    {
131        $this->blurRadius = $pValue;
132
133        return $this;
134    }
135
136    /**
137     * Get Shadow distance.
138     *
139     * @return int
140     */
141    public function getDistance()
142    {
143        return $this->distance;
144    }
145
146    /**
147     * Set Shadow distance.
148     *
149     * @param int $pValue
150     *
151     * @return $this
152     */
153    public function setDistance($pValue)
154    {
155        $this->distance = $pValue;
156
157        return $this;
158    }
159
160    /**
161     * Get Shadow direction (in degrees).
162     *
163     * @return int
164     */
165    public function getDirection()
166    {
167        return $this->direction;
168    }
169
170    /**
171     * Set Shadow direction (in degrees).
172     *
173     * @param int $pValue
174     *
175     * @return $this
176     */
177    public function setDirection($pValue)
178    {
179        $this->direction = $pValue;
180
181        return $this;
182    }
183
184    /**
185     * Get Shadow alignment.
186     *
187     * @return int
188     */
189    public function getAlignment()
190    {
191        return $this->alignment;
192    }
193
194    /**
195     * Set Shadow alignment.
196     *
197     * @param int $pValue
198     *
199     * @return $this
200     */
201    public function setAlignment($pValue)
202    {
203        $this->alignment = $pValue;
204
205        return $this;
206    }
207
208    /**
209     * Get Color.
210     *
211     * @return Color
212     */
213    public function getColor()
214    {
215        return $this->color;
216    }
217
218    /**
219     * Set Color.
220     *
221     * @param Color $pValue
222     *
223     * @return $this
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    public function getAlpha()
238    {
239        return $this->alpha;
240    }
241
242    /**
243     * Set Alpha.
244     *
245     * @param int $pValue
246     *
247     * @return $this
248     */
249    public function setAlpha($pValue)
250    {
251        $this->alpha = $pValue;
252
253        return $this;
254    }
255
256    /**
257     * Get hash code.
258     *
259     * @return string Hash code
260     */
261    public function getHashCode()
262    {
263        return md5(
264            ($this->visible ? 't' : 'f') .
265            $this->blurRadius .
266            $this->distance .
267            $this->direction .
268            $this->alignment .
269            $this->color->getHashCode() .
270            $this->alpha .
271            __CLASS__
272        );
273    }
274
275    /**
276     * Implement PHP __clone to create a deep clone, not just a shallow copy.
277     */
278    public function __clone()
279    {
280        $vars = get_object_vars($this);
281        foreach ($vars as $key => $value) {
282            if (is_object($value)) {
283                $this->$key = clone $value;
284            } else {
285                $this->$key = $value;
286            }
287        }
288    }
289}
290