File indexing completed on 2024-05-12 06:02:53

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  * @subpackage Annotation
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /** Internally used classes */
0024 // require_once 'Zend/Pdf/Element.php';
0025 
0026 /**
0027  * Abstract PDF annotation representation class
0028  *
0029  * An annotation associates an object such as a note, sound, or movie with a location
0030  * on a page of a PDF document, or provides a way to interact with the user by
0031  * means of the mouse and keyboard.
0032  *
0033  * @package    Zend_Pdf
0034  * @subpackage Annotation
0035  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0036  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0037  */
0038 abstract class Zend_Pdf_Annotation
0039 {
0040     /**
0041      * Annotation dictionary
0042      *
0043      * @var Zend_Pdf_Element_Dictionary|Zend_Pdf_Element_Object|Zend_Pdf_Element_Reference
0044      */
0045     protected $_annotationDictionary;
0046 
0047     /**
0048      * Get annotation dictionary
0049      *
0050      * @internal
0051      * @return Zend_Pdf_Element
0052      */
0053     public function getResource()
0054     {
0055         return $this->_annotationDictionary;
0056     }
0057 
0058 
0059     /**
0060      * Set bottom edge of the annotation rectangle.
0061      *
0062      * @param float $bottom
0063      * @return Zend_Pdf_Annotation
0064      */
0065     public function setBottom($bottom) {
0066         $this->_annotationDictionary->Rect->items[1]->touch();
0067         $this->_annotationDictionary->Rect->items[1]->value = $bottom;
0068 
0069         return $this;
0070     }
0071 
0072     /**
0073      * Get bottom edge of the annotation rectangle.
0074      *
0075      * @return float
0076      */
0077     public function getBottom() {
0078         return $this->_annotationDictionary->Rect->items[1]->value;
0079     }
0080 
0081     /**
0082      * Set top edge of the annotation rectangle.
0083      *
0084      * @param float $top
0085      * @return Zend_Pdf_Annotation
0086      */
0087     public function setTop($top) {
0088         $this->_annotationDictionary->Rect->items[3]->touch();
0089         $this->_annotationDictionary->Rect->items[3]->value = $top;
0090 
0091         return $this;
0092     }
0093 
0094     /**
0095      * Get top edge of the annotation rectangle.
0096      *
0097      * @return float
0098      */
0099     public function getTop() {
0100         return $this->_annotationDictionary->Rect->items[3]->value;
0101     }
0102 
0103     /**
0104      * Set right edge of the annotation rectangle.
0105      *
0106      * @param float $right
0107      * @return Zend_Pdf_Annotation
0108      */
0109     public function setRight($right) {
0110         $this->_annotationDictionary->Rect->items[2]->touch();
0111         $this->_annotationDictionary->Rect->items[2]->value = $right;
0112 
0113         return $this;
0114     }
0115 
0116     /**
0117      * Get right edge of the annotation rectangle.
0118      *
0119      * @return float
0120      */
0121     public function getRight() {
0122         return $this->_annotationDictionary->Rect->items[2]->value;
0123     }
0124 
0125     /**
0126      * Set left edge of the annotation rectangle.
0127      *
0128      * @param float $left
0129      * @return Zend_Pdf_Annotation
0130      */
0131     public function setLeft($left) {
0132         $this->_annotationDictionary->Rect->items[0]->touch();
0133         $this->_annotationDictionary->Rect->items[0]->value = $left;
0134 
0135         return $this;
0136     }
0137 
0138     /**
0139      * Get left edge of the annotation rectangle.
0140      *
0141      * @return float
0142      */
0143     public function getLeft() {
0144         return $this->_annotationDictionary->Rect->items[0]->value;
0145     }
0146 
0147     /**
0148      * Return text to be displayed for the annotation or, if this type of annotation
0149      * does not display text, an alternate description of the annotation’s contents
0150      * in human-readable form.
0151      *
0152      * @return string
0153      */
0154     public function getText() {
0155         if ($this->_annotationDictionary->Contents === null) {
0156             return '';
0157         }
0158 
0159         return $this->_annotationDictionary->Contents->value;
0160     }
0161 
0162     /**
0163      * Set text to be displayed for the annotation or, if this type of annotation
0164      * does not display text, an alternate description of the annotation’s contents
0165      * in human-readable form.
0166      *
0167      * @param string $text
0168      * @return Zend_Pdf_Annotation
0169      */
0170     public function setText($text) {
0171         // require_once 'Zend/Pdf/Element/String.php';
0172 
0173         if ($this->_annotationDictionary->Contents === null) {
0174             $this->_annotationDictionary->touch();
0175             $this->_annotationDictionary->Contents = new Zend_Pdf_Element_String($text);
0176         } else {
0177             $this->_annotationDictionary->Contents->touch();
0178             $this->_annotationDictionary->Contents->value = new Zend_Pdf_Element_String($text);
0179         }
0180 
0181         return $this;
0182     }
0183 
0184     /**
0185      * Annotation object constructor
0186      *
0187      * @throws Zend_Pdf_Exception
0188      */
0189     public function __construct(Zend_Pdf_Element $annotationDictionary)
0190     {
0191         if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
0192             // require_once 'Zend/Pdf/Exception.php';
0193             throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
0194         }
0195 
0196         $this->_annotationDictionary = $annotationDictionary;
0197 
0198         if ($this->_annotationDictionary->Type !== null  &&
0199             $this->_annotationDictionary->Type->value != 'Annot') {
0200             // require_once 'Zend/Pdf/Exception.php';
0201             throw new Zend_Pdf_Exception('Wrong resource type. \'Annot\' expected.');
0202         }
0203 
0204         if ($this->_annotationDictionary->Rect === null) {
0205             // require_once 'Zend/Pdf/Exception.php';
0206             throw new Zend_Pdf_Exception('\'Rect\' dictionary entry is required.');
0207         }
0208 
0209         if (count($this->_annotationDictionary->Rect->items) != 4 ||
0210             $this->_annotationDictionary->Rect->items[0]->getType() != Zend_Pdf_Element::TYPE_NUMERIC ||
0211             $this->_annotationDictionary->Rect->items[1]->getType() != Zend_Pdf_Element::TYPE_NUMERIC ||
0212             $this->_annotationDictionary->Rect->items[2]->getType() != Zend_Pdf_Element::TYPE_NUMERIC ||
0213             $this->_annotationDictionary->Rect->items[3]->getType() != Zend_Pdf_Element::TYPE_NUMERIC ) {
0214             // require_once 'Zend/Pdf/Exception.php';
0215             throw new Zend_Pdf_Exception('\'Rect\' dictionary entry must be an array of four numeric elements.');
0216         }
0217     }
0218 
0219     /**
0220      * Load Annotation object from a specified resource
0221      *
0222      * @internal
0223      * @param Zend_Pdf_Element $resource
0224      * @return Zend_Pdf_Annotation
0225      */
0226     public static function load(Zend_Pdf_Element $resource)
0227     {
0228         /** @todo implementation */
0229     }
0230 }