/framework/vendor/zend/Zend/Pdf/Destination/Zoom.php

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