web/Zend/Pdf/Canvas.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Pdf
       
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    19  * @version    $Id: Style.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    20  */
       
    21 
       
    22 require_once 'Zend/Pdf/Canvas/Abstract.php';
       
    23 
       
    24 /**
       
    25  * Canvas is an abstract rectangle drawing area which can be dropped into
       
    26  * page object at specified place.
       
    27  *
       
    28  * @package    Zend_Pdf
       
    29  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    30  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    31  */
       
    32 class Zend_Pdf_Canvas extends Zend_Pdf_Canvas_Abstract
       
    33 {
       
    34     /**
       
    35      * Canvas procedure sets.
       
    36      *
       
    37      * Allowed values: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'.
       
    38      *
       
    39      * @var array
       
    40      */
       
    41     protected $_procSet = array();
       
    42 
       
    43     /**
       
    44      * Canvas width expressed in default user space units (1/72 inch)
       
    45      *
       
    46      * @var float
       
    47      */
       
    48     protected $_width;
       
    49 
       
    50     /**
       
    51      * Canvas height expressed in default user space units (1/72 inch)
       
    52      *
       
    53      * @var float
       
    54      */
       
    55     protected $_height;
       
    56 
       
    57     protected $_resources = array('Font'      => array(),
       
    58                                   'XObject'   => array(),
       
    59                                   'ExtGState' => array());
       
    60 
       
    61     /**
       
    62      * Object constructor
       
    63      *
       
    64      * @param float $width
       
    65      * @param float $height
       
    66      */
       
    67     public function __construct($width, $height)
       
    68     {
       
    69         $this->_width  = $width;
       
    70         $this->_height = $height;
       
    71     }
       
    72 
       
    73     /**
       
    74      * Add procedure set to the canvas description
       
    75      *
       
    76      * @param string $procSetName
       
    77      */
       
    78     protected function _addProcSet($procSetName)
       
    79     {
       
    80         $this->_procset[$procSetName] = 1;
       
    81     }
       
    82 
       
    83     /**
       
    84      * Attach resource to the canvas
       
    85      *
       
    86      * Method returns a name of the resource which can be used
       
    87      * as a resource reference within drawing instructions stream
       
    88      * Allowed types: 'ExtGState', 'ColorSpace', 'Pattern', 'Shading',
       
    89      * 'XObject', 'Font', 'Properties'
       
    90      *
       
    91      * @param string $type
       
    92      * @param Zend_Pdf_Resource $resource
       
    93      * @return string
       
    94      */
       
    95     protected function _attachResource($type, Zend_Pdf_Resource $resource)
       
    96     {
       
    97         // Check, that resource is already attached to resource set.
       
    98         $resObject = $resource->getResource();
       
    99         foreach ($this->_resources[$type] as $resName => $collectedResObject) {
       
   100             if ($collectedResObject === $resObject) {
       
   101                 return $resName;
       
   102             }
       
   103         }
       
   104 
       
   105         $idCounter = 1;
       
   106         do {
       
   107             $newResName = $type[0] . $idCounter++;
       
   108         } while (isset($this->_resources[$type][$newResName]));
       
   109 
       
   110         $this->_resources[$type][$newResName] = $resObject;
       
   111 
       
   112         return $newResName;
       
   113     }
       
   114 
       
   115     /**
       
   116      * Returns dictionaries of used resources.
       
   117      *
       
   118      * Used for canvas implementations interoperability
       
   119      *
       
   120      * Structure of the returned array:
       
   121      * array(
       
   122      *   <resTypeName> => array(
       
   123      *                      <resName> => <Zend_Pdf_Resource object>,
       
   124      *                      <resName> => <Zend_Pdf_Resource object>,
       
   125      *                      <resName> => <Zend_Pdf_Resource object>,
       
   126      *                      ...
       
   127      *                    ),
       
   128      *   <resTypeName> => array(
       
   129      *                      <resName> => <Zend_Pdf_Resource object>,
       
   130      *                      <resName> => <Zend_Pdf_Resource object>,
       
   131      *                      <resName> => <Zend_Pdf_Resource object>,
       
   132      *                      ...
       
   133      *                    ),
       
   134      *   ...
       
   135      *   'ProcSet' => array()
       
   136      * )
       
   137      *
       
   138      * where ProcSet array is a list of used procedure sets names (strings).
       
   139      * Allowed procedure set names: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'
       
   140      *
       
   141      * @internal
       
   142      * @return array
       
   143      */
       
   144     public function getResources()
       
   145     {
       
   146         $this->_resources['ProcSet'] = array_keys($this->_procSet);
       
   147         return $this->_resources;
       
   148     }
       
   149 
       
   150     /**
       
   151      * Get drawing instructions stream
       
   152      *
       
   153      * It has to be returned as a PDF stream object to make it reusable.
       
   154      *
       
   155      * @internal
       
   156      * @returns Zend_Pdf_Resource_ContentStream
       
   157      */
       
   158     public function getContents()
       
   159     {
       
   160         /** @todo implementation */
       
   161     }
       
   162 
       
   163     /**
       
   164      * Return the height of this page in points.
       
   165      *
       
   166      * @return float
       
   167      */
       
   168     public function getHeight()
       
   169     {
       
   170         return $this->_height;
       
   171     }
       
   172 
       
   173     /**
       
   174      * Return the width of this page in points.
       
   175      *
       
   176      * @return float
       
   177      */
       
   178     public function getWidth()
       
   179     {
       
   180         return $this->_width;
       
   181     }
       
   182 }