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 Actions 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/Dictionary.php'; 0025 // require_once 'Zend/Pdf/Element/Name.php'; 0026 // require_once 'Zend/Pdf/Element/String.php'; 0027 // require_once 'Zend/Pdf/Element/Boolean.php'; 0028 0029 0030 /** Zend_Pdf_Action */ 0031 // require_once 'Zend/Pdf/Action.php'; 0032 0033 0034 /** 0035 * PDF 'Resolve a uniform resource identifier' action 0036 * 0037 * A URI action causes a URI to be resolved. 0038 * 0039 * @package Zend_Pdf 0040 * @subpackage Actions 0041 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0042 * @license http://framework.zend.com/license/new-bsd New BSD License 0043 */ 0044 class Zend_Pdf_Action_URI extends Zend_Pdf_Action 0045 { 0046 /** 0047 * Object constructor 0048 * 0049 * @param Zend_Pdf_Element_Dictionary $dictionary 0050 * @param SplObjectStorage $processedActions list of already processed action dictionaries, used to avoid cyclic references 0051 * @throws Zend_Pdf_Exception 0052 */ 0053 public function __construct(Zend_Pdf_Element $dictionary, SplObjectStorage $processedActions) 0054 { 0055 parent::__construct($dictionary, $processedActions); 0056 0057 if ($dictionary->URI === null) { 0058 // require_once 'Zend/Pdf/Exception.php'; 0059 throw new Zend_Pdf_Exception('URI action dictionary entry is required'); 0060 } 0061 } 0062 0063 /** 0064 * Validate URI 0065 * 0066 * @param string $uri 0067 * @return true 0068 * @throws Zend_Pdf_Exception 0069 */ 0070 protected static function _validateUri($uri) 0071 { 0072 $scheme = parse_url((string)$uri, PHP_URL_SCHEME); 0073 if ($scheme === false || $scheme === null) { 0074 // require_once 'Zend/Pdf/Exception.php'; 0075 throw new Zend_Pdf_Exception('Invalid URI'); 0076 } 0077 } 0078 0079 /** 0080 * Create new Zend_Pdf_Action_URI object using specified uri 0081 * 0082 * @param string $uri The URI to resolve, encoded in 7-bit ASCII 0083 * @param boolean $isMap A flag specifying whether to track the mouse position when the URI is resolved 0084 * @return Zend_Pdf_Action_URI 0085 */ 0086 public static function create($uri, $isMap = false) 0087 { 0088 self::_validateUri($uri); 0089 0090 $dictionary = new Zend_Pdf_Element_Dictionary(); 0091 $dictionary->Type = new Zend_Pdf_Element_Name('Action'); 0092 $dictionary->S = new Zend_Pdf_Element_Name('URI'); 0093 $dictionary->Next = null; 0094 $dictionary->URI = new Zend_Pdf_Element_String($uri); 0095 if ($isMap) { 0096 $dictionary->IsMap = new Zend_Pdf_Element_Boolean(true); 0097 } 0098 0099 return new Zend_Pdf_Action_URI($dictionary, new SplObjectStorage()); 0100 } 0101 0102 /** 0103 * Set URI to resolve 0104 * 0105 * @param string $uri The uri to resolve, encoded in 7-bit ASCII. 0106 * @return Zend_Pdf_Action_URI 0107 */ 0108 public function setUri($uri) 0109 { 0110 $this->_validateUri($uri); 0111 0112 $this->_actionDictionary->touch(); 0113 $this->_actionDictionary->URI = new Zend_Pdf_Element_String($uri); 0114 0115 return $this; 0116 } 0117 0118 /** 0119 * Get URI to resolve 0120 * 0121 * @return string 0122 */ 0123 public function getUri() 0124 { 0125 return $this->_actionDictionary->URI->value; 0126 } 0127 0128 /** 0129 * Set IsMap property 0130 * 0131 * If the IsMap flag is true and the user has triggered the URI action by clicking 0132 * an annotation, the coordinates of the mouse position at the time the action is 0133 * performed should be transformed from device space to user space and then offset 0134 * relative to the upper-left corner of the annotation rectangle. 0135 * 0136 * @param boolean $isMap A flag specifying whether to track the mouse position when the URI is resolved 0137 * @return Zend_Pdf_Action_URI 0138 */ 0139 public function setIsMap($isMap) 0140 { 0141 $this->_actionDictionary->touch(); 0142 0143 if ($isMap) { 0144 $this->_actionDictionary->IsMap = new Zend_Pdf_Element_Boolean(true); 0145 } else { 0146 $this->_actionDictionary->IsMap = null; 0147 } 0148 0149 return $this; 0150 } 0151 0152 /** 0153 * Get IsMap property 0154 * 0155 * If the IsMap flag is true and the user has triggered the URI action by clicking 0156 * an annotation, the coordinates of the mouse position at the time the action is 0157 * performed should be transformed from device space to user space and then offset 0158 * relative to the upper-left corner of the annotation rectangle. 0159 * 0160 * @return boolean 0161 */ 0162 public function getIsMap() 0163 { 0164 return $this->_actionDictionary->IsMap !== null && 0165 $this->_actionDictionary->IsMap->value; 0166 } 0167 }