Zoom.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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_Destination */
  23. require_once 'Zend/Pdf/Destination.php';
  24. /**
  25. * Destination array: [page /XYZ left top zoom]
  26. *
  27. * Display the page designated by page, with the coordinates (left, top) positioned
  28. * at the upper-left corner of the window and the contents of the page
  29. * magnified by the factor zoom. A null value for any of the parameters left, top,
  30. * or zoom specifies that the current value of that parameter is to be retained unchanged.
  31. * A zoom value of 0 has the same meaning as a null value.
  32. *
  33. * @package Zend_Pdf
  34. * @subpackage Destination
  35. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. */
  38. class Zend_Pdf_Destination_Zoom extends Zend_Pdf_Destination
  39. {
  40. /**
  41. * Create destination object
  42. *
  43. * @param Zend_Pdf_Page|Zend_Pdf_Element|integer $page Page object,
  44. * page number (integer or Zend_Pdf_Element_Numeric object) or
  45. * page dictionary object
  46. * @param float $left Left edge of displayed page
  47. * @param float $top Top edge of displayed page
  48. * @param float $zoom Zoom factor
  49. * @return Zend_Pdf_Destination_Zoom
  50. * @throws Zend_Pdf_Exception
  51. */
  52. public static function create($page, $left = null, $top = null, $zoom = null)
  53. {
  54. $destinationArray = new Zend_Pdf_Element_Array();
  55. if ($page instanceof Zend_Pdf_Element) {
  56. if ($page->getType() == Zend_Pdf_Element::TYPE_NUMERIC || $page->getType() == Zend_Pdf_Element::TYPE_DICTIONARY) {
  57. // Page destination entry is a page number or page dictionary object
  58. $destinationArray->items[] = $page;
  59. } else {
  60. require_once 'Zend/Pdf/Exception.php';
  61. throw new Zend_Pdf_Exception('Page entry must be a Zend_Pdf_Page object, page number or page dictionary reference.');
  62. }
  63. } else if ($page instanceof Zend_Pdf_Page) {
  64. $destinationArray->items[] = $page->getPageDictionary();
  65. } else if (is_integer($page)) {
  66. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($page);
  67. } else {
  68. require_once 'Zend/Pdf/Exception.php';
  69. throw new Zend_Pdf_Exception('Page entry must be a Zend_Pdf_Page object, page number or page dictionary reference.');
  70. }
  71. $destinationArray->items[] = new Zend_Pdf_Element_Name('XYZ');
  72. if ($left === null) {
  73. $destinationArray->items[] = new Zend_Pdf_Element_Null();
  74. } else {
  75. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($left);
  76. }
  77. if ($top === null) {
  78. $destinationArray->items[] = new Zend_Pdf_Element_Null();
  79. } else {
  80. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($top);
  81. }
  82. if ($zoom === null) {
  83. $destinationArray->items[] = new Zend_Pdf_Element_Null();
  84. } else {
  85. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($zoom);
  86. }
  87. return new Zend_Pdf_Destination_Zoom($destinationArray);
  88. }
  89. /**
  90. * Get left edge of the displayed page (null means viewer application 'current value')
  91. *
  92. * @return float
  93. */
  94. public function getLeftEdge()
  95. {
  96. return $this->_destinationArray->items[2]->value;
  97. }
  98. /**
  99. * Set left edge of the displayed page (null means viewer application 'current value')
  100. *
  101. * @param float $left
  102. * @return Zend_Pdf_Action_Zoom
  103. */
  104. public function setLeftEdge($left)
  105. {
  106. if ($left === null) {
  107. $this->_destinationArray->items[2] = new Zend_Pdf_Element_Null();
  108. } else {
  109. $this->_destinationArray->items[2] = new Zend_Pdf_Element_Numeric($left);
  110. }
  111. return $this;
  112. }
  113. /**
  114. * Get top edge of the displayed page (null means viewer application 'current value')
  115. *
  116. * @return float
  117. */
  118. public function getTopEdge()
  119. {
  120. return $this->_destinationArray->items[3]->value;
  121. }
  122. /**
  123. * Set top edge of the displayed page (null means viewer application 'current viewer')
  124. *
  125. * @param float $top
  126. * @return Zend_Pdf_Action_Zoom
  127. */
  128. public function setTopEdge($top)
  129. {
  130. if ($top === null) {
  131. $this->_destinationArray->items[3] = new Zend_Pdf_Element_Null();
  132. } else {
  133. $this->_destinationArray->items[3] = new Zend_Pdf_Element_Numeric($top);
  134. }
  135. return $this;
  136. }
  137. /**
  138. * Get ZoomFactor of the displayed page (null or 0 means viewer application 'current value')
  139. *
  140. * @return float
  141. */
  142. public function getZoomFactor()
  143. {
  144. return $this->_destinationArray->items[4]->value;
  145. }
  146. /**
  147. * Set ZoomFactor of the displayed page (null or 0 means viewer application 'current viewer')
  148. *
  149. * @param float $zoom
  150. * @return Zend_Pdf_Action_Zoom
  151. */
  152. public function setZoomFactor($zoom)
  153. {
  154. if ($zoom === null) {
  155. $this->_destinationArray->items[4] = new Zend_Pdf_Element_Null();
  156. } else {
  157. $this->_destinationArray->items[4] = new Zend_Pdf_Element_Numeric($zoom);
  158. }
  159. return $this;
  160. }
  161. }