ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
BaseDrawing.php
Go to the documentation of this file.
1 <?php
30 if (!defined('PHPEXCEL_ROOT')) {
34  define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35 }
36 
38 require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
39 
41 require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
42 
44 require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet/Drawing/Shadow.php';
45 
54 {
60  private static $_imageCounter = 0;
61 
67  private $_imageIndex = 0;
68 
74  protected $_name;
75 
81  protected $_description;
82 
88  protected $_worksheet;
89 
95  protected $_coordinates;
96 
102  protected $_offsetX;
103 
109  protected $_offsetY;
110 
116  protected $_width;
117 
123  protected $_height;
124 
131 
137  protected $_rotation;
138 
144  protected $_shadow;
145 
149  public function __construct()
150  {
151  // Initialise values
152  $this->_name = '';
153  $this->_description = '';
154  $this->_worksheet = null;
155  $this->_coordinates = 'A1';
156  $this->_offsetX = 0;
157  $this->_offsetY = 0;
158  $this->_width = 0;
159  $this->_height = 0;
160  $this->_resizeProportional = true;
161  $this->_rotation = 0;
162  $this->_shadow = new PHPExcel_Worksheet_Drawing_Shadow();
163 
164  // Set image index
165  self::$_imageCounter++;
166  $this->_imageIndex = self::$_imageCounter;
167  }
168 
174  public function getImageIndex() {
175  return $this->_imageIndex;
176  }
177 
183  public function getName() {
184  return $this->_name;
185  }
186 
193  public function setName($pValue = '') {
194  $this->_name = $pValue;
195  return $this;
196  }
197 
203  public function getDescription() {
204  return $this->_description;
205  }
206 
213  public function setDescription($pValue = '') {
214  $this->_description = $pValue;
215  return $this;
216  }
217 
223  public function getWorksheet() {
224  return $this->_worksheet;
225  }
226 
235  public function setWorksheet(PHPExcel_Worksheet $pValue = null, $pOverrideOld = false) {
236  if (is_null($this->_worksheet)) {
237  // Add drawing to PHPExcel_Worksheet
238  $this->_worksheet = $pValue;
239  $this->_worksheet->getCell($this->_coordinates);
240  $this->_worksheet->getDrawingCollection()->append($this);
241  } else {
242  if ($pOverrideOld) {
243  // Remove drawing from old PHPExcel_Worksheet
244  $iterator = $this->_worksheet->getDrawingCollection()->getIterator();
245 
246  while ($iterator->valid()) {
247  if ($iterator->current()->getHashCode() == $this->getHashCode()) {
248  $this->_worksheet->getDrawingCollection()->offsetUnset( $iterator->key() );
249  $this->_worksheet = null;
250  break;
251  }
252  }
253 
254  // Set new PHPExcel_Worksheet
255  $this->setWorksheet($pValue);
256  } else {
257  throw new Exception("A PHPExcel_Worksheet has already been assigned. Drawings can only exist on one PHPExcel_Worksheet.");
258  }
259  }
260  return $this;
261  }
262 
268  public function getCoordinates() {
269  return $this->_coordinates;
270  }
271 
278  public function setCoordinates($pValue = 'A1') {
279  $this->_coordinates = $pValue;
280  return $this;
281  }
282 
288  public function getOffsetX() {
289  return $this->_offsetX;
290  }
291 
298  public function setOffsetX($pValue = 0) {
299  $this->_offsetX = $pValue;
300  return $this;
301  }
302 
308  public function getOffsetY() {
309  return $this->_offsetY;
310  }
311 
318  public function setOffsetY($pValue = 0) {
319  $this->_offsetY = $pValue;
320  return $this;
321  }
322 
328  public function getWidth() {
329  return $this->_width;
330  }
331 
338  public function setWidth($pValue = 0) {
339  // Resize proportional?
340  if ($this->_resizeProportional && $pValue != 0) {
341  $ratio = $this->_height / $this->_width;
342  $this->_height = round($ratio * $pValue);
343  }
344 
345  // Set width
346  $this->_width = $pValue;
347 
348  return $this;
349  }
350 
356  public function getHeight() {
357  return $this->_height;
358  }
359 
366  public function setHeight($pValue = 0) {
367  // Resize proportional?
368  if ($this->_resizeProportional && $pValue != 0) {
369  $ratio = $this->_width / $this->_height;
370  $this->_width = round($ratio * $pValue);
371  }
372 
373  // Set height
374  $this->_height = $pValue;
375 
376  return $this;
377  }
378 
392  public function setWidthAndHeight($width = 0, $height = 0) {
393  $xratio = $width / $this->_width;
394  $yratio = $height / $this->_height;
395  if ($this->_resizeProportional && !($width == 0 || $height == 0)) {
396  if (($xratio * $this->_height) < $height) {
397  $this->_height = ceil($xratio * $this->_height);
398  $this->_width = $width;
399  } else {
400  $this->_width = ceil($yratio * $this->_width);
401  $this->_height = $height;
402  }
403  }
404  return $this;
405  }
406 
412  public function getResizeProportional() {
414  }
415 
422  public function setResizeProportional($pValue = true) {
423  $this->_resizeProportional = $pValue;
424  return $this;
425  }
426 
432  public function getRotation() {
433  return $this->_rotation;
434  }
435 
442  public function setRotation($pValue = 0) {
443  $this->_rotation = $pValue;
444  return $this;
445  }
446 
452  public function getShadow() {
453  return $this->_shadow;
454  }
455 
463  public function setShadow(PHPExcel_Worksheet_Drawing_Shadow $pValue = null) {
464  $this->_shadow = $pValue;
465  return $this;
466  }
467 
473  public function getHashCode() {
474  return md5(
475  $this->_name
476  . $this->_description
477  . $this->_worksheet->getHashCode()
478  . $this->_coordinates
479  . $this->_offsetX
480  . $this->_offsetY
481  . $this->_width
482  . $this->_height
483  . $this->_rotation
484  . $this->_shadow->getHashCode()
485  . __CLASS__
486  );
487  }
488 
494  private $_hashIndex;
495 
504  public function getHashIndex() {
505  return $this->_hashIndex;
506  }
507 
516  public function setHashIndex($value) {
517  $this->_hashIndex = $value;
518  }
519 
523  public function __clone() {
524  $vars = get_object_vars($this);
525  foreach ($vars as $key => $value) {
526  if (is_object($value)) {
527  $this->$key = clone $value;
528  } else {
529  $this->$key = $value;
530  }
531  }
532  }
533 }