|
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 * @subpackage Annotation |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Annotation.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** Internally used classes */ |
|
24 require_once 'Zend/Pdf/Element.php'; |
|
25 |
|
26 /** |
|
27 * Abstract PDF annotation representation class |
|
28 * |
|
29 * An annotation associates an object such as a note, sound, or movie with a location |
|
30 * on a page of a PDF document, or provides a way to interact with the user by |
|
31 * means of the mouse and keyboard. |
|
32 * |
|
33 * @package Zend_Pdf |
|
34 * @subpackage Annotation |
|
35 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
36 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
37 */ |
|
38 abstract class Zend_Pdf_Annotation |
|
39 { |
|
40 /** |
|
41 * Annotation dictionary |
|
42 * |
|
43 * @var Zend_Pdf_Element_Dictionary|Zend_Pdf_Element_Object|Zend_Pdf_Element_Reference |
|
44 */ |
|
45 protected $_annotationDictionary; |
|
46 |
|
47 /** |
|
48 * Get annotation dictionary |
|
49 * |
|
50 * @internal |
|
51 * @return Zend_Pdf_Element |
|
52 */ |
|
53 public function getResource() |
|
54 { |
|
55 return $this->_annotationDictionary; |
|
56 } |
|
57 |
|
58 |
|
59 /** |
|
60 * Set bottom edge of the annotation rectangle. |
|
61 * |
|
62 * @param float $bottom |
|
63 * @return Zend_Pdf_Annotation |
|
64 */ |
|
65 public function setBottom($bottom) { |
|
66 $this->_annotationDictionary->Rect->items[1]->touch(); |
|
67 $this->_annotationDictionary->Rect->items[1]->value = $bottom; |
|
68 |
|
69 return $this; |
|
70 } |
|
71 |
|
72 /** |
|
73 * Get bottom edge of the annotation rectangle. |
|
74 * |
|
75 * @return float |
|
76 */ |
|
77 public function getBottom() { |
|
78 return $this->_annotationDictionary->Rect->items[1]->value; |
|
79 } |
|
80 |
|
81 /** |
|
82 * Set top edge of the annotation rectangle. |
|
83 * |
|
84 * @param float $top |
|
85 * @return Zend_Pdf_Annotation |
|
86 */ |
|
87 public function setTop($top) { |
|
88 $this->_annotationDictionary->Rect->items[3]->touch(); |
|
89 $this->_annotationDictionary->Rect->items[3]->value = $top; |
|
90 |
|
91 return $this; |
|
92 } |
|
93 |
|
94 /** |
|
95 * Get top edge of the annotation rectangle. |
|
96 * |
|
97 * @return float |
|
98 */ |
|
99 public function getTop() { |
|
100 return $this->_annotationDictionary->Rect->items[3]->value; |
|
101 } |
|
102 |
|
103 /** |
|
104 * Set right edge of the annotation rectangle. |
|
105 * |
|
106 * @param float $right |
|
107 * @return Zend_Pdf_Annotation |
|
108 */ |
|
109 public function setRight($right) { |
|
110 $this->_annotationDictionary->Rect->items[2]->touch(); |
|
111 $this->_annotationDictionary->Rect->items[2]->value = $right; |
|
112 |
|
113 return $this; |
|
114 } |
|
115 |
|
116 /** |
|
117 * Get right edge of the annotation rectangle. |
|
118 * |
|
119 * @return float |
|
120 */ |
|
121 public function getRight() { |
|
122 return $this->_annotationDictionary->Rect->items[2]->value; |
|
123 } |
|
124 |
|
125 /** |
|
126 * Set left edge of the annotation rectangle. |
|
127 * |
|
128 * @param float $left |
|
129 * @return Zend_Pdf_Annotation |
|
130 */ |
|
131 public function setLeft($left) { |
|
132 $this->_annotationDictionary->Rect->items[0]->touch(); |
|
133 $this->_annotationDictionary->Rect->items[0]->value = $left; |
|
134 |
|
135 return $this; |
|
136 } |
|
137 |
|
138 /** |
|
139 * Get left edge of the annotation rectangle. |
|
140 * |
|
141 * @return float |
|
142 */ |
|
143 public function getLeft() { |
|
144 return $this->_annotationDictionary->Rect->items[0]->value; |
|
145 } |
|
146 |
|
147 /** |
|
148 * Return text to be displayed for the annotation or, if this type of annotation |
|
149 * does not display text, an alternate description of the annotation’s contents |
|
150 * in human-readable form. |
|
151 * |
|
152 * @return string |
|
153 */ |
|
154 public function getText() { |
|
155 if ($this->_annotationDictionary->Contents === null) { |
|
156 return ''; |
|
157 } |
|
158 |
|
159 return $this->_annotationDictionary->Contents->value; |
|
160 } |
|
161 |
|
162 /** |
|
163 * Set text to be displayed for the annotation or, if this type of annotation |
|
164 * does not display text, an alternate description of the annotation’s contents |
|
165 * in human-readable form. |
|
166 * |
|
167 * @param string $text |
|
168 * @return Zend_Pdf_Annotation |
|
169 */ |
|
170 public function setText($text) { |
|
171 require_once 'Zend/Pdf/Element/String.php'; |
|
172 |
|
173 if ($this->_annotationDictionary->Contents === null) { |
|
174 $this->_annotationDictionary->touch(); |
|
175 $this->_annotationDictionary->Contents = new Zend_Pdf_Element_String($text); |
|
176 } else { |
|
177 $this->_annotationDictionary->Contents->touch(); |
|
178 $this->_annotationDictionary->Contents->value = new Zend_Pdf_Element_String($text); |
|
179 } |
|
180 |
|
181 return $this; |
|
182 } |
|
183 |
|
184 /** |
|
185 * Annotation object constructor |
|
186 * |
|
187 * @throws Zend_Pdf_Exception |
|
188 */ |
|
189 public function __construct(Zend_Pdf_Element $annotationDictionary) |
|
190 { |
|
191 if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) { |
|
192 require_once 'Zend/Pdf/Exception.php'; |
|
193 throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.'); |
|
194 } |
|
195 |
|
196 $this->_annotationDictionary = $annotationDictionary; |
|
197 |
|
198 if ($this->_annotationDictionary->Type !== null && |
|
199 $this->_annotationDictionary->Type->value != 'Annot') { |
|
200 require_once 'Zend/Pdf/Exception.php'; |
|
201 throw new Zend_Pdf_Exception('Wrong resource type. \'Annot\' expected.'); |
|
202 } |
|
203 |
|
204 if ($this->_annotationDictionary->Rect === null) { |
|
205 require_once 'Zend/Pdf/Exception.php'; |
|
206 throw new Zend_Pdf_Exception('\'Rect\' dictionary entry is required.'); |
|
207 } |
|
208 |
|
209 if (count($this->_annotationDictionary->Rect->items) != 4 || |
|
210 $this->_annotationDictionary->Rect->items[0]->getType() != Zend_Pdf_Element::TYPE_NUMERIC || |
|
211 $this->_annotationDictionary->Rect->items[1]->getType() != Zend_Pdf_Element::TYPE_NUMERIC || |
|
212 $this->_annotationDictionary->Rect->items[2]->getType() != Zend_Pdf_Element::TYPE_NUMERIC || |
|
213 $this->_annotationDictionary->Rect->items[3]->getType() != Zend_Pdf_Element::TYPE_NUMERIC ) { |
|
214 require_once 'Zend/Pdf/Exception.php'; |
|
215 throw new Zend_Pdf_Exception('\'Rect\' dictionary entry must be an array of four numeric elements.'); |
|
216 } |
|
217 } |
|
218 |
|
219 /** |
|
220 * Load Annotation object from a specified resource |
|
221 * |
|
222 * @internal |
|
223 * @param $destinationArray |
|
224 * @return Zend_Pdf_Annotation |
|
225 */ |
|
226 public static function load(Zend_Pdf_Element $resource) |
|
227 { |
|
228 /** @todo implementation */ |
|
229 } |
|
230 } |