File indexing completed on 2024-12-22 05:36: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 // require_once 'Zend/Pdf/Element/Array.php';
0026 // require_once 'Zend/Pdf/Element/Dictionary.php';
0027 // require_once 'Zend/Pdf/Element/Name.php';
0028 // require_once 'Zend/Pdf/Element/Numeric.php';
0029 // require_once 'Zend/Pdf/Element/String.php';
0030 
0031 
0032 /** Zend_Pdf_Annotation */
0033 // require_once 'Zend/Pdf/Annotation.php';
0034 
0035 /**
0036  * A text annotation represents a "sticky note" attached to a point in the PDF document.
0037  *
0038  * @package    Zend_Pdf
0039  * @subpackage Annotation
0040  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0041  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0042  */
0043 class Zend_Pdf_Annotation_Text extends Zend_Pdf_Annotation
0044 {
0045     /**
0046      * Annotation object constructor
0047      *
0048      * @throws Zend_Pdf_Exception
0049      */
0050     public function __construct(Zend_Pdf_Element $annotationDictionary)
0051     {
0052         if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
0053             // require_once 'Zend/Pdf/Exception.php';
0054             throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
0055         }
0056 
0057         if ($annotationDictionary->Subtype === null  ||
0058             $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME  ||
0059             $annotationDictionary->Subtype->value != 'Text') {
0060             // require_once 'Zend/Pdf/Exception.php';
0061             throw new Zend_Pdf_Exception('Subtype => Text entry is requires');
0062         }
0063 
0064         parent::__construct($annotationDictionary);
0065     }
0066 
0067     /**
0068      * Create link annotation object
0069      *
0070      * @param float $x1
0071      * @param float $y1
0072      * @param float $x2
0073      * @param float $y2
0074      * @param string $text
0075      * @return Zend_Pdf_Annotation_Text
0076      */
0077     public static function create($x1, $y1, $x2, $y2, $text)
0078     {
0079         $annotationDictionary = new Zend_Pdf_Element_Dictionary();
0080 
0081         $annotationDictionary->Type    = new Zend_Pdf_Element_Name('Annot');
0082         $annotationDictionary->Subtype = new Zend_Pdf_Element_Name('Text');
0083 
0084         $rectangle = new Zend_Pdf_Element_Array();
0085         $rectangle->items[] = new Zend_Pdf_Element_Numeric($x1);
0086         $rectangle->items[] = new Zend_Pdf_Element_Numeric($y1);
0087         $rectangle->items[] = new Zend_Pdf_Element_Numeric($x2);
0088         $rectangle->items[] = new Zend_Pdf_Element_Numeric($y2);
0089         $annotationDictionary->Rect = $rectangle;
0090 
0091         $annotationDictionary->Contents = new Zend_Pdf_Element_String($text);
0092 
0093         return new Zend_Pdf_Annotation_Text($annotationDictionary);
0094     }
0095 }