Shadow.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. /**
  3. * PHPExcel_Worksheet_Drawing_Shadow
  4. *
  5. * Copyright (c) 2006 - 2015 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Worksheet_Drawing
  23. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. class PHPExcel_Worksheet_Drawing_Shadow implements PHPExcel_IComparable
  28. {
  29. /* Shadow alignment */
  30. const SHADOW_BOTTOM = 'b';
  31. const SHADOW_BOTTOM_LEFT = 'bl';
  32. const SHADOW_BOTTOM_RIGHT = 'br';
  33. const SHADOW_CENTER = 'ctr';
  34. const SHADOW_LEFT = 'l';
  35. const SHADOW_TOP = 't';
  36. const SHADOW_TOP_LEFT = 'tl';
  37. const SHADOW_TOP_RIGHT = 'tr';
  38. /**
  39. * Visible
  40. *
  41. * @var boolean
  42. */
  43. private $visible;
  44. /**
  45. * Blur radius
  46. *
  47. * Defaults to 6
  48. *
  49. * @var int
  50. */
  51. private $blurRadius;
  52. /**
  53. * Shadow distance
  54. *
  55. * Defaults to 2
  56. *
  57. * @var int
  58. */
  59. private $distance;
  60. /**
  61. * Shadow direction (in degrees)
  62. *
  63. * @var int
  64. */
  65. private $direction;
  66. /**
  67. * Shadow alignment
  68. *
  69. * @var int
  70. */
  71. private $alignment;
  72. /**
  73. * Color
  74. *
  75. * @var PHPExcel_Style_Color
  76. */
  77. private $color;
  78. /**
  79. * Alpha
  80. *
  81. * @var int
  82. */
  83. private $alpha;
  84. /**
  85. * Create a new PHPExcel_Worksheet_Drawing_Shadow
  86. */
  87. public function __construct()
  88. {
  89. // Initialise values
  90. $this->visible = false;
  91. $this->blurRadius = 6;
  92. $this->distance = 2;
  93. $this->direction = 0;
  94. $this->alignment = PHPExcel_Worksheet_Drawing_Shadow::SHADOW_BOTTOM_RIGHT;
  95. $this->color = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK);
  96. $this->alpha = 50;
  97. }
  98. /**
  99. * Get Visible
  100. *
  101. * @return boolean
  102. */
  103. public function getVisible()
  104. {
  105. return $this->visible;
  106. }
  107. /**
  108. * Set Visible
  109. *
  110. * @param boolean $pValue
  111. * @return PHPExcel_Worksheet_Drawing_Shadow
  112. */
  113. public function setVisible($pValue = false)
  114. {
  115. $this->visible = $pValue;
  116. return $this;
  117. }
  118. /**
  119. * Get Blur radius
  120. *
  121. * @return int
  122. */
  123. public function getBlurRadius()
  124. {
  125. return $this->blurRadius;
  126. }
  127. /**
  128. * Set Blur radius
  129. *
  130. * @param int $pValue
  131. * @return PHPExcel_Worksheet_Drawing_Shadow
  132. */
  133. public function setBlurRadius($pValue = 6)
  134. {
  135. $this->blurRadius = $pValue;
  136. return $this;
  137. }
  138. /**
  139. * Get Shadow distance
  140. *
  141. * @return int
  142. */
  143. public function getDistance()
  144. {
  145. return $this->distance;
  146. }
  147. /**
  148. * Set Shadow distance
  149. *
  150. * @param int $pValue
  151. * @return PHPExcel_Worksheet_Drawing_Shadow
  152. */
  153. public function setDistance($pValue = 2)
  154. {
  155. $this->distance = $pValue;
  156. return $this;
  157. }
  158. /**
  159. * Get Shadow direction (in degrees)
  160. *
  161. * @return int
  162. */
  163. public function getDirection()
  164. {
  165. return $this->direction;
  166. }
  167. /**
  168. * Set Shadow direction (in degrees)
  169. *
  170. * @param int $pValue
  171. * @return PHPExcel_Worksheet_Drawing_Shadow
  172. */
  173. public function setDirection($pValue = 0)
  174. {
  175. $this->direction = $pValue;
  176. return $this;
  177. }
  178. /**
  179. * Get Shadow alignment
  180. *
  181. * @return int
  182. */
  183. public function getAlignment()
  184. {
  185. return $this->alignment;
  186. }
  187. /**
  188. * Set Shadow alignment
  189. *
  190. * @param int $pValue
  191. * @return PHPExcel_Worksheet_Drawing_Shadow
  192. */
  193. public function setAlignment($pValue = 0)
  194. {
  195. $this->alignment = $pValue;
  196. return $this;
  197. }
  198. /**
  199. * Get Color
  200. *
  201. * @return PHPExcel_Style_Color
  202. */
  203. public function getColor()
  204. {
  205. return $this->color;
  206. }
  207. /**
  208. * Set Color
  209. *
  210. * @param PHPExcel_Style_Color $pValue
  211. * @throws PHPExcel_Exception
  212. * @return PHPExcel_Worksheet_Drawing_Shadow
  213. */
  214. public function setColor(PHPExcel_Style_Color $pValue = null)
  215. {
  216. $this->color = $pValue;
  217. return $this;
  218. }
  219. /**
  220. * Get Alpha
  221. *
  222. * @return int
  223. */
  224. public function getAlpha()
  225. {
  226. return $this->alpha;
  227. }
  228. /**
  229. * Set Alpha
  230. *
  231. * @param int $pValue
  232. * @return PHPExcel_Worksheet_Drawing_Shadow
  233. */
  234. public function setAlpha($pValue = 0)
  235. {
  236. $this->alpha = $pValue;
  237. return $this;
  238. }
  239. /**
  240. * Get hash code
  241. *
  242. * @return string Hash code
  243. */
  244. public function getHashCode()
  245. {
  246. return md5(
  247. ($this->visible ? 't' : 'f') .
  248. $this->blurRadius .
  249. $this->distance .
  250. $this->direction .
  251. $this->alignment .
  252. $this->color->getHashCode() .
  253. $this->alpha .
  254. __CLASS__
  255. );
  256. }
  257. /**
  258. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  259. */
  260. public function __clone()
  261. {
  262. $vars = get_object_vars($this);
  263. foreach ($vars as $key => $value) {
  264. if (is_object($value)) {
  265. $this->$key = clone $value;
  266. } else {
  267. $this->$key = $value;
  268. }
  269. }
  270. }
  271. }