PageRenderTime 43ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/v1.2.0/Classes/PHPExcel/Style/Fill.php

#
PHP | 216 lines | 82 code | 20 blank | 114 comment | 4 complexity | d071034b666d8575a5e0de464884257e MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.0, LGPL-2.1, GPL-3.0, LGPL-3.0
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2007 PHPExcel, Maarten Balliauw
  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_Style
  23. * @copyright Copyright (c) 2006 - 2007 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/lgpl.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /** PHPExcel_Style_Color */
  28. require_once 'PHPExcel/Style/Color.php';
  29. /** PHPExcel_IComparable */
  30. require_once 'PHPExcel/IComparable.php';
  31. /**
  32. * PHPExcel_Style_Fill
  33. *
  34. * @category PHPExcel
  35. * @package PHPExcel_Style
  36. * @copyright Copyright (c) 2006 - 2007 PHPExcel (http://www.codeplex.com/PHPExcel)
  37. */
  38. class PHPExcel_Style_Fill implements PHPExcel_IComparable
  39. {
  40. /* Fill types */
  41. const FILL_NONE = 'none';
  42. const FILL_SOLID = 'solid';
  43. const FILL_GRADIENT_LINEAR = 'linear';
  44. const FILL_GRADIENT_PATH = 'path';
  45. const FILL_PATTERN_DARKDOWN = 'darkDown';
  46. const FILL_PATTERN_DARKGRAY = 'darkGray';
  47. const FILL_PATTERN_DARKGRID = 'darkGrid';
  48. const FILL_PATTERN_DARKHORIZONTAL = 'darkHorizontal';
  49. const FILL_PATTERN_DARKTRELLIS = 'darkTrellis';
  50. const FILL_PATTERN_DARKUP = 'darkUp';
  51. const FILL_PATTERN_DARKVERTICAL = 'darkVertical';
  52. const FILL_PATTERN_GRAY0625 = 'gray0625';
  53. const FILL_PATTERN_GRAY125 = 'gray125';
  54. const FILL_PATTERN_LIGHTDOWN = 'lightDown';
  55. const FILL_PATTERN_LIGHTGRAY = 'lightGray';
  56. const FILL_PATTERN_LIGHTGRID = 'lightGrid';
  57. const FILL_PATTERN_LIGHTHORIZONTAL = 'lightHorizontal';
  58. const FILL_PATTERN_LIGHTTRELLIS = 'lightTrellis';
  59. const FILL_PATTERN_LIGHTUP = 'lightUp';
  60. const FILL_PATTERN_LIGHTVERTICAL = 'lightVertical';
  61. const FILL_PATTERN_MEDIUMGRAY = 'mediumGray';
  62. /**
  63. * Fill type
  64. *
  65. * @var string
  66. */
  67. private $_fillType;
  68. /**
  69. * Rotation
  70. *
  71. * @var double
  72. */
  73. private $_rotation;
  74. /**
  75. * Start color
  76. *
  77. * @var PHPExcel_Style_Color
  78. */
  79. private $_startColor;
  80. /**
  81. * End color
  82. *
  83. * @var PHPExcel_Style_Color
  84. */
  85. private $_endColor;
  86. /**
  87. * Create a new PHPExcel_Style_Fill
  88. */
  89. public function __construct()
  90. {
  91. // Initialise values
  92. $this->_fillType = PHPExcel_Style_Fill::FILL_NONE;
  93. $this->_rotation = 0;
  94. $this->_startColor = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_WHITE);
  95. $this->_endColor = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK);
  96. }
  97. /**
  98. * Get Fill Type
  99. *
  100. * @return string
  101. */
  102. public function getFillType() {
  103. return $this->_fillType;
  104. }
  105. /**
  106. * Set Fill Type
  107. *
  108. * @param string $pValue PHPExcel_Style_Fill fill type
  109. */
  110. public function setFillType($pValue = PHPExcel_Style_Fill::FILL_NONE) {
  111. $this->_fillType = $pValue;
  112. }
  113. /**
  114. * Get Rotation
  115. *
  116. * @return double
  117. */
  118. public function getRotation() {
  119. return $this->_rotation;
  120. }
  121. /**
  122. * Set Rotation
  123. *
  124. * @param double $pValue
  125. */
  126. public function setRotation($pValue = 0) {
  127. $this->_rotation = $pValue;
  128. }
  129. /**
  130. * Get Start Color
  131. *
  132. * @return PHPExcel_Style_Color
  133. */
  134. public function getStartColor() {
  135. return $this->_startColor;
  136. }
  137. /**
  138. * Set Start Color
  139. *
  140. * @param PHPExcel_Style_Color $pValue
  141. * @throws Exception
  142. */
  143. public function setStartColor($pValue = null) {
  144. if ($pValue instanceof PHPExcel_Style_Color) {
  145. $this->_startColor = $pValue;
  146. } else {
  147. throw new Exception("Invalid PHPExcel_Style_Color passed.");
  148. }
  149. }
  150. /**
  151. * Get End Color
  152. *
  153. * @return PHPExcel_Style_Color
  154. */
  155. public function getEndColor() {
  156. return $this->_endColor;
  157. }
  158. /**
  159. * Set End Color
  160. *
  161. * @param PHPExcel_Style_Color $pValue
  162. * @throws Exception
  163. */
  164. public function setEndColor($pValue = null) {
  165. if ($pValue instanceof PHPExcel_Style_Color) {
  166. $this->_endColor = $pValue;
  167. } else {
  168. throw new Exception("Invalid PHPExcel_Style_Color passed.");
  169. }
  170. }
  171. /**
  172. * Get hash code
  173. *
  174. * @return string Hash code
  175. */
  176. public function getHashCode() {
  177. return md5(
  178. $this->_fillType
  179. . $this->_rotation
  180. . $this->_startColor->getHashCode()
  181. . $this->_endColor->getHashCode()
  182. . __CLASS__
  183. );
  184. }
  185. /**
  186. * Duplicate object
  187. *
  188. * Duplicates the current object, also duplicating referenced objects (deep cloning).
  189. * Standard PHP clone does not copy referenced objects!
  190. *
  191. * @return PHPExcel_Style_Fill
  192. */
  193. public function duplicate() {
  194. return unserialize(serialize($this));
  195. }
  196. }