PHPPowerPoint_Shape
[ class tree: PHPPowerPoint_Shape ] [ index: PHPPowerPoint_Shape ] [ all elements ]

Source for file Shape.php

Documentation is available at Shape.php

  1. <?php
  2. /**
  3.  * PHPPowerPoint
  4.  *
  5.  * Copyright (c) 2009 - 2010 PHPPowerPoint
  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   PHPPowerPoint
  22.  * @package    PHPPowerPoint_Shape
  23.  * @copyright  Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    0.1.0, 2009-04-27
  26.  */
  27.  
  28.  
  29. /** PHPPowerPoint_IComparable */
  30. require_once 'PHPPowerPoint/IComparable.php';
  31.  
  32. /** PHPPowerPoint_Slide */
  33. require_once 'PHPPowerPoint/Slide.php';
  34.  
  35. /** PHPPowerPoint_Style_Fill */
  36. require_once 'PHPPowerPoint/Style/Fill.php';
  37.  
  38. /** PHPPowerPoint_Shape_Shadow */
  39. require_once 'PHPPowerPoint/Shape/Shadow.php';
  40.  
  41.  
  42. /**
  43.  * PHPPowerPoint_Shape
  44.  *
  45.  * @category   PHPPowerPoint
  46.  * @package    PHPPowerPoint_Shape
  47.  * @copyright  Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
  48.  */
  49. abstract class PHPPowerPoint_Shape implements PHPPowerPoint_IComparable
  50. {        
  51.     /**
  52.      * Slide
  53.      *
  54.      * @var PHPPowerPoint_Slide 
  55.      */
  56.     protected $_slide;
  57.     
  58.     /**
  59.      * Offset X
  60.      *
  61.      * @var int 
  62.      */
  63.     protected $_offsetX;
  64.     
  65.     /**
  66.      * Offset Y
  67.      *
  68.      * @var int 
  69.      */
  70.     protected $_offsetY;
  71.     
  72.     /**
  73.      * Width
  74.      *
  75.      * @var int 
  76.      */
  77.     protected $_width;
  78.     
  79.     /**
  80.      * Height
  81.      *
  82.      * @var int 
  83.      */
  84.     protected $_height;
  85.     
  86.     /**
  87.      * Fill
  88.      *
  89.      * @var PHPPowerPoint_Style_Fill 
  90.      */
  91.     private $_fill;
  92.  
  93.     /**
  94.      * Rotation
  95.      *
  96.      * @var int 
  97.      */
  98.     protected $_rotation;
  99.     
  100.     /**
  101.      * Shadow
  102.      *
  103.      * @var PHPPowerPoint_Shape_Shadow 
  104.      */
  105.     protected $_shadow;    
  106.     
  107.     /**
  108.      * Create a new PHPPowerPoint_Shape
  109.      */
  110.     public function __construct()
  111.     {
  112.         // Initialise values
  113.         $this->_slide                = null;
  114.         $this->_offsetX                = 0;
  115.         $this->_offsetY                = 0;
  116.         $this->_width                = 0;
  117.         $this->_height                = 0;
  118.         $this->_rotation            = 0;
  119.         $this->_fill                = new PHPPowerPoint_Style_Fill();
  120.         $this->_shadow                = new PHPPowerPoint_Shape_Shadow();
  121.     }
  122.  
  123.     /**
  124.      * Get Slide
  125.      *
  126.      * @return PHPPowerPoint_Slide 
  127.      */
  128.     public function getSlide({
  129.         return $this->_slide;
  130.     }
  131.     
  132.     /**
  133.      * Set Slide
  134.      *
  135.      * @param     PHPPowerPoint_Slide     $pValue 
  136.      * @param     bool                    $pOverrideOld    If a Slide has already been assigned, overwrite it and remove image from old Slide?
  137.      * @throws     Exception
  138.      */
  139.     public function setSlide(PHPPowerPoint_slide $pValue null$pOverrideOld false{
  140.         if (is_null($this->_slide)) {
  141.             // Add drawing to PHPPowerPoint_Slide
  142.             $this->_slide = $pValue;
  143.             $this->_slide->getShapeCollection()->append($this);
  144.         else {
  145.             if ($pOverrideOld{
  146.                 // Remove drawing from old PHPPowerPoint_Slide
  147.                 $iterator $this->_slide->getShapeCollection()->getIterator();
  148.                     
  149.                 while ($iterator->valid()) {
  150.                     if ($iterator->current()->getHashCode(== $this->getHashCode()) {
  151.                         $this->_slide->getShapeCollection()->offsetUnset$iterator->key() );
  152.                         $this->_slide = null;
  153.                         break;
  154.                     }
  155.                 }
  156.                     
  157.                 // Set new PHPPowerPoint_Slide
  158.                 $this->setSlide($pValue);
  159.             else {
  160.                 throw new Exception("A PHPPowerPoint_Slide has already been assigned. Shapes can only exist on one PHPPowerPoint_Slide.");
  161.             }
  162.         }
  163.     }
  164.  
  165.     /**
  166.      * Get OffsetX
  167.      *
  168.      * @return int 
  169.      */
  170.     public function getOffsetX({
  171.         return $this->_offsetX;
  172.     }
  173.     
  174.     /**
  175.      * Set OffsetX
  176.      *
  177.      * @param int $pValue 
  178.      */
  179.     public function setOffsetX($pValue 0{
  180.         $this->_offsetX = $pValue;
  181.     }
  182.     
  183.     /**
  184.      * Get OffsetY
  185.      *
  186.      * @return int 
  187.      */
  188.     public function getOffsetY({
  189.         return $this->_offsetY;
  190.     }
  191.     
  192.     /**
  193.      * Set OffsetY
  194.      *
  195.      * @param int $pValue 
  196.      */
  197.     public function setOffsetY($pValue 0{
  198.         $this->_offsetY = $pValue;
  199.     }
  200.     
  201.     /**
  202.      * Get Width
  203.      *
  204.      * @return int 
  205.      */
  206.     public function getWidth({
  207.         return $this->_width;
  208.     }
  209.     
  210.     /**
  211.      * Set Width
  212.      *
  213.      * @param int $pValue 
  214.      */
  215.     public function setWidth($pValue 0{
  216.         $this->_width = $pValue;
  217.     }
  218.     
  219.     /**
  220.      * Get Height
  221.      *
  222.      * @return int 
  223.      */
  224.     public function getHeight({
  225.         return $this->_height;
  226.     }
  227.     
  228.     /**
  229.      * Set Height
  230.      *
  231.      * @param int $pValue 
  232.      */
  233.     public function setHeight($pValue 0{
  234.         $this->_height = $pValue;
  235.     }
  236.     
  237.     /**
  238.      * Set width and height with proportional resize
  239.      *
  240.      * @param int $width 
  241.      * @param int $height 
  242.      * @example $objDrawing->setWidthAndHeight(160,120);
  243.      */
  244.     public function setWidthAndHeight($width 0$height 0{
  245.         $this->_width  = $width;
  246.         $this->_height    = $height;
  247.     }
  248.     
  249.     /**
  250.      * Get Rotation
  251.      *
  252.      * @return int 
  253.      */
  254.     public function getRotation({
  255.         return $this->_rotation;
  256.     }
  257.     
  258.     /**
  259.      * Set Rotation
  260.      *
  261.      * @param int $pValue 
  262.      */
  263.     public function setRotation($pValue 0{
  264.         $this->_rotation = $pValue;
  265.     }
  266.     
  267.     /**
  268.      * Get Fill
  269.      *
  270.      * @return PHPPowerPoint_Style_Fill 
  271.      */
  272.     public function getFill({
  273.         return $this->_fill;
  274.     }
  275.     
  276.     /**
  277.      * Get Shadow
  278.      *
  279.      * @return PHPPowerPoint_Shape_Shadow 
  280.      */
  281.     public function getShadow({
  282.         return $this->_shadow;
  283.     }
  284.     
  285.     /**
  286.      * Set Shadow
  287.      *
  288.      * @param     PHPPowerPoint_Shape_Shadow $pValue 
  289.      * @throws     Exception
  290.      */
  291.     public function setShadow(PHPPowerPoint_Shape_Shadow $pValue null{
  292.            $this->_shadow = $pValue;
  293.     }
  294.  
  295.     /**
  296.      * Get hash code
  297.      *
  298.      * @return string    Hash code
  299.      */    
  300.     public function getHashCode({
  301.         return md5(
  302.               $this->_slide->getHashCode()
  303.             . $this->_offsetX
  304.             . $this->_offsetY
  305.             . $this->_width
  306.             . $this->_height
  307.             . $this->_rotation
  308.             . $this->getFill()->getHashCode()
  309.             . $this->_shadow->getHashCode()
  310.             . __CLASS__
  311.         );
  312.     }
  313.     
  314.     /**
  315.      * Hash index
  316.      *
  317.      * @var string 
  318.      */
  319.     private $_hashIndex;
  320.     
  321.     /**
  322.      * Get hash index
  323.      * 
  324.      * Note that this index may vary during script execution! Only reliable moment is
  325.      * while doing a write of a workbook and when changes are not allowed.
  326.      *
  327.      * @return string    Hash index
  328.      */
  329.     public function getHashIndex({
  330.         return $this->_hashIndex;
  331.     }
  332.     
  333.     /**
  334.      * Set hash index
  335.      * 
  336.      * Note that this index may vary during script execution! Only reliable moment is
  337.      * while doing a write of a workbook and when changes are not allowed.
  338.      *
  339.      * @param string    $value    Hash index
  340.      */
  341.     public function setHashIndex($value{
  342.         $this->_hashIndex = $value;
  343.     }
  344.         
  345.     /**
  346.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  347.      */
  348.     public function __clone({
  349.         $vars get_object_vars($this);
  350.         foreach ($vars as $key => $value{
  351.             if (is_object($value)) {
  352.                 $this->$key clone $value;
  353.             else {
  354.                 $this->$key $value;
  355.             }
  356.         }
  357.     }
  358. }

Documentation generated on Sat, 25 Apr 2009 11:38:03 +0200 by phpDocumentor 1.4.1