Shadow.php 4.7 KB

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