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

Source for file MemoryDrawing.php

Documentation is available at MemoryDrawing.php

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

Documentation generated on Wed, 22 Apr 2009 09:00:42 +0200 by phpDocumentor 1.4.1