File indexing completed on 2025-01-19 05:21:21
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 reference table 0025 * 0026 * @category Zend 0027 * @package Zend_Pdf 0028 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0029 * @license http://framework.zend.com/license/new-bsd New BSD License 0030 */ 0031 class Zend_Pdf_Element_Reference_Table 0032 { 0033 /** 0034 * Parent reference table 0035 * 0036 * @var Zend_Pdf_Element_Reference_Table 0037 */ 0038 private $_parent; 0039 0040 /** 0041 * Free entries 0042 * 'reference' => next free object number 0043 * 0044 * @var array 0045 */ 0046 private $_free; 0047 0048 /** 0049 * Generation numbers for free objects. 0050 * Array: objNum => nextGeneration 0051 * 0052 * @var array 0053 */ 0054 private $_generations; 0055 0056 /** 0057 * In use entries 0058 * 'reference' => offset 0059 * 0060 * @var array 0061 */ 0062 private $_inuse; 0063 0064 /** 0065 * Generation numbers for free objects. 0066 * Array: objNum => objGeneration 0067 * 0068 * @var array 0069 */ 0070 private $_usedObjects; 0071 0072 0073 0074 /** 0075 * Object constructor 0076 */ 0077 public function __construct() 0078 { 0079 $this->_parent = null; 0080 $this->_free = array(); $this->_generations = array(); 0081 $this->_inuse = array(); $this->_usedObjects = array(); 0082 } 0083 0084 0085 /** 0086 * Add reference to the reference table 0087 * 0088 * @param string $ref 0089 * @param integer $offset 0090 * @param boolean $inuse 0091 */ 0092 public function addReference($ref, $offset, $inuse = true) 0093 { 0094 $refElements = explode(' ', $ref); 0095 if (!is_numeric($refElements[0]) || !is_numeric($refElements[1]) || $refElements[2] != 'R') { 0096 // require_once 'Zend/Pdf/Exception.php'; 0097 throw new Zend_Pdf_Exception("Incorrect reference: '$ref'"); 0098 } 0099 $objNum = (int)$refElements[0]; 0100 $genNum = (int)$refElements[1]; 0101 0102 if ($inuse) { 0103 $this->_inuse[$ref] = $offset; 0104 $this->_usedObjects[$objNum] = $objNum; 0105 } else { 0106 $this->_free[$ref] = $offset; 0107 $this->_generations[$objNum] = $genNum; 0108 } 0109 } 0110 0111 0112 /** 0113 * Set parent reference table 0114 * 0115 * @param Zend_Pdf_Element_Reference_Table $parent 0116 */ 0117 public function setParent(self $parent) 0118 { 0119 $this->_parent = $parent; 0120 } 0121 0122 0123 /** 0124 * Get object offset 0125 * 0126 * @param string $ref 0127 * @return integer 0128 */ 0129 public function getOffset($ref) 0130 { 0131 if (isset($this->_inuse[$ref])) { 0132 return $this->_inuse[$ref]; 0133 } 0134 0135 if (isset($this->_free[$ref])) { 0136 return null; 0137 } 0138 0139 if (isset($this->_parent)) { 0140 return $this->_parent->getOffset($ref); 0141 } 0142 0143 return null; 0144 } 0145 0146 0147 /** 0148 * Get next object from a list of free objects. 0149 * 0150 * @param string $ref 0151 * @return integer 0152 * @throws Zend_Pdf_Exception 0153 */ 0154 public function getNextFree($ref) 0155 { 0156 if (isset($this->_inuse[$ref])) { 0157 // require_once 'Zend/Pdf/Exception.php'; 0158 throw new Zend_Pdf_Exception('Object is not free'); 0159 } 0160 0161 if (isset($this->_free[$ref])) { 0162 return $this->_free[$ref]; 0163 } 0164 0165 if (isset($this->_parent)) { 0166 return $this->_parent->getNextFree($ref); 0167 } 0168 0169 // require_once 'Zend/Pdf/Exception.php'; 0170 throw new Zend_Pdf_Exception('Object not found.'); 0171 } 0172 0173 0174 /** 0175 * Get next generation number for free object 0176 * 0177 * @param integer $objNum 0178 * @return unknown 0179 */ 0180 public function getNewGeneration($objNum) 0181 { 0182 if (isset($this->_usedObjects[$objNum])) { 0183 // require_once 'Zend/Pdf/Exception.php'; 0184 throw new Zend_Pdf_Exception('Object is not free'); 0185 } 0186 0187 if (isset($this->_generations[$objNum])) { 0188 return $this->_generations[$objNum]; 0189 } 0190 0191 if (isset($this->_parent)) { 0192 return $this->_parent->getNewGeneration($objNum); 0193 } 0194 0195 // require_once 'Zend/Pdf/Exception.php'; 0196 throw new Zend_Pdf_Exception('Object not found.'); 0197 } 0198 }