[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * PHPExcel_Worksheet_BaseDrawing 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_Worksheet 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_Worksheet_BaseDrawing implements PHPExcel_IComparable 29 { 30 /** 31 * Image counter 32 * 33 * @var int 34 */ 35 private static $imageCounter = 0; 36 37 /** 38 * Image index 39 * 40 * @var int 41 */ 42 private $imageIndex = 0; 43 44 /** 45 * Name 46 * 47 * @var string 48 */ 49 protected $name; 50 51 /** 52 * Description 53 * 54 * @var string 55 */ 56 protected $description; 57 58 /** 59 * Worksheet 60 * 61 * @var PHPExcel_Worksheet 62 */ 63 protected $worksheet; 64 65 /** 66 * Coordinates 67 * 68 * @var string 69 */ 70 protected $coordinates; 71 72 /** 73 * Offset X 74 * 75 * @var int 76 */ 77 protected $offsetX; 78 79 /** 80 * Offset Y 81 * 82 * @var int 83 */ 84 protected $offsetY; 85 86 /** 87 * Width 88 * 89 * @var int 90 */ 91 protected $width; 92 93 /** 94 * Height 95 * 96 * @var int 97 */ 98 protected $height; 99 100 /** 101 * Proportional resize 102 * 103 * @var boolean 104 */ 105 protected $resizeProportional; 106 107 /** 108 * Rotation 109 * 110 * @var int 111 */ 112 protected $rotation; 113 114 /** 115 * Shadow 116 * 117 * @var PHPExcel_Worksheet_Drawing_Shadow 118 */ 119 protected $shadow; 120 121 /** 122 * Create a new PHPExcel_Worksheet_BaseDrawing 123 */ 124 public function __construct() 125 { 126 // Initialise values 127 $this->name = ''; 128 $this->description = ''; 129 $this->worksheet = null; 130 $this->coordinates = 'A1'; 131 $this->offsetX = 0; 132 $this->offsetY = 0; 133 $this->width = 0; 134 $this->height = 0; 135 $this->resizeProportional = true; 136 $this->rotation = 0; 137 $this->shadow = new PHPExcel_Worksheet_Drawing_Shadow(); 138 139 // Set image index 140 self::$imageCounter++; 141 $this->imageIndex = self::$imageCounter; 142 } 143 144 /** 145 * Get image index 146 * 147 * @return int 148 */ 149 public function getImageIndex() 150 { 151 return $this->imageIndex; 152 } 153 154 /** 155 * Get Name 156 * 157 * @return string 158 */ 159 public function getName() 160 { 161 return $this->name; 162 } 163 164 /** 165 * Set Name 166 * 167 * @param string $pValue 168 * @return PHPExcel_Worksheet_BaseDrawing 169 */ 170 public function setName($pValue = '') 171 { 172 $this->name = $pValue; 173 return $this; 174 } 175 176 /** 177 * Get Description 178 * 179 * @return string 180 */ 181 public function getDescription() 182 { 183 return $this->description; 184 } 185 186 /** 187 * Set Description 188 * 189 * @param string $pValue 190 * @return PHPExcel_Worksheet_BaseDrawing 191 */ 192 public function setDescription($pValue = '') 193 { 194 $this->description = $pValue; 195 return $this; 196 } 197 198 /** 199 * Get Worksheet 200 * 201 * @return PHPExcel_Worksheet 202 */ 203 public function getWorksheet() 204 { 205 return $this->worksheet; 206 } 207 208 /** 209 * Set Worksheet 210 * 211 * @param PHPExcel_Worksheet $pValue 212 * @param bool $pOverrideOld If a Worksheet has already been assigned, overwrite it and remove image from old Worksheet? 213 * @throws PHPExcel_Exception 214 * @return PHPExcel_Worksheet_BaseDrawing 215 */ 216 public function setWorksheet(PHPExcel_Worksheet $pValue = null, $pOverrideOld = false) 217 { 218 if (is_null($this->worksheet)) { 219 // Add drawing to PHPExcel_Worksheet 220 $this->worksheet = $pValue; 221 $this->worksheet->getCell($this->coordinates); 222 $this->worksheet->getDrawingCollection()->append($this); 223 } else { 224 if ($pOverrideOld) { 225 // Remove drawing from old PHPExcel_Worksheet 226 $iterator = $this->worksheet->getDrawingCollection()->getIterator(); 227 228 while ($iterator->valid()) { 229 if ($iterator->current()->getHashCode() == $this->getHashCode()) { 230 $this->worksheet->getDrawingCollection()->offsetUnset($iterator->key()); 231 $this->worksheet = null; 232 break; 233 } 234 } 235 236 // Set new PHPExcel_Worksheet 237 $this->setWorksheet($pValue); 238 } else { 239 throw new PHPExcel_Exception("A PHPExcel_Worksheet has already been assigned. Drawings can only exist on one PHPExcel_Worksheet."); 240 } 241 } 242 return $this; 243 } 244 245 /** 246 * Get Coordinates 247 * 248 * @return string 249 */ 250 public function getCoordinates() 251 { 252 return $this->coordinates; 253 } 254 255 /** 256 * Set Coordinates 257 * 258 * @param string $pValue 259 * @return PHPExcel_Worksheet_BaseDrawing 260 */ 261 public function setCoordinates($pValue = 'A1') 262 { 263 $this->coordinates = $pValue; 264 return $this; 265 } 266 267 /** 268 * Get OffsetX 269 * 270 * @return int 271 */ 272 public function getOffsetX() 273 { 274 return $this->offsetX; 275 } 276 277 /** 278 * Set OffsetX 279 * 280 * @param int $pValue 281 * @return PHPExcel_Worksheet_BaseDrawing 282 */ 283 public function setOffsetX($pValue = 0) 284 { 285 $this->offsetX = $pValue; 286 return $this; 287 } 288 289 /** 290 * Get OffsetY 291 * 292 * @return int 293 */ 294 public function getOffsetY() 295 { 296 return $this->offsetY; 297 } 298 299 /** 300 * Set OffsetY 301 * 302 * @param int $pValue 303 * @return PHPExcel_Worksheet_BaseDrawing 304 */ 305 public function setOffsetY($pValue = 0) 306 { 307 $this->offsetY = $pValue; 308 return $this; 309 } 310 311 /** 312 * Get Width 313 * 314 * @return int 315 */ 316 public function getWidth() 317 { 318 return $this->width; 319 } 320 321 /** 322 * Set Width 323 * 324 * @param int $pValue 325 * @return PHPExcel_Worksheet_BaseDrawing 326 */ 327 public function setWidth($pValue = 0) 328 { 329 // Resize proportional? 330 if ($this->resizeProportional && $pValue != 0) { 331 $ratio = $this->height / ($this->width != 0 ? $this->width : 1); 332 $this->height = round($ratio * $pValue); 333 } 334 335 // Set width 336 $this->width = $pValue; 337 338 return $this; 339 } 340 341 /** 342 * Get Height 343 * 344 * @return int 345 */ 346 public function getHeight() 347 { 348 return $this->height; 349 } 350 351 /** 352 * Set Height 353 * 354 * @param int $pValue 355 * @return PHPExcel_Worksheet_BaseDrawing 356 */ 357 public function setHeight($pValue = 0) 358 { 359 // Resize proportional? 360 if ($this->resizeProportional && $pValue != 0) { 361 $ratio = $this->width / ($this->height != 0 ? $this->height : 1); 362 $this->width = round($ratio * $pValue); 363 } 364 365 // Set height 366 $this->height = $pValue; 367 368 return $this; 369 } 370 371 /** 372 * Set width and height with proportional resize 373 * Example: 374 * <code> 375 * $objDrawing->setResizeProportional(true); 376 * $objDrawing->setWidthAndHeight(160,120); 377 * </code> 378 * 379 * @author Vincent@luo MSN:kele_100@hotmail.com 380 * @param int $width 381 * @param int $height 382 * @return PHPExcel_Worksheet_BaseDrawing 383 */ 384 public function setWidthAndHeight($width = 0, $height = 0) 385 { 386 $xratio = $width / ($this->width != 0 ? $this->width : 1); 387 $yratio = $height / ($this->height != 0 ? $this->height : 1); 388 if ($this->resizeProportional && !($width == 0 || $height == 0)) { 389 if (($xratio * $this->height) < $height) { 390 $this->height = ceil($xratio * $this->height); 391 $this->width = $width; 392 } else { 393 $this->width = ceil($yratio * $this->width); 394 $this->height = $height; 395 } 396 } else { 397 $this->width = $width; 398 $this->height = $height; 399 } 400 401 return $this; 402 } 403 404 /** 405 * Get ResizeProportional 406 * 407 * @return boolean 408 */ 409 public function getResizeProportional() 410 { 411 return $this->resizeProportional; 412 } 413 414 /** 415 * Set ResizeProportional 416 * 417 * @param boolean $pValue 418 * @return PHPExcel_Worksheet_BaseDrawing 419 */ 420 public function setResizeProportional($pValue = true) 421 { 422 $this->resizeProportional = $pValue; 423 return $this; 424 } 425 426 /** 427 * Get Rotation 428 * 429 * @return int 430 */ 431 public function getRotation() 432 { 433 return $this->rotation; 434 } 435 436 /** 437 * Set Rotation 438 * 439 * @param int $pValue 440 * @return PHPExcel_Worksheet_BaseDrawing 441 */ 442 public function setRotation($pValue = 0) 443 { 444 $this->rotation = $pValue; 445 return $this; 446 } 447 448 /** 449 * Get Shadow 450 * 451 * @return PHPExcel_Worksheet_Drawing_Shadow 452 */ 453 public function getShadow() 454 { 455 return $this->shadow; 456 } 457 458 /** 459 * Set Shadow 460 * 461 * @param PHPExcel_Worksheet_Drawing_Shadow $pValue 462 * @throws PHPExcel_Exception 463 * @return PHPExcel_Worksheet_BaseDrawing 464 */ 465 public function setShadow(PHPExcel_Worksheet_Drawing_Shadow $pValue = null) 466 { 467 $this->shadow = $pValue; 468 return $this; 469 } 470 471 /** 472 * Get hash code 473 * 474 * @return string Hash code 475 */ 476 public function getHashCode() 477 { 478 return md5( 479 $this->name . 480 $this->description . 481 $this->worksheet->getHashCode() . 482 $this->coordinates . 483 $this->offsetX . 484 $this->offsetY . 485 $this->width . 486 $this->height . 487 $this->rotation . 488 $this->shadow->getHashCode() . 489 __CLASS__ 490 ); 491 } 492 493 /** 494 * Implement PHP __clone to create a deep clone, not just a shallow copy. 495 */ 496 public function __clone() 497 { 498 $vars = get_object_vars($this); 499 foreach ($vars as $key => $value) { 500 if (is_object($value)) { 501 $this->$key = clone $value; 502 } else { 503 $this->$key = $value; 504 } 505 } 506 } 507 }
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 |