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