Shadow.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2014 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 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.8.0, 2014-03-02
  26. */
  27. /**
  28. * PHPExcel_Worksheet_Drawing_Shadow
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Worksheet_Drawing
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Worksheet_Drawing_Shadow implements PHPExcel_IComparable
  35. {
  36. /* Shadow alignment */
  37. const SHADOW_BOTTOM = 'b';
  38. const SHADOW_BOTTOM_LEFT = 'bl';
  39. const SHADOW_BOTTOM_RIGHT = 'br';
  40. const SHADOW_CENTER = 'ctr';
  41. const SHADOW_LEFT = 'l';
  42. const SHADOW_TOP = 't';
  43. const SHADOW_TOP_LEFT = 'tl';
  44. const SHADOW_TOP_RIGHT = 'tr';
  45. /**
  46. * Visible
  47. *
  48. * @var boolean
  49. */
  50. private $_visible;
  51. /**
  52. * Blur radius
  53. *
  54. * Defaults to 6
  55. *
  56. * @var int
  57. */
  58. private $_blurRadius;
  59. /**
  60. * Shadow distance
  61. *
  62. * Defaults to 2
  63. *
  64. * @var int
  65. */
  66. private $_distance;
  67. /**
  68. * Shadow direction (in degrees)
  69. *
  70. * @var int
  71. */
  72. private $_direction;
  73. /**
  74. * Shadow alignment
  75. *
  76. * @var int
  77. */
  78. private $_alignment;
  79. /**
  80. * Color
  81. *
  82. * @var PHPExcel_Style_Color
  83. */
  84. private $_color;
  85. /**
  86. * Alpha
  87. *
  88. * @var int
  89. */
  90. private $_alpha;
  91. /**
  92. * Create a new PHPExcel_Worksheet_Drawing_Shadow
  93. */
  94. public function __construct()
  95. {
  96. // Initialise values
  97. $this->_visible = false;
  98. $this->_blurRadius = 6;
  99. $this->_distance = 2;
  100. $this->_direction = 0;
  101. $this->_alignment = PHPExcel_Worksheet_Drawing_Shadow::SHADOW_BOTTOM_RIGHT;
  102. $this->_color = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK);
  103. $this->_alpha = 50;
  104. }
  105. /**
  106. * Get Visible
  107. *
  108. * @return boolean
  109. */
  110. public function getVisible() {
  111. return $this->_visible;
  112. }
  113. /**
  114. * Set Visible
  115. *
  116. * @param boolean $pValue
  117. * @return PHPExcel_Worksheet_Drawing_Shadow
  118. */
  119. public function setVisible($pValue = false) {
  120. $this->_visible = $pValue;
  121. return $this;
  122. }
  123. /**
  124. * Get Blur radius
  125. *
  126. * @return int
  127. */
  128. public function getBlurRadius() {
  129. return $this->_blurRadius;
  130. }
  131. /**
  132. * Set Blur radius
  133. *
  134. * @param int $pValue
  135. * @return PHPExcel_Worksheet_Drawing_Shadow
  136. */
  137. public function setBlurRadius($pValue = 6) {
  138. $this->_blurRadius = $pValue;
  139. return $this;
  140. }
  141. /**
  142. * Get Shadow distance
  143. *
  144. * @return int
  145. */
  146. public function getDistance() {
  147. return $this->_distance;
  148. }
  149. /**
  150. * Set Shadow distance
  151. *
  152. * @param int $pValue
  153. * @return PHPExcel_Worksheet_Drawing_Shadow
  154. */
  155. public function setDistance($pValue = 2) {
  156. $this->_distance = $pValue;
  157. return $this;
  158. }
  159. /**
  160. * Get Shadow direction (in degrees)
  161. *
  162. * @return int
  163. */
  164. public function getDirection() {
  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. $this->_direction = $pValue;
  175. return $this;
  176. }
  177. /**
  178. * Get Shadow alignment
  179. *
  180. * @return int
  181. */
  182. public function getAlignment() {
  183. return $this->_alignment;
  184. }
  185. /**
  186. * Set Shadow alignment
  187. *
  188. * @param int $pValue
  189. * @return PHPExcel_Worksheet_Drawing_Shadow
  190. */
  191. public function setAlignment($pValue = 0) {
  192. $this->_alignment = $pValue;
  193. return $this;
  194. }
  195. /**
  196. * Get Color
  197. *
  198. * @return PHPExcel_Style_Color
  199. */
  200. public function getColor() {
  201. return $this->_color;
  202. }
  203. /**
  204. * Set Color
  205. *
  206. * @param PHPExcel_Style_Color $pValue
  207. * @throws PHPExcel_Exception
  208. * @return PHPExcel_Worksheet_Drawing_Shadow
  209. */
  210. public function setColor(PHPExcel_Style_Color $pValue = null) {
  211. $this->_color = $pValue;
  212. return $this;
  213. }
  214. /**
  215. * Get Alpha
  216. *
  217. * @return int
  218. */
  219. public function getAlpha() {
  220. return $this->_alpha;
  221. }
  222. /**
  223. * Set Alpha
  224. *
  225. * @param int $pValue
  226. * @return PHPExcel_Worksheet_Drawing_Shadow
  227. */
  228. public function setAlpha($pValue = 0) {
  229. $this->_alpha = $pValue;
  230. return $this;
  231. }
  232. /**
  233. * Get hash code
  234. *
  235. * @return string Hash code
  236. */
  237. public function getHashCode() {
  238. return md5(
  239. ($this->_visible ? 't' : 'f')
  240. . $this->_blurRadius
  241. . $this->_distance
  242. . $this->_direction
  243. . $this->_alignment
  244. . $this->_color->getHashCode()
  245. . $this->_alpha
  246. . __CLASS__
  247. );
  248. }
  249. /**
  250. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  251. */
  252. public function __clone() {
  253. $vars = get_object_vars($this);
  254. foreach ($vars as $key => $value) {
  255. if (is_object($value)) {
  256. $this->$key = clone $value;
  257. } else {
  258. $this->$key = $value;
  259. }
  260. }
  261. }
  262. }