FitRectangle.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 /FitR left bottom right top]
  26. *
  27. * Display the page designated by page, with its contents magnified just enough
  28. * to fit the rectangle specified by the coordinates left, bottom, right, and top
  29. * entirely within the window both horizontally and vertically. If the required
  30. * horizontal and vertical magnification factors are different, use the smaller of
  31. * the two, centering the rectangle within the window in the other dimension.
  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_FitRectangle 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 $bottom Bottom edge of displayed page
  48. * @param float $right Right edge of displayed page
  49. * @param float $top Top edge of displayed page
  50. * @return Zend_Pdf_Destination_FitRectangle
  51. * @throws Zend_Pdf_Exception
  52. */
  53. public static function create($page, $left, $bottom, $right, $top)
  54. {
  55. $destinationArray = new Zend_Pdf_Element_Array();
  56. if ($page instanceof Zend_Pdf_Element) {
  57. if ($page->getType() == Zend_Pdf_Element::TYPE_NUMERIC || $page->getType() == Zend_Pdf_Element::TYPE_DICTIONARY) {
  58. // Page destination entry is a page number or page dictionary object
  59. $destinationArray->items[] = $page;
  60. } else {
  61. require_once 'Zend/Pdf/Exception.php';
  62. throw new Zend_Pdf_Exception('Page entry must be a Zend_Pdf_Page object, page number or page dictionary reference.');
  63. }
  64. } else if ($page instanceof Zend_Pdf_Page) {
  65. $destinationArray->items[] = $page->getPageDictionary();
  66. } else if (is_integer($page)) {
  67. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($page);
  68. } else {
  69. require_once 'Zend/Pdf/Exception.php';
  70. throw new Zend_Pdf_Exception('Page entry must be a Zend_Pdf_Page object, page number or page dictionary reference.');
  71. }
  72. $destinationArray->items[] = new Zend_Pdf_Element_Name('FitR');
  73. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($left);
  74. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($bottom);
  75. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($right);
  76. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($top);
  77. return new Zend_Pdf_Destination_FitRectangle($destinationArray);
  78. }
  79. /**
  80. * Get left edge of the displayed page
  81. *
  82. * @return float
  83. */
  84. public function getLeftEdge()
  85. {
  86. return $this->_destinationArray->items[2]->value;
  87. }
  88. /**
  89. * Set left edge of the displayed page
  90. *
  91. * @param float $left
  92. * @return Zend_Pdf_Action_FitRectangle
  93. */
  94. public function setLeftEdge($left)
  95. {
  96. $this->_destinationArray->items[2] = new Zend_Pdf_Element_Numeric($left);
  97. return $this;
  98. }
  99. /**
  100. * Get bottom edge of the displayed page
  101. *
  102. * @return float
  103. */
  104. public function getBottomEdge()
  105. {
  106. return $this->_destinationArray->items[3]->value;
  107. }
  108. /**
  109. * Set bottom edge of the displayed page
  110. *
  111. * @param float $bottom
  112. * @return Zend_Pdf_Action_FitRectangle
  113. */
  114. public function setBottomEdge($bottom)
  115. {
  116. $this->_destinationArray->items[3] = new Zend_Pdf_Element_Numeric($bottom);
  117. return $this;
  118. }
  119. /**
  120. * Get right edge of the displayed page
  121. *
  122. * @return float
  123. */
  124. public function getRightEdge()
  125. {
  126. return $this->_destinationArray->items[4]->value;
  127. }
  128. /**
  129. * Set right edge of the displayed page
  130. *
  131. * @param float $right
  132. * @return Zend_Pdf_Action_FitRectangle
  133. */
  134. public function setRightEdge($right)
  135. {
  136. $this->_destinationArray->items[4] = new Zend_Pdf_Element_Numeric($right);
  137. return $this;
  138. }
  139. /**
  140. * Get top edge of the displayed page
  141. *
  142. * @return float
  143. */
  144. public function getTopEdge()
  145. {
  146. return $this->_destinationArray->items[5]->value;
  147. }
  148. /**
  149. * Set top edge of the displayed page
  150. *
  151. * @param float $top
  152. * @return Zend_Pdf_Action_FitRectangle
  153. */
  154. public function setTopEdge($top)
  155. {
  156. $this->_destinationArray->items[5] = new Zend_Pdf_Element_Numeric($top);
  157. return $this;
  158. }
  159. }