/tine20/library/Zend/Pdf/Destination/Zoom.php

https://gitlab.com/rsilveira1987/Expresso · PHP · 171 lines · 73 code · 18 blank · 80 comment · 16 complexity · e74ec5ad78d027141a13c2fd80f03b21 MD5 · raw file

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