2
0

FitRectangle.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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_Explicit */
  23. require_once 'Zend/Pdf/Destination/Explicit.php';
  24. /**
  25. * Zend_Pdf_Destination_FitRectangle explicit detination
  26. *
  27. * Destination array: [page /FitR left bottom right top]
  28. *
  29. * Display the page designated by page, with its contents magnified just enough
  30. * to fit the rectangle specified by the coordinates left, bottom, right, and top
  31. * entirely within the window both horizontally and vertically. If the required
  32. * horizontal and vertical magnification factors are different, use the smaller of
  33. * the two, centering the rectangle within the window in the other dimension.
  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_FitRectangle 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 $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_Page) {
  57. $destinationArray->items[] = $page->getPageDictionary();
  58. } else if (is_integer($page)) {
  59. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($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 or a page number.');
  63. }
  64. $destinationArray->items[] = new Zend_Pdf_Element_Name('FitR');
  65. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($left);
  66. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($bottom);
  67. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($right);
  68. $destinationArray->items[] = new Zend_Pdf_Element_Numeric($top);
  69. return new Zend_Pdf_Destination_FitRectangle($destinationArray);
  70. }
  71. /**
  72. * Get left edge of the displayed page
  73. *
  74. * @return float
  75. */
  76. public function getLeftEdge()
  77. {
  78. return $this->_destinationArray->items[2]->value;
  79. }
  80. /**
  81. * Set left edge of the displayed page
  82. *
  83. * @param float $left
  84. * @return Zend_Pdf_Action_FitRectangle
  85. */
  86. public function setLeftEdge($left)
  87. {
  88. $this->_destinationArray->items[2] = new Zend_Pdf_Element_Numeric($left);
  89. return $this;
  90. }
  91. /**
  92. * Get bottom edge of the displayed page
  93. *
  94. * @return float
  95. */
  96. public function getBottomEdge()
  97. {
  98. return $this->_destinationArray->items[3]->value;
  99. }
  100. /**
  101. * Set bottom edge of the displayed page
  102. *
  103. * @param float $bottom
  104. * @return Zend_Pdf_Action_FitRectangle
  105. */
  106. public function setBottomEdge($bottom)
  107. {
  108. $this->_destinationArray->items[3] = new Zend_Pdf_Element_Numeric($bottom);
  109. return $this;
  110. }
  111. /**
  112. * Get right edge of the displayed page
  113. *
  114. * @return float
  115. */
  116. public function getRightEdge()
  117. {
  118. return $this->_destinationArray->items[4]->value;
  119. }
  120. /**
  121. * Set right edge of the displayed page
  122. *
  123. * @param float $right
  124. * @return Zend_Pdf_Action_FitRectangle
  125. */
  126. public function setRightEdge($right)
  127. {
  128. $this->_destinationArray->items[4] = new Zend_Pdf_Element_Numeric($right);
  129. return $this;
  130. }
  131. /**
  132. * Get top edge of the displayed page
  133. *
  134. * @return float
  135. */
  136. public function getTopEdge()
  137. {
  138. return $this->_destinationArray->items[5]->value;
  139. }
  140. /**
  141. * Set top edge of the displayed page
  142. *
  143. * @param float $top
  144. * @return Zend_Pdf_Action_FitRectangle
  145. */
  146. public function setTopEdge($top)
  147. {
  148. $this->_destinationArray->items[5] = new Zend_Pdf_Element_Numeric($top);
  149. return $this;
  150. }
  151. }