File indexing completed on 2024-05-12 06:02:53

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Pdf
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id: Style.php 20096 2010-01-06 02:05:09Z bkarwin $
0020  */
0021 
0022 // require_once 'Zend/Pdf/Canvas/Abstract.php';
0023 
0024 /**
0025  * Canvas is an abstract rectangle drawing area which can be dropped into
0026  * page object at specified place.
0027  *
0028  * @package    Zend_Pdf
0029  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0030  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0031  */
0032 class Zend_Pdf_Canvas extends Zend_Pdf_Canvas_Abstract
0033 {
0034     /**
0035      * Canvas procedure sets.
0036      *
0037      * Allowed values: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'.
0038      *
0039      * @var array
0040      */
0041     protected $_procSet = array();
0042 
0043     /**
0044      * Canvas width expressed in default user space units (1/72 inch)
0045      *
0046      * @var float
0047      */
0048     protected $_width;
0049 
0050     /**
0051      * Canvas height expressed in default user space units (1/72 inch)
0052      *
0053      * @var float
0054      */
0055     protected $_height;
0056 
0057     protected $_resources = array('Font'      => array(),
0058                                   'XObject'   => array(),
0059                                   'ExtGState' => array());
0060 
0061     /**
0062      * Object constructor
0063      *
0064      * @param float $width
0065      * @param float $height
0066      */
0067     public function __construct($width, $height)
0068     {
0069         $this->_width  = $width;
0070         $this->_height = $height;
0071     }
0072 
0073     /**
0074      * Add procedure set to the canvas description
0075      *
0076      * @param string $procSetName
0077      */
0078     protected function _addProcSet($procSetName)
0079     {
0080         $this->_procset[$procSetName] = 1;
0081     }
0082 
0083     /**
0084      * Attach resource to the canvas
0085      *
0086      * Method returns a name of the resource which can be used
0087      * as a resource reference within drawing instructions stream
0088      * Allowed types: 'ExtGState', 'ColorSpace', 'Pattern', 'Shading',
0089      * 'XObject', 'Font', 'Properties'
0090      *
0091      * @param string $type
0092      * @param Zend_Pdf_Resource $resource
0093      * @return string
0094      */
0095     protected function _attachResource($type, Zend_Pdf_Resource $resource)
0096     {
0097         // Check, that resource is already attached to resource set.
0098         $resObject = $resource->getResource();
0099         foreach ($this->_resources[$type] as $resName => $collectedResObject) {
0100             if ($collectedResObject === $resObject) {
0101                 return $resName;
0102             }
0103         }
0104 
0105         $idCounter = 1;
0106         do {
0107             $newResName = $type[0] . $idCounter++;
0108         } while (isset($this->_resources[$type][$newResName]));
0109 
0110         $this->_resources[$type][$newResName] = $resObject;
0111 
0112         return $newResName;
0113     }
0114 
0115     /**
0116      * Returns dictionaries of used resources.
0117      *
0118      * Used for canvas implementations interoperability
0119      *
0120      * Structure of the returned array:
0121      * array(
0122      *   <resTypeName> => array(
0123      *                      <resName> => <Zend_Pdf_Resource object>,
0124      *                      <resName> => <Zend_Pdf_Resource object>,
0125      *                      <resName> => <Zend_Pdf_Resource object>,
0126      *                      ...
0127      *                    ),
0128      *   <resTypeName> => array(
0129      *                      <resName> => <Zend_Pdf_Resource object>,
0130      *                      <resName> => <Zend_Pdf_Resource object>,
0131      *                      <resName> => <Zend_Pdf_Resource object>,
0132      *                      ...
0133      *                    ),
0134      *   ...
0135      *   'ProcSet' => array()
0136      * )
0137      *
0138      * where ProcSet array is a list of used procedure sets names (strings).
0139      * Allowed procedure set names: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'
0140      *
0141      * @internal
0142      * @return array
0143      */
0144     public function getResources()
0145     {
0146         $this->_resources['ProcSet'] = array_keys($this->_procSet);
0147         return $this->_resources;
0148     }
0149 
0150     /**
0151      * Get drawing instructions stream
0152      *
0153      * It has to be returned as a PDF stream object to make it reusable.
0154      *
0155      * @internal
0156      * @returns Zend_Pdf_Resource_ContentStream
0157      */
0158     public function getContents()
0159     {
0160         /** @todo implementation */
0161     }
0162 
0163     /**
0164      * Return the height of this page in points.
0165      *
0166      * @return float
0167      */
0168     public function getHeight()
0169     {
0170         return $this->_height;
0171     }
0172 
0173     /**
0174      * Return the width of this page in points.
0175      *
0176      * @return float
0177      */
0178     public function getWidth()
0179     {
0180         return $this->_width;
0181     }
0182 }