Destination.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 Destination
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** Zend_Pdf_ElementFactory */
  23. require_once 'Zend/Pdf/ElementFactory.php';
  24. /** Zend_Pdf_Page */
  25. require_once 'Zend/Pdf/Page.php';
  26. /**
  27. * Abstract PDF explicit destination representation class
  28. *
  29. * @package Zend_Pdf
  30. * @subpackage Destination
  31. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. abstract class Zend_Pdf_Destination
  35. {
  36. /**
  37. * Destination description array
  38. *
  39. * @var Zend_Pdf_Element_Array
  40. */
  41. protected $_destinationArray;
  42. /**
  43. * True if it's a remote destination
  44. *
  45. * @var boolean
  46. */
  47. protected $_isRemote;
  48. /**
  49. * Destination object constructor
  50. *
  51. * @param Zend_Pdf_Element $destinationArray
  52. * @throws Zend_Pdf_Exception
  53. */
  54. public function __construct(Zend_Pdf_Element $destinationArray)
  55. {
  56. if ($destinationArray->getType() != Zend_Pdf_Element::TYPE_ARRAY) {
  57. require_once 'Zend/Pdf/Exception.php';
  58. throw new Zend_Pdf_Exception('$destinationArray mast be direct or indirect array object.');
  59. }
  60. $this->_destinationArray = $destinationArray;
  61. if (count($this->_destinationArray->items) == 0) {
  62. require_once 'Zend/Pdf/Exception.php';
  63. throw new Zend_Pdf_Exception('Destination array must contain a page reference.');
  64. }
  65. if (count($this->_destinationArray->items) == 1) {
  66. require_once 'Zend/Pdf/Exception.php';
  67. throw new Zend_Pdf_Exception('Destination array must contain a destination type name.');
  68. }
  69. switch ($this->_destinationArray->items[0]->getType()) {
  70. case Zend_Pdf_Element::TYPE_NUMERIC:
  71. $this->_isRemote = true;
  72. break;
  73. case Zend_Pdf_Element::TYPE_DICTIONARY:
  74. $this->_isRemote = false;
  75. break;
  76. default:
  77. require_once 'Zend/Pdf/Exception.php';
  78. throw new Zend_Pdf_Exception('Destination target must be a page number or page dictionary object.');
  79. break;
  80. }
  81. }
  82. public static function load(Zend_Pdf_Element $destinationArray)
  83. {
  84. if ($destinationArray->getType() != Zend_Pdf_Element::TYPE_ARRAY) {
  85. require_once 'Zend/Pdf/Exception.php';
  86. throw new Zend_Pdf_Exception('$destinationArray mast be direct or indirect array object.');
  87. }
  88. if (count($destinationArray->items) == 0) {
  89. require_once 'Zend/Pdf/Exception.php';
  90. throw new Zend_Pdf_Exception('Destination array must contain a page reference.');
  91. }
  92. if (count($destinationArray->items) == 1) {
  93. require_once 'Zend/Pdf/Exception.php';
  94. throw new Zend_Pdf_Exception('Destination array must contain a destination type name.');
  95. }
  96. switch ($destinationArray->items[1]->value) {
  97. case 'XYZ':
  98. require_once 'Zend/Pdf/Destination/Zoom.php';
  99. return new Zend_Pdf_Destination_Zoom($destinationArray);
  100. break;
  101. case 'Fit':
  102. require_once 'Zend/Pdf/Destination/Fit.php';
  103. return new Zend_Pdf_Destination_Fit($destinationArray);
  104. break;
  105. case 'FitH':
  106. require_once 'Zend/Pdf/Destination/FitHorizontally.php';
  107. return new Zend_Pdf_Destination_FitHorizontally($destinationArray);
  108. break;
  109. case 'FitV':
  110. require_once 'Zend/Pdf/Destination/FitVertically.php';
  111. return new Zend_Pdf_Destination_FitVertically($destinationArray);
  112. break;
  113. case 'FitR':
  114. require_once 'Zend/Pdf/Destination/FitRectangle.php';
  115. return new Zend_Pdf_Destination_FitRectangle($destinationArray);
  116. break;
  117. case 'FitB':
  118. require_once 'Zend/Pdf/Destination/FitBoundingBox.php';
  119. return new Zend_Pdf_Destination_FitBoundingBox($destinationArray);
  120. break;
  121. case 'FitBH':
  122. require_once 'Zend/Pdf/Destination/FitBoundingBoxHorizontally.php';
  123. return new Zend_Pdf_Destination_FitBoundingBoxHorizontally($destinationArray);
  124. break;
  125. case 'FitBV':
  126. require_once 'Zend/Pdf/Destination/FitBoundingBoxVertically.php';
  127. return new Zend_Pdf_Destination_FitBoundingBoxVertically($destinationArray);
  128. break;
  129. default:
  130. require_once 'Zend/Pdf/Destination/Unknown.php';
  131. return new Zend_Pdf_Destination_Unknown($destinationArray);
  132. break;
  133. }
  134. }
  135. /**
  136. * Returns true if it's a remote destination
  137. *
  138. * @return boolean
  139. */
  140. public function isRemote()
  141. {
  142. return $this->_isRemote;
  143. }
  144. /**
  145. * Returns destination target
  146. *
  147. * Returns page number for remote destinations and
  148. * page dictionary object reference otherwise
  149. *
  150. * @return integer|Zend_Pdf_Element_Dictionary
  151. */
  152. public function getTarget()
  153. {
  154. if ($this->isRemote()) {
  155. return $this->_destinationArray->items[0]->value;
  156. } else {
  157. return $this->_destinationArray->items[0];
  158. }
  159. }
  160. /**
  161. * Get destination array object
  162. *
  163. * @internal
  164. * @return Zend_Pdf_Element_Array|Zend_Pdf_Element_Object|Zend_Pdf_Element_Reference
  165. */
  166. public function getDestinationArray()
  167. {
  168. return $this->_destinationArray;
  169. }
  170. }