web/lib/Zend/Pdf/Resource.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     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: Resource.php 22909 2010-08-27 19:57:48Z alexander $
       
    20  */
       
    21 
       
    22 
       
    23 /**
       
    24  * PDF file Resource abstraction
       
    25  *
       
    26  * @package    Zend_Pdf
       
    27  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    28  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    29  */
       
    30 abstract class Zend_Pdf_Resource
       
    31 {
       
    32     /**
       
    33      * Each Pdf resource (fonts, images, ...) interacts with a PDF itself.
       
    34      * It creates appropriate PDF objects, structures and sometime embedded files.
       
    35      * Resources are referenced in content streams by names, which are stored in
       
    36      * a page resource dictionaries.
       
    37      *
       
    38      * Thus, resources must be attached to the PDF.
       
    39      *
       
    40      * Resource abstraction uses own PDF object factory to store all necessary information.
       
    41      * At the render time internal object factory is appended to the global PDF file
       
    42      * factory.
       
    43      *
       
    44      * Resource abstraction also cashes information about rendered PDF files and
       
    45      * doesn't duplicate resource description each time then Resource is rendered
       
    46      * (referenced).
       
    47      *
       
    48      * @var Zend_Pdf_ElementFactory_Interface
       
    49      */
       
    50     protected $_objectFactory;
       
    51 
       
    52     /**
       
    53      * Main resource object
       
    54      *
       
    55      * @var Zend_Pdf_Element_Object
       
    56      */
       
    57     protected $_resource;
       
    58 
       
    59     /**
       
    60      * Object constructor.
       
    61      *
       
    62      * If resource is not a Zend_Pdf_Element object, then stream object with specified value is
       
    63      * generated.
       
    64      *
       
    65      * @param Zend_Pdf_Element|string $resource
       
    66      */
       
    67     public function __construct($resource)
       
    68     {
       
    69         if ($resource instanceof Zend_Pdf_Element_Object) {
       
    70             $this->_objectFactory = $resource->getFactory();
       
    71             $this->_resource      = $resource;
       
    72 
       
    73             return;
       
    74         }
       
    75 
       
    76         require_once 'Zend/Pdf/ElementFactory.php';
       
    77 
       
    78         $this->_objectFactory = Zend_Pdf_ElementFactory::createFactory(1);
       
    79         if ($resource instanceof Zend_Pdf_Element) {
       
    80             $this->_resource  = $this->_objectFactory->newObject($resource);
       
    81         } else {
       
    82             $this->_resource  = $this->_objectFactory->newStreamObject($resource);
       
    83         }
       
    84     }
       
    85 
       
    86     /**
       
    87      * Clone page, extract it and dependent objects from the current document,
       
    88      * so it can be used within other docs.
       
    89      */
       
    90     public function __clone()
       
    91     {
       
    92         /** @todo implementation*/
       
    93 
       
    94 //        $factory = Zend_Pdf_ElementFactory::createFactory(1);
       
    95 //        $processed = array();
       
    96 //
       
    97 //        // Clone dictionary object.
       
    98 //        // Do it explicitly to prevent sharing resource attributes between different
       
    99 //        // results of clone operation (other resources are still shared)
       
   100 //        $dictionary = new Zend_Pdf_Element_Dictionary();
       
   101 //        foreach ($this->_pageDictionary->getKeys() as $key) {
       
   102 //         $dictionary->$key = $this->_pageDictionary->$key->makeClone($factory->getFactory(),
       
   103 //                                                                     $processed,
       
   104 //                                                                     Zend_Pdf_Element::CLONE_MODE_SKIP_PAGES);
       
   105 //        }
       
   106 //
       
   107 //        $this->_pageDictionary = $factory->newObject($dictionary);
       
   108 //        $this->_objectFactory  = $factory;
       
   109 //        $this->_attached       = false;
       
   110 //        $this->_style          = null;
       
   111 //        $this->_font           = null;
       
   112     }
       
   113 
       
   114     /**
       
   115      * Clone resource, extract it and dependent objects from the current document,
       
   116      * so it can be used within other docs.
       
   117      *
       
   118      * @internal
       
   119      * @param Zend_Pdf_ElementFactory_Interface $factory
       
   120      * @param array $processed
       
   121      * @return Zend_Pdf_Page
       
   122      */
       
   123     public function cloneResource($factory, &$processed)
       
   124     {
       
   125         /** @todo implementation*/
       
   126 
       
   127 //        // Clone dictionary object.
       
   128 //        // Do it explicitly to prevent sharing page attributes between different
       
   129 //        // results of clonePage() operation (other resources are still shared)
       
   130 //        $dictionary = new Zend_Pdf_Element_Dictionary();
       
   131 //        foreach ($this->_pageDictionary->getKeys() as $key) {
       
   132 //            $dictionary->$key = $this->_pageDictionary->$key->makeClone($factory->getFactory(),
       
   133 //                                                                        $processed,
       
   134 //                                                                        Zend_Pdf_Element::CLONE_MODE_SKIP_PAGES);
       
   135 //        }
       
   136 //
       
   137 //        $clonedPage = new Zend_Pdf_Page($factory->newObject($dictionary), $factory);
       
   138 //        $clonedPage->_attached = false;
       
   139 //
       
   140 //        return $clonedPage;
       
   141     }
       
   142 
       
   143     /**
       
   144      * Get resource.
       
   145      * Used to reference resource in an internal PDF data structures (resource dictionaries)
       
   146      *
       
   147      * @internal
       
   148      * @return Zend_Pdf_Element_Object
       
   149      */
       
   150     public function getResource()
       
   151     {
       
   152         return $this->_resource;
       
   153     }
       
   154 
       
   155     /**
       
   156      * Get factory.
       
   157      *
       
   158      * @internal
       
   159      * @return Zend_Pdf_ElementFactory_Interface
       
   160      */
       
   161     public function getFactory()
       
   162     {
       
   163         return $this->_objectFactory;
       
   164     }
       
   165 }