| 1 |
<?php |
| 2 |
|
| 3 |
namespace TablePress\PhpOffice\PhpSpreadsheet\Worksheet\Drawing; |
| 4 |
|
| 5 |
use TablePress\PhpOffice\PhpSpreadsheet\IComparable; |
| 6 |
use TablePress\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 |
private bool $visible; |
| 24 |
|
| 25 |
/** |
| 26 |
* Blur radius. |
| 27 |
* |
| 28 |
* Defaults to 6 |
| 29 |
*/ |
| 30 |
private int $blurRadius; |
| 31 |
|
| 32 |
/** |
| 33 |
* Shadow distance. |
| 34 |
* |
| 35 |
* Defaults to 2 |
| 36 |
*/ |
| 37 |
private int $distance; |
| 38 |
|
| 39 |
/** |
| 40 |
* Shadow direction (in degrees). |
| 41 |
*/ |
| 42 |
private int $direction; |
| 43 |
|
| 44 |
/** |
| 45 |
* Shadow alignment. |
| 46 |
*/ |
| 47 |
private string $alignment; |
| 48 |
|
| 49 |
/** |
| 50 |
* Color. |
| 51 |
*/ |
| 52 |
private Color $color; |
| 53 |
|
| 54 |
/** |
| 55 |
* Alpha. |
| 56 |
*/ |
| 57 |
private int $alpha; |
| 58 |
|
| 59 |
/** |
| 60 |
* Create a new Shadow. |
| 61 |
*/ |
| 62 |
public function __construct() |
| 63 |
{ |
| 64 |
// Initialise values |
| 65 |
$this->visible = false; |
| 66 |
$this->blurRadius = 6; |
| 67 |
$this->distance = 2; |
| 68 |
$this->direction = 0; |
| 69 |
$this->alignment = self::SHADOW_BOTTOM_RIGHT; |
| 70 |
$this->color = new Color(Color::COLOR_BLACK); |
| 71 |
$this->alpha = 50; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Get Visible. |
| 76 |
*/ |
| 77 |
public function getVisible(): bool |
| 78 |
{ |
| 79 |
return $this->visible; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Set Visible. |
| 84 |
* |
| 85 |
* @return $this |
| 86 |
*/ |
| 87 |
public function setVisible(bool $visible) |
| 88 |
{ |
| 89 |
$this->visible = $visible; |
| 90 |
|
| 91 |
return $this; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Get Blur radius. |
| 96 |
*/ |
| 97 |
public function getBlurRadius(): int |
| 98 |
{ |
| 99 |
return $this->blurRadius; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Set Blur radius. |
| 104 |
* |
| 105 |
* @return $this |
| 106 |
*/ |
| 107 |
public function setBlurRadius(int $blurRadius) |
| 108 |
{ |
| 109 |
$this->blurRadius = $blurRadius; |
| 110 |
|
| 111 |
return $this; |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Get Shadow distance. |
| 116 |
*/ |
| 117 |
public function getDistance(): int |
| 118 |
{ |
| 119 |
return $this->distance; |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Set Shadow distance. |
| 124 |
* |
| 125 |
* @return $this |
| 126 |
*/ |
| 127 |
public function setDistance(int $distance) |
| 128 |
{ |
| 129 |
$this->distance = $distance; |
| 130 |
|
| 131 |
return $this; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Get Shadow direction (in degrees). |
| 136 |
*/ |
| 137 |
public function getDirection(): int |
| 138 |
{ |
| 139 |
return $this->direction; |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Set Shadow direction (in degrees). |
| 144 |
* |
| 145 |
* @return $this |
| 146 |
*/ |
| 147 |
public function setDirection(int $direction) |
| 148 |
{ |
| 149 |
$this->direction = $direction; |
| 150 |
|
| 151 |
return $this; |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Get Shadow alignment. |
| 156 |
*/ |
| 157 |
public function getAlignment(): string |
| 158 |
{ |
| 159 |
return $this->alignment; |
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* Set Shadow alignment. |
| 164 |
* |
| 165 |
* @return $this |
| 166 |
*/ |
| 167 |
public function setAlignment(string $alignment) |
| 168 |
{ |
| 169 |
$this->alignment = $alignment; |
| 170 |
|
| 171 |
return $this; |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Get Color. |
| 176 |
*/ |
| 177 |
public function getColor(): Color |
| 178 |
{ |
| 179 |
return $this->color; |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* Set Color. |
| 184 |
* |
| 185 |
* @return $this |
| 186 |
*/ |
| 187 |
public function setColor(Color $color) |
| 188 |
{ |
| 189 |
$this->color = $color; |
| 190 |
|
| 191 |
return $this; |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Get Alpha. |
| 196 |
*/ |
| 197 |
public function getAlpha(): int |
| 198 |
{ |
| 199 |
return $this->alpha; |
| 200 |
} |
| 201 |
|
| 202 |
/** |
| 203 |
* Set Alpha. |
| 204 |
* |
| 205 |
* @return $this |
| 206 |
*/ |
| 207 |
public function setAlpha(int $alpha) |
| 208 |
{ |
| 209 |
$this->alpha = $alpha; |
| 210 |
|
| 211 |
return $this; |
| 212 |
} |
| 213 |
|
| 214 |
/** |
| 215 |
* Get hash code. |
| 216 |
* |
| 217 |
* @return string Hash code |
| 218 |
*/ |
| 219 |
public function getHashCode(): string |
| 220 |
{ |
| 221 |
return md5( |
| 222 |
($this->visible ? 't' : 'f') |
| 223 |
. $this->blurRadius |
| 224 |
. $this->distance |
| 225 |
. $this->direction |
| 226 |
. $this->alignment |
| 227 |
. $this->color->getHashCode() |
| 228 |
. $this->alpha |
| 229 |
. __CLASS__ |
| 230 |
); |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
| 235 |
*/ |
| 236 |
public function __clone() |
| 237 |
{ |
| 238 |
$vars = get_object_vars($this); |
| 239 |
foreach ($vars as $key => $value) { |
| 240 |
if (is_object($value)) { |
| 241 |
$this->$key = clone $value; |
| 242 |
} else { |
| 243 |
$this->$key = $value; |
| 244 |
} |
| 245 |
} |
| 246 |
} |
| 247 |
} |
| 248 |
|