[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * PHPExcel_Style_Fill 5 * 6 * Copyright (c) 2006 - 2015 PHPExcel 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 * 22 * @category PHPExcel 23 * @package PHPExcel_Style 24 * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) 25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL 26 * @version ##VERSION##, ##DATE## 27 */ 28 class PHPExcel_Style_Fill extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable 29 { 30 /* Fill types */ 31 const FILL_NONE = 'none'; 32 const FILL_SOLID = 'solid'; 33 const FILL_GRADIENT_LINEAR = 'linear'; 34 const FILL_GRADIENT_PATH = 'path'; 35 const FILL_PATTERN_DARKDOWN = 'darkDown'; 36 const FILL_PATTERN_DARKGRAY = 'darkGray'; 37 const FILL_PATTERN_DARKGRID = 'darkGrid'; 38 const FILL_PATTERN_DARKHORIZONTAL = 'darkHorizontal'; 39 const FILL_PATTERN_DARKTRELLIS = 'darkTrellis'; 40 const FILL_PATTERN_DARKUP = 'darkUp'; 41 const FILL_PATTERN_DARKVERTICAL = 'darkVertical'; 42 const FILL_PATTERN_GRAY0625 = 'gray0625'; 43 const FILL_PATTERN_GRAY125 = 'gray125'; 44 const FILL_PATTERN_LIGHTDOWN = 'lightDown'; 45 const FILL_PATTERN_LIGHTGRAY = 'lightGray'; 46 const FILL_PATTERN_LIGHTGRID = 'lightGrid'; 47 const FILL_PATTERN_LIGHTHORIZONTAL = 'lightHorizontal'; 48 const FILL_PATTERN_LIGHTTRELLIS = 'lightTrellis'; 49 const FILL_PATTERN_LIGHTUP = 'lightUp'; 50 const FILL_PATTERN_LIGHTVERTICAL = 'lightVertical'; 51 const FILL_PATTERN_MEDIUMGRAY = 'mediumGray'; 52 53 /** 54 * Fill type 55 * 56 * @var string 57 */ 58 protected $fillType = PHPExcel_Style_Fill::FILL_NONE; 59 60 /** 61 * Rotation 62 * 63 * @var double 64 */ 65 protected $rotation = 0; 66 67 /** 68 * Start color 69 * 70 * @var PHPExcel_Style_Color 71 */ 72 protected $startColor; 73 74 /** 75 * End color 76 * 77 * @var PHPExcel_Style_Color 78 */ 79 protected $endColor; 80 81 /** 82 * Create a new PHPExcel_Style_Fill 83 * 84 * @param boolean $isSupervisor Flag indicating if this is a supervisor or not 85 * Leave this value at default unless you understand exactly what 86 * its ramifications are 87 * @param boolean $isConditional Flag indicating if this is a conditional style or not 88 * Leave this value at default unless you understand exactly what 89 * its ramifications are 90 */ 91 public function __construct($isSupervisor = false, $isConditional = false) 92 { 93 // Supervisor? 94 parent::__construct($isSupervisor); 95 96 // Initialise values 97 if ($isConditional) { 98 $this->fillType = null; 99 } 100 $this->startColor = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_WHITE, $isSupervisor, $isConditional); 101 $this->endColor = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor, $isConditional); 102 103 // bind parent if we are a supervisor 104 if ($isSupervisor) { 105 $this->startColor->bindParent($this, 'startColor'); 106 $this->endColor->bindParent($this, 'endColor'); 107 } 108 } 109 110 /** 111 * Get the shared style component for the currently active cell in currently active sheet. 112 * Only used for style supervisor 113 * 114 * @return PHPExcel_Style_Fill 115 */ 116 public function getSharedComponent() 117 { 118 return $this->parent->getSharedComponent()->getFill(); 119 } 120 121 /** 122 * Build style array from subcomponents 123 * 124 * @param array $array 125 * @return array 126 */ 127 public function getStyleArray($array) 128 { 129 return array('fill' => $array); 130 } 131 132 /** 133 * Apply styles from array 134 * 135 * <code> 136 * $objPHPExcel->getActiveSheet()->getStyle('B2')->getFill()->applyFromArray( 137 * array( 138 * 'type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR, 139 * 'rotation' => 0, 140 * 'startcolor' => array( 141 * 'rgb' => '000000' 142 * ), 143 * 'endcolor' => array( 144 * 'argb' => 'FFFFFFFF' 145 * ) 146 * ) 147 * ); 148 * </code> 149 * 150 * @param array $pStyles Array containing style information 151 * @throws PHPExcel_Exception 152 * @return PHPExcel_Style_Fill 153 */ 154 public function applyFromArray($pStyles = null) 155 { 156 if (is_array($pStyles)) { 157 if ($this->isSupervisor) { 158 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); 159 } else { 160 if (array_key_exists('type', $pStyles)) { 161 $this->setFillType($pStyles['type']); 162 } 163 if (array_key_exists('rotation', $pStyles)) { 164 $this->setRotation($pStyles['rotation']); 165 } 166 if (array_key_exists('startcolor', $pStyles)) { 167 $this->getStartColor()->applyFromArray($pStyles['startcolor']); 168 } 169 if (array_key_exists('endcolor', $pStyles)) { 170 $this->getEndColor()->applyFromArray($pStyles['endcolor']); 171 } 172 if (array_key_exists('color', $pStyles)) { 173 $this->getStartColor()->applyFromArray($pStyles['color']); 174 } 175 } 176 } else { 177 throw new PHPExcel_Exception("Invalid style array passed."); 178 } 179 return $this; 180 } 181 182 /** 183 * Get Fill Type 184 * 185 * @return string 186 */ 187 public function getFillType() 188 { 189 if ($this->isSupervisor) { 190 return $this->getSharedComponent()->getFillType(); 191 } 192 return $this->fillType; 193 } 194 195 /** 196 * Set Fill Type 197 * 198 * @param string $pValue PHPExcel_Style_Fill fill type 199 * @return PHPExcel_Style_Fill 200 */ 201 public function setFillType($pValue = PHPExcel_Style_Fill::FILL_NONE) 202 { 203 if ($this->isSupervisor) { 204 $styleArray = $this->getStyleArray(array('type' => $pValue)); 205 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); 206 } else { 207 $this->fillType = $pValue; 208 } 209 return $this; 210 } 211 212 /** 213 * Get Rotation 214 * 215 * @return double 216 */ 217 public function getRotation() 218 { 219 if ($this->isSupervisor) { 220 return $this->getSharedComponent()->getRotation(); 221 } 222 return $this->rotation; 223 } 224 225 /** 226 * Set Rotation 227 * 228 * @param double $pValue 229 * @return PHPExcel_Style_Fill 230 */ 231 public function setRotation($pValue = 0) 232 { 233 if ($this->isSupervisor) { 234 $styleArray = $this->getStyleArray(array('rotation' => $pValue)); 235 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); 236 } else { 237 $this->rotation = $pValue; 238 } 239 return $this; 240 } 241 242 /** 243 * Get Start Color 244 * 245 * @return PHPExcel_Style_Color 246 */ 247 public function getStartColor() 248 { 249 return $this->startColor; 250 } 251 252 /** 253 * Set Start Color 254 * 255 * @param PHPExcel_Style_Color $pValue 256 * @throws PHPExcel_Exception 257 * @return PHPExcel_Style_Fill 258 */ 259 public function setStartColor(PHPExcel_Style_Color $pValue = null) 260 { 261 // make sure parameter is a real color and not a supervisor 262 $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue; 263 264 if ($this->isSupervisor) { 265 $styleArray = $this->getStartColor()->getStyleArray(array('argb' => $color->getARGB())); 266 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); 267 } else { 268 $this->startColor = $color; 269 } 270 return $this; 271 } 272 273 /** 274 * Get End Color 275 * 276 * @return PHPExcel_Style_Color 277 */ 278 public function getEndColor() 279 { 280 return $this->endColor; 281 } 282 283 /** 284 * Set End Color 285 * 286 * @param PHPExcel_Style_Color $pValue 287 * @throws PHPExcel_Exception 288 * @return PHPExcel_Style_Fill 289 */ 290 public function setEndColor(PHPExcel_Style_Color $pValue = null) 291 { 292 // make sure parameter is a real color and not a supervisor 293 $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue; 294 295 if ($this->isSupervisor) { 296 $styleArray = $this->getEndColor()->getStyleArray(array('argb' => $color->getARGB())); 297 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); 298 } else { 299 $this->endColor = $color; 300 } 301 return $this; 302 } 303 304 /** 305 * Get hash code 306 * 307 * @return string Hash code 308 */ 309 public function getHashCode() 310 { 311 if ($this->isSupervisor) { 312 return $this->getSharedComponent()->getHashCode(); 313 } 314 return md5( 315 $this->getFillType() . 316 $this->getRotation() . 317 $this->getStartColor()->getHashCode() . 318 $this->getEndColor()->getHashCode() . 319 __CLASS__ 320 ); 321 } 322 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |