|
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: Object.php 22844 2010-08-16 15:38:53Z alexander $ |
|
20 */ |
|
21 |
|
22 |
|
23 /** Zend_Pdf_Element */ |
|
24 require_once 'Zend/Pdf/Element.php'; |
|
25 |
|
26 |
|
27 /** |
|
28 * PDF file 'indirect object' element implementation |
|
29 * |
|
30 * @category Zend |
|
31 * @package Zend_Pdf |
|
32 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
33 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
34 */ |
|
35 class Zend_Pdf_Element_Object extends Zend_Pdf_Element |
|
36 { |
|
37 /** |
|
38 * Object value |
|
39 * |
|
40 * @var Zend_Pdf_Element |
|
41 */ |
|
42 protected $_value; |
|
43 |
|
44 /** |
|
45 * Object number within PDF file |
|
46 * |
|
47 * @var integer |
|
48 */ |
|
49 protected $_objNum; |
|
50 |
|
51 /** |
|
52 * Generation number |
|
53 * |
|
54 * @var integer |
|
55 */ |
|
56 protected $_genNum; |
|
57 |
|
58 /** |
|
59 * Reference to the factory. |
|
60 * |
|
61 * @var Zend_Pdf_ElementFactory |
|
62 */ |
|
63 protected $_factory; |
|
64 |
|
65 /** |
|
66 * Object constructor |
|
67 * |
|
68 * @param Zend_Pdf_Element $val |
|
69 * @param integer $objNum |
|
70 * @param integer $genNum |
|
71 * @param Zend_Pdf_ElementFactory $factory |
|
72 * @throws Zend_Pdf_Exception |
|
73 */ |
|
74 public function __construct(Zend_Pdf_Element $val, $objNum, $genNum, Zend_Pdf_ElementFactory $factory) |
|
75 { |
|
76 if ($val instanceof self) { |
|
77 require_once 'Zend/Pdf/Exception.php'; |
|
78 throw new Zend_Pdf_Exception('Object number must not be an instance of Zend_Pdf_Element_Object.'); |
|
79 } |
|
80 |
|
81 if ( !(is_integer($objNum) && $objNum > 0) ) { |
|
82 require_once 'Zend/Pdf/Exception.php'; |
|
83 throw new Zend_Pdf_Exception('Object number must be positive integer.'); |
|
84 } |
|
85 |
|
86 if ( !(is_integer($genNum) && $genNum >= 0) ) { |
|
87 require_once 'Zend/Pdf/Exception.php'; |
|
88 throw new Zend_Pdf_Exception('Generation number must be non-negative integer.'); |
|
89 } |
|
90 |
|
91 $this->_value = $val; |
|
92 $this->_objNum = $objNum; |
|
93 $this->_genNum = $genNum; |
|
94 $this->_factory = $factory; |
|
95 |
|
96 $this->setParentObject($this); |
|
97 |
|
98 $factory->registerObject($this, $objNum . ' ' . $genNum); |
|
99 } |
|
100 |
|
101 |
|
102 /** |
|
103 * Check, that object is generated by specified factory |
|
104 * |
|
105 * @return Zend_Pdf_ElementFactory |
|
106 */ |
|
107 public function getFactory() |
|
108 { |
|
109 return $this->_factory; |
|
110 } |
|
111 |
|
112 /** |
|
113 * Return type of the element. |
|
114 * |
|
115 * @return integer |
|
116 */ |
|
117 public function getType() |
|
118 { |
|
119 return $this->_value->getType(); |
|
120 } |
|
121 |
|
122 |
|
123 /** |
|
124 * Get object number |
|
125 * |
|
126 * @return integer |
|
127 */ |
|
128 public function getObjNum() |
|
129 { |
|
130 return $this->_objNum; |
|
131 } |
|
132 |
|
133 |
|
134 /** |
|
135 * Get generation number |
|
136 * |
|
137 * @return integer |
|
138 */ |
|
139 public function getGenNum() |
|
140 { |
|
141 return $this->_genNum; |
|
142 } |
|
143 |
|
144 |
|
145 /** |
|
146 * Return reference to the object |
|
147 * |
|
148 * @param Zend_Pdf_Factory $factory |
|
149 * @return string |
|
150 */ |
|
151 public function toString($factory = null) |
|
152 { |
|
153 if ($factory === null) { |
|
154 $shift = 0; |
|
155 } else { |
|
156 $shift = $factory->getEnumerationShift($this->_factory); |
|
157 } |
|
158 |
|
159 return $this->_objNum + $shift . ' ' . $this->_genNum . ' R'; |
|
160 } |
|
161 |
|
162 |
|
163 /** |
|
164 * Dump object to a string to save within PDF file. |
|
165 * |
|
166 * $factory parameter defines operation context. |
|
167 * |
|
168 * @param Zend_Pdf_ElementFactory $factory |
|
169 * @return string |
|
170 */ |
|
171 public function dump(Zend_Pdf_ElementFactory $factory) |
|
172 { |
|
173 $shift = $factory->getEnumerationShift($this->_factory); |
|
174 |
|
175 return $this->_objNum + $shift . " " . $this->_genNum . " obj \n" |
|
176 . $this->_value->toString($factory) . "\n" |
|
177 . "endobj\n"; |
|
178 } |
|
179 |
|
180 /** |
|
181 * Get handler |
|
182 * |
|
183 * @param string $property |
|
184 * @return mixed |
|
185 */ |
|
186 public function __get($property) |
|
187 { |
|
188 return $this->_value->$property; |
|
189 } |
|
190 |
|
191 /** |
|
192 * Set handler |
|
193 * |
|
194 * @param string $property |
|
195 * @param mixed $value |
|
196 */ |
|
197 public function __set($property, $value) |
|
198 { |
|
199 $this->_value->$property = $value; |
|
200 } |
|
201 |
|
202 /** |
|
203 * Call handler |
|
204 * |
|
205 * @param string $method |
|
206 * @param array $args |
|
207 * @return mixed |
|
208 */ |
|
209 public function __call($method, $args) |
|
210 { |
|
211 return call_user_func_array(array($this->_value, $method), $args); |
|
212 } |
|
213 |
|
214 /** |
|
215 * Detach PDF object from the factory (if applicable), clone it and attach to new factory. |
|
216 * |
|
217 * @param Zend_Pdf_ElementFactory $factory The factory to attach |
|
218 * @param array &$processed List of already processed indirect objects, used to avoid objects duplication |
|
219 * @param integer $mode Cloning mode (defines filter for objects cloning) |
|
220 * @returns Zend_Pdf_Element |
|
221 */ |
|
222 public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode) |
|
223 { |
|
224 $id = spl_object_hash($this); |
|
225 if (isset($processed[$id])) { |
|
226 // Do nothing if object is already processed |
|
227 // return it |
|
228 return $processed[$id]; |
|
229 } |
|
230 |
|
231 // Create obect with null value and register it in $processed container |
|
232 $processed[$id] = $clonedObject = $factory->newObject(new Zend_Pdf_Element_Null()); |
|
233 |
|
234 // Pecursively process actual data |
|
235 $clonedObject->_value = $this->_value->makeClone($factory, $processed, $mode); |
|
236 |
|
237 if ($clonedObject->_value instanceof Zend_Pdf_Element_Null) { |
|
238 // Do not store null objects within $processed container since it may be filtered |
|
239 // by $mode parameter but used in some future pass |
|
240 unset($processed[$id]); |
|
241 |
|
242 // Return direct null object |
|
243 return $clonedObject->_value; |
|
244 } |
|
245 |
|
246 return $clonedObject; |
|
247 } |
|
248 |
|
249 /** |
|
250 * Mark object as modified, to include it into new PDF file segment |
|
251 */ |
|
252 public function touch() |
|
253 { |
|
254 $this->_factory->markAsModified($this); |
|
255 } |
|
256 |
|
257 /** |
|
258 * Return object, which can be used to identify object and its references identity |
|
259 * |
|
260 * @return Zend_Pdf_Element_Object |
|
261 */ |
|
262 public function getObject() |
|
263 { |
|
264 return $this; |
|
265 } |
|
266 |
|
267 /** |
|
268 * Clean up resources, used by object |
|
269 */ |
|
270 public function cleanUp() |
|
271 { |
|
272 $this->_value = null; |
|
273 } |
|
274 |
|
275 /** |
|
276 * Convert PDF element to PHP type. |
|
277 * |
|
278 * @return mixed |
|
279 */ |
|
280 public function toPhp() |
|
281 { |
|
282 return $this->_value->toPhp(); |
|
283 } |
|
284 } |