You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
6.8 KiB

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