File indexing completed on 2024-05-26 06:03:16

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Pdf
0017  * @subpackage Destination
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 
0024 /** Internally used classes */
0025 // require_once 'Zend/Pdf/Element/Array.php';
0026 // require_once 'Zend/Pdf/Element/Name.php';
0027 // require_once 'Zend/Pdf/Element/Numeric.php';
0028 
0029 
0030 /** Zend_Pdf_Destination_Explicit */
0031 // require_once 'Zend/Pdf/Destination/Explicit.php';
0032 
0033 /**
0034  * Zend_Pdf_Destination_FitRectangle explicit detination
0035  *
0036  * Destination array: [page /FitR left bottom right top]
0037  *
0038  * Display the page designated by page, with its contents magnified just enough
0039  * to fit the rectangle specified by the coordinates left, bottom, right, and top
0040  * entirely within the window both horizontally and vertically. If the required
0041  * horizontal and vertical magnification factors are different, use the smaller of
0042  * the two, centering the rectangle within the window in the other dimension.
0043  *
0044  * @package    Zend_Pdf
0045  * @subpackage Destination
0046  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0047  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0048  */
0049 class Zend_Pdf_Destination_FitRectangle extends Zend_Pdf_Destination_Explicit
0050 {
0051     /**
0052      * Create destination object
0053      *
0054      * @param Zend_Pdf_Page|integer $page  Page object or page number
0055      * @param float $left    Left edge of displayed page
0056      * @param float $bottom  Bottom edge of displayed page
0057      * @param float $right   Right edge of displayed page
0058      * @param float $top     Top edge of displayed page
0059      * @return Zend_Pdf_Destination_FitRectangle
0060      * @throws Zend_Pdf_Exception
0061      */
0062     public static function create($page, $left, $bottom, $right, $top)
0063     {
0064         $destinationArray = new Zend_Pdf_Element_Array();
0065 
0066         if ($page instanceof Zend_Pdf_Page) {
0067             $destinationArray->items[] = $page->getPageDictionary();
0068         } else if (is_integer($page)) {
0069             $destinationArray->items[] = new Zend_Pdf_Element_Numeric($page);
0070         } else {
0071             // require_once 'Zend/Pdf/Exception.php';
0072             throw new Zend_Pdf_Exception('Page entry must be a Zend_Pdf_Page object or a page number.');
0073         }
0074 
0075         $destinationArray->items[] = new Zend_Pdf_Element_Name('FitR');
0076         $destinationArray->items[] = new Zend_Pdf_Element_Numeric($left);
0077         $destinationArray->items[] = new Zend_Pdf_Element_Numeric($bottom);
0078         $destinationArray->items[] = new Zend_Pdf_Element_Numeric($right);
0079         $destinationArray->items[] = new Zend_Pdf_Element_Numeric($top);
0080 
0081         return new Zend_Pdf_Destination_FitRectangle($destinationArray);
0082     }
0083 
0084     /**
0085      * Get left edge of the displayed page
0086      *
0087      * @return float
0088      */
0089     public function getLeftEdge()
0090     {
0091         return $this->_destinationArray->items[2]->value;
0092     }
0093 
0094     /**
0095      * Set left edge of the displayed page
0096      *
0097      * @param float $left
0098      * @return Zend_Pdf_Action_FitRectangle
0099      */
0100     public function setLeftEdge($left)
0101     {
0102         $this->_destinationArray->items[2] = new Zend_Pdf_Element_Numeric($left);
0103         return $this;
0104     }
0105 
0106     /**
0107      * Get bottom edge of the displayed page
0108      *
0109      * @return float
0110      */
0111     public function getBottomEdge()
0112     {
0113         return $this->_destinationArray->items[3]->value;
0114     }
0115 
0116     /**
0117      * Set bottom edge of the displayed page
0118      *
0119      * @param float $bottom
0120      * @return Zend_Pdf_Action_FitRectangle
0121      */
0122     public function setBottomEdge($bottom)
0123     {
0124         $this->_destinationArray->items[3] = new Zend_Pdf_Element_Numeric($bottom);
0125         return $this;
0126     }
0127 
0128     /**
0129      * Get right edge of the displayed page
0130      *
0131      * @return float
0132      */
0133     public function getRightEdge()
0134     {
0135         return $this->_destinationArray->items[4]->value;
0136     }
0137 
0138     /**
0139      * Set right edge of the displayed page
0140      *
0141      * @param float $right
0142      * @return Zend_Pdf_Action_FitRectangle
0143      */
0144     public function setRightEdge($right)
0145     {
0146         $this->_destinationArray->items[4] = new Zend_Pdf_Element_Numeric($right);
0147         return $this;
0148     }
0149 
0150     /**
0151      * Get top edge of the displayed page
0152      *
0153      * @return float
0154      */
0155     public function getTopEdge()
0156     {
0157         return $this->_destinationArray->items[5]->value;
0158     }
0159 
0160     /**
0161      * Set top edge of the displayed page
0162      *
0163      * @param float $top
0164      * @return Zend_Pdf_Action_FitRectangle
0165      */
0166     public function setTopEdge($top)
0167     {
0168         $this->_destinationArray->items[5] = new Zend_Pdf_Element_Numeric($top);
0169         return $this;
0170     }
0171 }