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

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$
0020  */
0021 
0022 
0023 /**
0024  * PDF file Resource abstraction
0025  *
0026  * @package    Zend_Pdf
0027  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0028  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0029  */
0030 abstract class Zend_Pdf_Resource
0031 {
0032     /**
0033      * Each Pdf resource (fonts, images, ...) interacts with a PDF itself.
0034      * It creates appropriate PDF objects, structures and sometime embedded files.
0035      * Resources are referenced in content streams by names, which are stored in
0036      * a page resource dictionaries.
0037      *
0038      * Thus, resources must be attached to the PDF.
0039      *
0040      * Resource abstraction uses own PDF object factory to store all necessary information.
0041      * At the render time internal object factory is appended to the global PDF file
0042      * factory.
0043      *
0044      * Resource abstraction also cashes information about rendered PDF files and
0045      * doesn't duplicate resource description each time then Resource is rendered
0046      * (referenced).
0047      *
0048      * @var Zend_Pdf_ElementFactory_Interface
0049      */
0050     protected $_objectFactory;
0051 
0052     /**
0053      * Main resource object
0054      *
0055      * @var Zend_Pdf_Element_Object
0056      */
0057     protected $_resource;
0058 
0059     /**
0060      * Object constructor.
0061      *
0062      * If resource is not a Zend_Pdf_Element object, then stream object with specified value is
0063      * generated.
0064      *
0065      * @param Zend_Pdf_Element|string $resource
0066      */
0067     public function __construct($resource)
0068     {
0069         if ($resource instanceof Zend_Pdf_Element_Object) {
0070             $this->_objectFactory = $resource->getFactory();
0071             $this->_resource      = $resource;
0072 
0073             return;
0074         }
0075 
0076         // require_once 'Zend/Pdf/ElementFactory.php';
0077 
0078         $this->_objectFactory = Zend_Pdf_ElementFactory::createFactory(1);
0079         if ($resource instanceof Zend_Pdf_Element) {
0080             $this->_resource  = $this->_objectFactory->newObject($resource);
0081         } else {
0082             $this->_resource  = $this->_objectFactory->newStreamObject($resource);
0083         }
0084     }
0085 
0086     /**
0087      * Clone page, extract it and dependent objects from the current document,
0088      * so it can be used within other docs.
0089      */
0090     public function __clone()
0091     {
0092         /** @todo implementation*/
0093 
0094 //        $factory = Zend_Pdf_ElementFactory::createFactory(1);
0095 //        $processed = array();
0096 //
0097 //        // Clone dictionary object.
0098 //        // Do it explicitly to prevent sharing resource attributes between different
0099 //        // results of clone operation (other resources are still shared)
0100 //        $dictionary = new Zend_Pdf_Element_Dictionary();
0101 //        foreach ($this->_pageDictionary->getKeys() as $key) {
0102 //         $dictionary->$key = $this->_pageDictionary->$key->makeClone($factory->getFactory(),
0103 //                                                                     $processed,
0104 //                                                                     Zend_Pdf_Element::CLONE_MODE_SKIP_PAGES);
0105 //        }
0106 //
0107 //        $this->_pageDictionary = $factory->newObject($dictionary);
0108 //        $this->_objectFactory  = $factory;
0109 //        $this->_attached       = false;
0110 //        $this->_style          = null;
0111 //        $this->_font           = null;
0112     }
0113 
0114     /**
0115      * Clone resource, extract it and dependent objects from the current document,
0116      * so it can be used within other docs.
0117      *
0118      * @internal
0119      * @param Zend_Pdf_ElementFactory_Interface $factory
0120      * @param array $processed
0121      * @return Zend_Pdf_Page
0122      */
0123     public function cloneResource($factory, &$processed)
0124     {
0125         /** @todo implementation*/
0126 
0127 //        // Clone dictionary object.
0128 //        // Do it explicitly to prevent sharing page attributes between different
0129 //        // results of clonePage() operation (other resources are still shared)
0130 //        $dictionary = new Zend_Pdf_Element_Dictionary();
0131 //        foreach ($this->_pageDictionary->getKeys() as $key) {
0132 //            $dictionary->$key = $this->_pageDictionary->$key->makeClone($factory->getFactory(),
0133 //                                                                        $processed,
0134 //                                                                        Zend_Pdf_Element::CLONE_MODE_SKIP_PAGES);
0135 //        }
0136 //
0137 //        $clonedPage = new Zend_Pdf_Page($factory->newObject($dictionary), $factory);
0138 //        $clonedPage->_attached = false;
0139 //
0140 //        return $clonedPage;
0141     }
0142 
0143     /**
0144      * Get resource.
0145      * Used to reference resource in an internal PDF data structures (resource dictionaries)
0146      *
0147      * @internal
0148      * @return Zend_Pdf_Element_Object
0149      */
0150     public function getResource()
0151     {
0152         return $this->_resource;
0153     }
0154 
0155     /**
0156      * Get factory.
0157      *
0158      * @internal
0159      * @return Zend_Pdf_ElementFactory_Interface
0160      */
0161     public function getFactory()
0162     {
0163         return $this->_objectFactory;
0164     }
0165 }