File Source for Fill.php

PHPExcel_Style

# Source for file Fill.php

Documentation is available at Fill.php

1. <?php
2. /**
3. * PHPExcel
4. *
5. * Copyright (c) 2006 - 2011 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_Style
23. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25. * @version 1.7.6, 2011-02-27
26. */
29. /**
30. * PHPExcel_Style_Fill
31. *
32. * @category PHPExcel
33. * @package PHPExcel_Style
34. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35. */
36. class PHPExcel_Style_Fill implements PHPExcel_IComparable
37. {
38. /* Fill types */
39. const FILL_NONE = 'none';
40. const FILL_SOLID = 'solid';
41. const FILL_GRADIENT_LINEAR = 'linear';
42. const FILL_GRADIENT_PATH = 'path';
43. const FILL_PATTERN_DARKDOWN = 'darkDown';
44. const FILL_PATTERN_DARKGRAY = 'darkGray';
45. const FILL_PATTERN_DARKGRID = 'darkGrid';
46. const FILL_PATTERN_DARKHORIZONTAL = 'darkHorizontal';
47. const FILL_PATTERN_DARKTRELLIS = 'darkTrellis';
48. const FILL_PATTERN_DARKUP = 'darkUp';
49. const FILL_PATTERN_DARKVERTICAL = 'darkVertical';
50. const FILL_PATTERN_GRAY0625 = 'gray0625';
51. const FILL_PATTERN_GRAY125 = 'gray125';
52. const FILL_PATTERN_LIGHTDOWN = 'lightDown';
53. const FILL_PATTERN_LIGHTGRAY = 'lightGray';
54. const FILL_PATTERN_LIGHTGRID = 'lightGrid';
55. const FILL_PATTERN_LIGHTHORIZONTAL = 'lightHorizontal';
56. const FILL_PATTERN_LIGHTTRELLIS = 'lightTrellis';
57. const FILL_PATTERN_LIGHTUP = 'lightUp';
58. const FILL_PATTERN_LIGHTVERTICAL = 'lightVertical';
59. const FILL_PATTERN_MEDIUMGRAY = 'mediumGray';
61. /**
62. * Fill type
63. *
64. * @var string
65. */
66. private $_fillType = PHPExcel_Style_Fill:: FILL_NONE;
68. /**
69. * Rotation
70. *
71. * @var double
72. */
73. private $_rotation = 0;
75. /**
76. * Start color
77. *
78. * @var PHPExcel_Style_Color
79. */
80. private $_startColor;
82. /**
83. * End color
84. *
85. * @var PHPExcel_Style_Color
86. */
87. private $_endColor;
89. /**
90. * Parent Borders
91. *
92. * @var _parentPropertyName string
93. */
94. private $_parentPropertyName;
96. /**
97. * Supervisor?
98. *
99. * @var boolean
100. */
101. private $_isSupervisor;
103. /**
104. * Parent. Only used for supervisor
105. *
106. * @var PHPExcel_Style
107. */
108. private $_parent;
110. /**
111. * Create a new PHPExcel_Style_Fill
112. */
113. public function __construct($isSupervisor = false)
114. {
115. // Supervisor?
116. $this->_isSupervisor = $isSupervisor;
118. // Initialise values
119. $this->_startColor = new PHPExcel_Style_Color( PHPExcel_Style_Color:: COLOR_WHITE, $isSupervisor);
120. $this->_endColor = new PHPExcel_Style_Color( PHPExcel_Style_Color:: COLOR_BLACK, $isSupervisor);
122. // bind parent if we are a supervisor
123. if ($isSupervisor) {
124. $this->_startColor-> bindParent($this, '_startColor');
125. $this->_endColor-> bindParent($this, '_endColor');
126. }
127. }
129. /**
130. * Bind parent. Only used for supervisor
131. *
132. * @param PHPExcel_Style $parent
133. * @return PHPExcel_Style_Fill
134. */
135. public function bindParent($parent)
136. {
137. $this->_parent = $parent;
138. return $this;
139. }
141. /**
142. * Is this a supervisor or a real style component?
143. *
144. * @return boolean
145. */
146. public function getIsSupervisor()
147. {
148. return $this->_isSupervisor;
149. }
151. /**
152. * Get the shared style component for the currently active cell in currently active sheet.
153. * Only used for style supervisor
154. *
155. * @return PHPExcel_Style_Fill
156. */
157. public function getSharedComponent()
158. {
159. return $this->_parent-> getSharedComponent()->getFill();
160. }
162. /**
163. * Get the currently active sheet. Only used for supervisor
164. *
165. * @return PHPExcel_Worksheet
166. */
167. public function getActiveSheet()
168. {
169. return $this->_parent-> getActiveSheet();
170. }
172. /**
173. * Get the currently active cell coordinate in currently active sheet.
174. * Only used for supervisor
175. *
176. * @return string E.g. 'A1'
177. */
178. public function getSelectedCells()
179. {
180. return $this-> getActiveSheet()->getSelectedCells();
181. }
183. /**
184. * Get the currently active cell coordinate in currently active sheet.
185. * Only used for supervisor
186. *
187. * @return string E.g. 'A1'
188. */
189. public function getActiveCell()
190. {
191. return $this-> getActiveSheet()->getActiveCell();
192. }
194. /**
195. * Build style array from subcomponents
196. *
197. * @param array $array
198. * @return array
199. */
200. public function getStyleArray($array)
201. {
202. return array('fill' => $array);
203. }
205. /**
206. * Apply styles from array
207. *
208. * <code>
209. * $objPHPExcel->getActiveSheet()->getStyle('B2')->getFill()->applyFromArray(
210. * array(
211. * 'type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
212. * 'rotation' => 0,
213. * 'startcolor' => array(
214. * 'rgb' => '000000'
215. * ),
216. * 'endcolor' => array(
217. * 'argb' => 'FFFFFFFF'
218. * )
219. * )
220. * );
221. * </code>
222. *
223. * @param array $pStyles Array containing style information
224. * @throws Exception
225. * @return PHPExcel_Style_Fill
226. */
227. public function applyFromArray($pStyles = null) {
228. if ( is_array($pStyles)) {
229. if ($this->_isSupervisor) {
230. $this-> getActiveSheet()->getStyle($this-> getSelectedCells())->applyFromArray($this-> getStyleArray($pStyles));
231. } else {
232. if ( array_key_exists('type', $pStyles)) {
233. $this-> setFillType($pStyles['type']);
234. }
235. if ( array_key_exists('rotation', $pStyles)) {
236. $this-> setRotation($pStyles['rotation']);
237. }
238. if ( array_key_exists('startcolor', $pStyles)) {
239. $this-> getStartColor()->applyFromArray($pStyles['startcolor']);
240. }
241. if ( array_key_exists('endcolor', $pStyles)) {
242. $this-> getEndColor()->applyFromArray($pStyles['endcolor']);
243. }
244. if ( array_key_exists('color', $pStyles)) {
245. $this-> getStartColor()->applyFromArray($pStyles['color']);
246. }
247. }
248. } else {
249. throw new Exception("Invalid style array passed.");
250. }
251. return $this;
252. }
254. /**
255. * Get Fill Type
256. *
257. * @return string
258. */
259. public function getFillType() {
260. if ($this->_isSupervisor) {
261. return $this-> getSharedComponent()->getFillType();
262. }
263. return $this->_fillType;
264. }
266. /**
267. * Set Fill Type
268. *
269. * @param string $pValue PHPExcel_Style_Fill fill type
270. * @return PHPExcel_Style_Fill
271. */
272. public function setFillType($pValue = PHPExcel_Style_Fill:: FILL_NONE) {
273. if ($this->_isSupervisor) {
274. $styleArray = $this-> getStyleArray(array('type' => $pValue));
275. $this-> getActiveSheet()->getStyle($this-> getSelectedCells())->applyFromArray($styleArray);
276. } else {
277. $this->_fillType = $pValue;
278. }
279. return $this;
280. }
282. /**
283. * Get Rotation
284. *
285. * @return double
286. */
287. public function getRotation() {
288. if ($this->_isSupervisor) {
289. return $this-> getSharedComponent()->getRotation();
290. }
291. return $this->_rotation;
292. }
294. /**
295. * Set Rotation
296. *
297. * @param double $pValue
298. * @return PHPExcel_Style_Fill
299. */
300. public function setRotation($pValue = 0) {
301. if ($this->_isSupervisor) {
302. $styleArray = $this-> getStyleArray(array('rotation' => $pValue));
303. $this-> getActiveSheet()->getStyle($this-> getSelectedCells())->applyFromArray($styleArray);
304. } else {
305. $this->_rotation = $pValue;
306. }
307. return $this;
308. }
310. /**
311. * Get Start Color
312. *
313. * @return PHPExcel_Style_Color
314. */
315. public function getStartColor() {
316. return $this->_startColor;
317. }
319. /**
320. * Set Start Color
321. *
322. * @param PHPExcel_Style_Color $pValue
323. * @throws Exception
324. * @return PHPExcel_Style_Fill
325. */
326. public function setStartColor(PHPExcel_Style_Color $pValue = null) {
327. // make sure parameter is a real color and not a supervisor
328. $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue;
330. if ($this->_isSupervisor) {
331. $styleArray = $this-> getStartColor()->getStyleArray(array('argb' => $color->getARGB()));
332. $this-> getActiveSheet()->getStyle($this-> getSelectedCells())->applyFromArray($styleArray);
333. } else {
334. $this->_startColor = $color;
335. }
336. return $this;
337. }
339. /**
340. * Get End Color
341. *
342. * @return PHPExcel_Style_Color
343. */
344. public function getEndColor() {
345. return $this->_endColor;
346. }
348. /**
349. * Set End Color
350. *
351. * @param PHPExcel_Style_Color $pValue
352. * @throws Exception
353. * @return PHPExcel_Style_Fill
354. */
355. public function setEndColor(PHPExcel_Style_Color $pValue = null) {
356. // make sure parameter is a real color and not a supervisor
357. $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue;
359. if ($this->_isSupervisor) {
360. $styleArray = $this-> getEndColor()->getStyleArray(array('argb' => $color->getARGB()));
361. $this-> getActiveSheet()->getStyle($this-> getSelectedCells())->applyFromArray($styleArray);
362. } else {
363. $this->_endColor = $color;
364. }
365. return $this;
366. }
368. /**
369. * Get hash code
370. *
371. * @return string Hash code
372. */
373. public function getHashCode() {
374. if ($this->_isSupervisor) {
375. return $this-> getSharedComponent()->getHashCode();
376. }
377. return md5(
378. $this-> getFillType()
379. . $this-> getRotation()
380. . $this-> getStartColor()->getHashCode()
381. . $this-> getEndColor()->getHashCode()
382. . __CLASS__
383. );
384. }
386. /**
387. * Implement PHP __clone to create a deep clone, not just a shallow copy.
388. */
389. public function __clone() {
390. $vars = get_object_vars($this);
391. foreach ($vars as $key => $value) {
392. if (( is_object($value)) && ($key != '_parent')) {
393. $this->$key = clone $value;
394. } else {
395. $this->$key = $value;
396. }
397. }
398. }
399. }

Documentation generated on Sun, 27 Feb 2011 16:31:32 -0800 by phpDocumentor 1.4.3