File indexing completed on 2025-01-19 05:21:23
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 element implementation 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_Element 0031 { 0032 const TYPE_BOOL = 1; 0033 const TYPE_NUMERIC = 2; 0034 const TYPE_STRING = 3; 0035 const TYPE_NAME = 4; 0036 const TYPE_ARRAY = 5; 0037 const TYPE_DICTIONARY = 6; 0038 const TYPE_STREAM = 7; 0039 const TYPE_NULL = 11; 0040 0041 /** 0042 * Reference to the top level indirect object, which contains this element. 0043 * 0044 * @var Zend_Pdf_Element_Object 0045 */ 0046 private $_parentObject = null; 0047 0048 /** 0049 * Return type of the element. 0050 * See ZPdfPDFConst for possible values 0051 * 0052 * @return integer 0053 */ 0054 abstract public function getType(); 0055 0056 /** 0057 * Convert element to a string, which can be directly 0058 * written to a PDF file. 0059 * 0060 * $factory parameter defines operation context. 0061 * 0062 * @param Zend_Pdf_Factory $factory 0063 * @return string 0064 */ 0065 abstract public function toString($factory = null); 0066 0067 const CLONE_MODE_SKIP_PAGES = 1; // Do not follow pages during deep copy process 0068 const CLONE_MODE_FORCE_CLONING = 2; // Force top level object cloning even it's already processed 0069 0070 /** 0071 * Detach PDF object from the factory (if applicable), clone it and attach to new factory. 0072 * 0073 * @todo It's nevessry to check if SplObjectStorage class works faster 0074 * (Needs PHP 5.3.x to attach object _with_ additional data to storage) 0075 * 0076 * @param Zend_Pdf_ElementFactory $factory The factory to attach 0077 * @param array &$processed List of already processed indirect objects, used to avoid objects duplication 0078 * @param integer $mode Cloning mode (defines filter for objects cloning) 0079 * @returns Zend_Pdf_Element 0080 */ 0081 public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode) 0082 { 0083 return clone $this; 0084 } 0085 0086 /** 0087 * Set top level parent indirect object. 0088 * 0089 * @param Zend_Pdf_Element_Object $parent 0090 */ 0091 public function setParentObject(Zend_Pdf_Element_Object $parent) 0092 { 0093 $this->_parentObject = $parent; 0094 } 0095 0096 0097 /** 0098 * Get top level parent indirect object. 0099 * 0100 * @return Zend_Pdf_Element_Object 0101 */ 0102 public function getParentObject() 0103 { 0104 return $this->_parentObject; 0105 } 0106 0107 0108 /** 0109 * Mark object as modified, to include it into new PDF file segment. 0110 * 0111 * We don't automate this action to keep control on PDF update process. 0112 * All new objects are treated as "modified" automatically. 0113 */ 0114 public function touch() 0115 { 0116 if ($this->_parentObject !== null) { 0117 $this->_parentObject->touch(); 0118 } 0119 } 0120 0121 /** 0122 * Clean up resources, used by object 0123 */ 0124 public function cleanUp() 0125 { 0126 // Do nothing 0127 } 0128 0129 /** 0130 * Convert PDF element to PHP type. 0131 * 0132 * @return mixed 0133 */ 0134 public function toPhp() 0135 { 0136 return $this->value; 0137 } 0138 0139 /** 0140 * Convert PHP value into PDF element. 0141 * 0142 * @param mixed $input 0143 * @return Zend_Pdf_Element 0144 */ 0145 public static function phpToPdf($input) 0146 { 0147 if (is_numeric($input)) { 0148 // require_once 'Zend/Pdf/Element/Numeric.php'; 0149 return new Zend_Pdf_Element_Numeric($input); 0150 } else if (is_bool($input)) { 0151 // require_once 'Zend/Pdf/Element/Boolean.php'; 0152 return new Zend_Pdf_Element_Boolean($input); 0153 } else if (is_array($input)) { 0154 $pdfElementsArray = array(); 0155 $isDictionary = false; 0156 0157 foreach ($input as $key => $value) { 0158 if (is_string($key)) { 0159 $isDictionary = true; 0160 } 0161 $pdfElementsArray[$key] = Zend_Pdf_Element::phpToPdf($value); 0162 } 0163 0164 if ($isDictionary) { 0165 // require_once 'Zend/Pdf/Element/Dictionary.php'; 0166 return new Zend_Pdf_Element_Dictionary($pdfElementsArray); 0167 } else { 0168 // require_once 'Zend/Pdf/Element/Array.php'; 0169 return new Zend_Pdf_Element_Array($pdfElementsArray); 0170 } 0171 } else { 0172 // require_once 'Zend/Pdf/Element/String.php'; 0173 return new Zend_Pdf_Element_String((string)$input); 0174 } 0175 } 0176 }