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

Documentation generated on Mon, 10 Aug 2009 08:06:37 +0200 by phpDocumentor 1.4.1