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.

167 lines
5.2 KiB

12 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 Actions
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: URI.php 24593 2012-01-05 20:35:02Z matthew $
  21. */
  22. /** Internally used classes */
  23. // require_once 'Zend/Pdf/Element/Dictionary.php';
  24. // require_once 'Zend/Pdf/Element/Name.php';
  25. // require_once 'Zend/Pdf/Element/String.php';
  26. // require_once 'Zend/Pdf/Element/Boolean.php';
  27. /** Zend_Pdf_Action */
  28. // require_once 'Zend/Pdf/Action.php';
  29. /**
  30. * PDF 'Resolve a uniform resource identifier' action
  31. *
  32. * A URI action causes a URI to be resolved.
  33. *
  34. * @package Zend_Pdf
  35. * @subpackage Actions
  36. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. */
  39. class Zend_Pdf_Action_URI extends Zend_Pdf_Action
  40. {
  41. /**
  42. * Object constructor
  43. *
  44. * @param Zend_Pdf_Element_Dictionary $dictionary
  45. * @param SplObjectStorage $processedActions list of already processed action dictionaries, used to avoid cyclic references
  46. * @throws Zend_Pdf_Exception
  47. */
  48. public function __construct(Zend_Pdf_Element $dictionary, SplObjectStorage $processedActions)
  49. {
  50. parent::__construct($dictionary, $processedActions);
  51. if ($dictionary->URI === null) {
  52. // require_once 'Zend/Pdf/Exception.php';
  53. throw new Zend_Pdf_Exception('URI action dictionary entry is required');
  54. }
  55. }
  56. /**
  57. * Validate URI
  58. *
  59. * @param string $uri
  60. * @return true
  61. * @throws Zend_Pdf_Exception
  62. */
  63. protected static function _validateUri($uri)
  64. {
  65. $scheme = parse_url((string)$uri, PHP_URL_SCHEME);
  66. if ($scheme === false || $scheme === null) {
  67. // require_once 'Zend/Pdf/Exception.php';
  68. throw new Zend_Pdf_Exception('Invalid URI');
  69. }
  70. }
  71. /**
  72. * Create new Zend_Pdf_Action_URI object using specified uri
  73. *
  74. * @param string $uri The URI to resolve, encoded in 7-bit ASCII
  75. * @param boolean $isMap A flag specifying whether to track the mouse position when the URI is resolved
  76. * @return Zend_Pdf_Action_URI
  77. */
  78. public static function create($uri, $isMap = false)
  79. {
  80. self::_validateUri($uri);
  81. $dictionary = new Zend_Pdf_Element_Dictionary();
  82. $dictionary->Type = new Zend_Pdf_Element_Name('Action');
  83. $dictionary->S = new Zend_Pdf_Element_Name('URI');
  84. $dictionary->Next = null;
  85. $dictionary->URI = new Zend_Pdf_Element_String($uri);
  86. if ($isMap) {
  87. $dictionary->IsMap = new Zend_Pdf_Element_Boolean(true);
  88. }
  89. return new Zend_Pdf_Action_URI($dictionary, new SplObjectStorage());
  90. }
  91. /**
  92. * Set URI to resolve
  93. *
  94. * @param string $uri The uri to resolve, encoded in 7-bit ASCII.
  95. * @return Zend_Pdf_Action_URI
  96. */
  97. public function setUri($uri)
  98. {
  99. $this->_validateUri($uri);
  100. $this->_actionDictionary->touch();
  101. $this->_actionDictionary->URI = new Zend_Pdf_Element_String($uri);
  102. return $this;
  103. }
  104. /**
  105. * Get URI to resolve
  106. *
  107. * @return string
  108. */
  109. public function getUri()
  110. {
  111. return $this->_actionDictionary->URI->value;
  112. }
  113. /**
  114. * Set IsMap property
  115. *
  116. * If the IsMap flag is true and the user has triggered the URI action by clicking
  117. * an annotation, the coordinates of the mouse position at the time the action is
  118. * performed should be transformed from device space to user space and then offset
  119. * relative to the upper-left corner of the annotation rectangle.
  120. *
  121. * @param boolean $isMap A flag specifying whether to track the mouse position when the URI is resolved
  122. * @return Zend_Pdf_Action_URI
  123. */
  124. public function setIsMap($isMap)
  125. {
  126. $this->_actionDictionary->touch();
  127. if ($isMap) {
  128. $this->_actionDictionary->IsMap = new Zend_Pdf_Element_Boolean(true);
  129. } else {
  130. $this->_actionDictionary->IsMap = null;
  131. }
  132. return $this;
  133. }
  134. /**
  135. * Get IsMap property
  136. *
  137. * If the IsMap flag is true and the user has triggered the URI action by clicking
  138. * an annotation, the coordinates of the mouse position at the time the action is
  139. * performed should be transformed from device space to user space and then offset
  140. * relative to the upper-left corner of the annotation rectangle.
  141. *
  142. * @return boolean
  143. */
  144. public function getIsMap()
  145. {
  146. return $this->_actionDictionary->IsMap !== null &&
  147. $this->_actionDictionary->IsMap->value;
  148. }
  149. }