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 0030 0031 /** Zend_Pdf_Annotation */ 0032 // require_once 'Zend/Pdf/Annotation.php'; 0033 0034 /** 0035 * A link annotation represents either a hypertext link to a destination elsewhere in 0036 * the document or an action to be performed. 0037 * 0038 * Only destinations are used now since only GoTo action can be created by user 0039 * in current implementation. 0040 * 0041 * @package Zend_Pdf 0042 * @subpackage Annotation 0043 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0044 * @license http://framework.zend.com/license/new-bsd New BSD License 0045 */ 0046 class Zend_Pdf_Annotation_Link extends Zend_Pdf_Annotation 0047 { 0048 /** 0049 * Annotation object constructor 0050 * 0051 * @throws Zend_Pdf_Exception 0052 */ 0053 public function __construct(Zend_Pdf_Element $annotationDictionary) 0054 { 0055 if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) { 0056 // require_once 'Zend/Pdf/Exception.php'; 0057 throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.'); 0058 } 0059 0060 if ($annotationDictionary->Subtype === null || 0061 $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME || 0062 $annotationDictionary->Subtype->value != 'Link') { 0063 // require_once 'Zend/Pdf/Exception.php'; 0064 throw new Zend_Pdf_Exception('Subtype => Link entry is requires'); 0065 } 0066 0067 parent::__construct($annotationDictionary); 0068 } 0069 0070 /** 0071 * Create link annotation object 0072 * 0073 * @param float $x1 0074 * @param float $y1 0075 * @param float $x2 0076 * @param float $y2 0077 * @param Zend_Pdf_Target|string $target 0078 * @return Zend_Pdf_Annotation_Link 0079 * @throws Zend_Pdf_Exception 0080 */ 0081 public static function create($x1, $y1, $x2, $y2, $target) 0082 { 0083 if (is_string($target)) { 0084 // require_once 'Zend/Pdf/Destination/Named.php'; 0085 $target = Zend_Pdf_Destination_Named::create($target); 0086 } 0087 if (!$target instanceof Zend_Pdf_Target) { 0088 // require_once 'Zend/Pdf/Exception.php'; 0089 throw new Zend_Pdf_Exception('$target parameter must be a Zend_Pdf_Target object or a string.'); 0090 } 0091 0092 $annotationDictionary = new Zend_Pdf_Element_Dictionary(); 0093 0094 $annotationDictionary->Type = new Zend_Pdf_Element_Name('Annot'); 0095 $annotationDictionary->Subtype = new Zend_Pdf_Element_Name('Link'); 0096 0097 $rectangle = new Zend_Pdf_Element_Array(); 0098 $rectangle->items[] = new Zend_Pdf_Element_Numeric($x1); 0099 $rectangle->items[] = new Zend_Pdf_Element_Numeric($y1); 0100 $rectangle->items[] = new Zend_Pdf_Element_Numeric($x2); 0101 $rectangle->items[] = new Zend_Pdf_Element_Numeric($y2); 0102 $annotationDictionary->Rect = $rectangle; 0103 0104 if ($target instanceof Zend_Pdf_Destination) { 0105 $annotationDictionary->Dest = $target->getResource(); 0106 } else { 0107 $annotationDictionary->A = $target->getResource(); 0108 } 0109 0110 return new Zend_Pdf_Annotation_Link($annotationDictionary); 0111 } 0112 0113 /** 0114 * Set link annotation destination 0115 * 0116 * @param Zend_Pdf_Target|string $target 0117 * @return Zend_Pdf_Annotation_Link 0118 */ 0119 public function setDestination($target) 0120 { 0121 if (is_string($target)) { 0122 // require_once 'Zend/Pdf/Destination/Named.php'; 0123 $destination = Zend_Pdf_Destination_Named::create($target); 0124 } 0125 if (!$target instanceof Zend_Pdf_Target) { 0126 // require_once 'Zend/Pdf/Exception.php'; 0127 throw new Zend_Pdf_Exception('$target parameter must be a Zend_Pdf_Target object or a string.'); 0128 } 0129 0130 $this->_annotationDictionary->touch(); 0131 $this->_annotationDictionary->Dest = $destination->getResource(); 0132 if ($target instanceof Zend_Pdf_Destination) { 0133 $this->_annotationDictionary->Dest = $target->getResource(); 0134 $this->_annotationDictionary->A = null; 0135 } else { 0136 $this->_annotationDictionary->Dest = null; 0137 $this->_annotationDictionary->A = $target->getResource(); 0138 } 0139 0140 return $this; 0141 } 0142 0143 /** 0144 * Get link annotation destination 0145 * 0146 * @return Zend_Pdf_Target|null 0147 */ 0148 public function getDestination() 0149 { 0150 if ($this->_annotationDictionary->Dest === null && 0151 $this->_annotationDictionary->A === null) { 0152 return null; 0153 } 0154 0155 if ($this->_annotationDictionary->Dest !== null) { 0156 // require_once 'Zend/Pdf/Destination.php'; 0157 return Zend_Pdf_Destination::load($this->_annotationDictionary->Dest); 0158 } else { 0159 // require_once 'Zend/Pdf/Action.php'; 0160 return Zend_Pdf_Action::load($this->_annotationDictionary->A); 0161 } 0162 } 0163 }