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

Source for file MemoryDrawing.php

Documentation is available at MemoryDrawing.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_Shape */
  33. require_once 'PHPPowerPoint/Shape.php';
  34.  
  35. /** PHPPowerPoint_Shape_BaseDrawing */
  36. require_once 'PHPPowerPoint/Shape/BaseDrawing.php';
  37.  
  38.  
  39. /**
  40.  * PHPPowerPoint_Shape_MemoryDrawing
  41.  *
  42.  * @category   PHPPowerPoint
  43.  * @package    PHPPowerPoint_Shape
  44.  * @copyright  Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
  45.  */
  46. {    
  47.     /* Rendering functions */
  48.     const RENDERING_DEFAULT                    = 'imagepng';
  49.     const RENDERING_PNG                        = 'imagepng';
  50.     const RENDERING_GIF                        = 'imagegif';
  51.     const RENDERING_JPEG                    = 'imagejpeg';
  52.     
  53.     /* MIME types */
  54.     const MIMETYPE_DEFAULT                    = 'image/png';
  55.     const MIMETYPE_PNG                        = 'image/png';
  56.     const MIMETYPE_GIF                        = 'image/gif';
  57.     const MIMETYPE_JPEG                        = 'image/jpeg';
  58.     
  59.     /**
  60.      * Image resource
  61.      *
  62.      * @var resource 
  63.      */
  64.     private $_imageResource;
  65.     
  66.     /**
  67.      * Rendering function
  68.      *
  69.      * @var string 
  70.      */
  71.     private $_renderingFunction;
  72.     
  73.     /**
  74.      * Mime type
  75.      *
  76.      * @var string 
  77.      */
  78.     private $_mimeType;
  79.     
  80.     /**
  81.      * Unique name
  82.      *
  83.      * @var string 
  84.      */
  85.     private $_uniqueName;
  86.     
  87.     /**
  88.      * Create a new PHPPowerPoint_Slide_MemoryDrawing
  89.      */
  90.     public function __construct()
  91.     {
  92.         // Initialise values
  93.         $this->_imageResource        = null;
  94.         $this->_renderingFunction     = self::RENDERING_DEFAULT;
  95.         $this->_mimeType            = self::MIMETYPE_DEFAULT;
  96.         $this->_uniqueName            = md5(rand(09999)time(rand(09999));
  97.         
  98.         // Initialize parent
  99.         parent::__construct();
  100.     }
  101.     
  102.     /**
  103.      * Get image resource
  104.      *
  105.      * @return resource 
  106.      */
  107.     public function getImageResource({
  108.         return $this->_imageResource;
  109.     }
  110.     
  111.     /**
  112.      * Set image resource
  113.      *
  114.      * @param    $value resource
  115.      */
  116.     public function setImageResource($value null{
  117.         $this->_imageResource = $value;
  118.         
  119.         if (!is_null($this->_imageResource)) {
  120.             // Get width/height
  121.             $this->_width    = imagesx($this->_imageResource);
  122.             $this->_height    = imagesy($this->_imageResource);
  123.         }
  124.     }
  125.     
  126.     /**
  127.      * Get rendering function
  128.      *
  129.      * @return string 
  130.      */
  131.     public function getRenderingFunction({
  132.         return $this->_renderingFunction;
  133.     }
  134.     
  135.     /**
  136.      * Set rendering function
  137.      *
  138.      * @param string $value 
  139.      */
  140.     public function setRenderingFunction($value PHPPowerPoint_Slide_MemoryDrawing::RENDERING_DEFAULT{
  141.         $this->_renderingFunction = $value;
  142.     }
  143.     
  144.     /**
  145.      * Get mime type
  146.      *
  147.      * @return string 
  148.      */
  149.     public function getMimeType({
  150.         return $this->_mimeType;
  151.     }
  152.     
  153.     /**
  154.      * Set mime type
  155.      *
  156.      * @param string $value 
  157.      */
  158.     public function setMimeType($value PHPPowerPoint_Slide_MemoryDrawing::MIMETYPE_DEFAULT{
  159.         $this->_mimeType = $value;
  160.     }
  161.     
  162.     /**
  163.      * Get indexed filename (using image index)
  164.      *
  165.      * @return string 
  166.      */
  167.     public function getIndexedFilename({
  168.         $extension     strtolower($this->getMimeType());
  169.         $extension     explode('/'$extension);
  170.         $extension     $extension[1];
  171.                     
  172.         return $this->_uniqueName . $this->getImageIndex('.' $extension;
  173.     }
  174.  
  175.     /**
  176.      * Get hash code
  177.      *
  178.      * @return string    Hash code
  179.      */    
  180.     public function getHashCode({
  181.         return md5(
  182.               $this->_renderingFunction
  183.             . $this->_mimeType
  184.             . $this->_uniqueName
  185.             . parent::getHashCode()
  186.             . __CLASS__
  187.         );
  188.     }
  189.     
  190.     /**
  191.      * Hash index
  192.      *
  193.      * @var string 
  194.      */
  195.     private $_hashIndex;
  196.     
  197.     /**
  198.      * Get hash index
  199.      * 
  200.      * Note that this index may vary during script execution! Only reliable moment is
  201.      * while doing a write of a workbook and when changes are not allowed.
  202.      *
  203.      * @return string    Hash index
  204.      */
  205.     public function getHashIndex({
  206.         return $this->_hashIndex;
  207.     }
  208.     
  209.     /**
  210.      * Set hash index
  211.      * 
  212.      * Note that this index may vary during script execution! Only reliable moment is
  213.      * while doing a write of a workbook and when changes are not allowed.
  214.      *
  215.      * @param string    $value    Hash index
  216.      */
  217.     public function setHashIndex($value{
  218.         $this->_hashIndex = $value;
  219.     }
  220.         
  221.     /**
  222.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  223.      */
  224.     public function __clone({
  225.         $vars get_object_vars($this);
  226.         foreach ($vars as $key => $value{
  227.             if (is_object($value)) {
  228.                 $this->$key clone $value;
  229.             else {
  230.                 $this->$key $value;
  231.             }
  232.         }
  233.     }
  234. }

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