| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Pdf
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- /** Zend_Pdf_Destination */
- require_once 'Zend/Pdf/Destination.php';
- /** Zend_Pdf_Action */
- require_once 'Zend/Pdf/ElementFactory.php';
- /** Zend_Pdf */
- require_once 'Zend/Pdf.php';
- /**
- * @category Zend
- * @package Zend_Pdf
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Pdf
- */
- class Zend_Pdf_DestinationTest extends PHPUnit_Framework_TestCase
- {
- public function setUp()
- {
- date_default_timezone_set('GMT');
- }
- public function testLoad()
- {
- $pdf = new Zend_Pdf();
- $page1 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
- $page2 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
- // Zend_Pdf_Destination_Zoom
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('XYZ');
- $destArray->items[] = new Zend_Pdf_Element_Numeric(0); // left
- $destArray->items[] = new Zend_Pdf_Element_Numeric(842); // top
- $destArray->items[] = new Zend_Pdf_Element_Numeric(1); // zoom
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_Zoom);
- $this->assertEquals($destination->getResource()->toString(), '[4 0 R /XYZ 0 842 1 ]');
- // Zend_Pdf_Destination_Fit
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('Fit');
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_Fit);
- $this->assertEquals($destination->getResource()->toString(), '[4 0 R /Fit ]');
- // Zend_Pdf_Destination_FitHorizontally
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('FitH');
- $destArray->items[] = new Zend_Pdf_Element_Numeric(842); // top
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_FitHorizontally);
- $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitH 842 ]');
- // Zend_Pdf_Destination_FitVertically
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('FitV');
- $destArray->items[] = new Zend_Pdf_Element_Numeric(0); // left
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_FitVertically);
- $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitV 0 ]');
- // Zend_Pdf_Destination_FitRectangle
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('FitR');
- $destArray->items[] = new Zend_Pdf_Element_Numeric(0); // left
- $destArray->items[] = new Zend_Pdf_Element_Numeric(10); // bottom
- $destArray->items[] = new Zend_Pdf_Element_Numeric(595); // right
- $destArray->items[] = new Zend_Pdf_Element_Numeric(842); // top
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_FitRectangle);
- $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitR 0 10 595 842 ]');
- // Zend_Pdf_Destination_FitBoundingBox
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('FitB');
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_FitBoundingBox);
- $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitB ]');
- // Zend_Pdf_Destination_FitBoundingBoxHorizontally
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('FitBH');
- $destArray->items[] = new Zend_Pdf_Element_Numeric(842); // top
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_FitBoundingBoxHorizontally);
- $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitBH 842 ]');
- // Zend_Pdf_Destination_FitBoundingBoxVertically
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('FitBV');
- $destArray->items[] = new Zend_Pdf_Element_Numeric(0); // left
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_FitBoundingBoxVertically);
- $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitBV 0 ]');
- }
- public function testGettersSetters()
- {
- $pdf = new Zend_Pdf();
- $page1 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
- $page2 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
- // Zend_Pdf_Destination_Zoom
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('XYZ');
- $destArray->items[] = new Zend_Pdf_Element_Numeric(0); // left
- $destArray->items[] = new Zend_Pdf_Element_Numeric(842); // top
- $destArray->items[] = new Zend_Pdf_Element_Numeric(1); // zoom
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertEquals($destination->getLeftEdge(), 0);
- $destination->setLeftEdge(5);
- $this->assertEquals($destination->getLeftEdge(), 5);
- $this->assertEquals($destination->getTopEdge(), 842);
- $destination->setTopEdge(825);
- $this->assertEquals($destination->getTopEdge(), 825);
- $this->assertEquals($destination->getZoomFactor(), 1);
- $destination->setZoomFactor(0.5);
- $this->assertEquals($destination->getZoomFactor(), 0.5);
- // Zend_Pdf_Destination_FitHorizontally
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('FitH');
- $destArray->items[] = new Zend_Pdf_Element_Numeric(842); // top
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertEquals($destination->getTopEdge(), 842);
- $destination->setTopEdge(825);
- $this->assertEquals($destination->getTopEdge(), 825);
- // Zend_Pdf_Destination_FitVertically
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('FitV');
- $destArray->items[] = new Zend_Pdf_Element_Numeric(0); // left
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertEquals($destination->getLeftEdge(), 0);
- $destination->setLeftEdge(5);
- $this->assertEquals($destination->getLeftEdge(), 5);
- // Zend_Pdf_Destination_FitRectangle
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('FitR');
- $destArray->items[] = new Zend_Pdf_Element_Numeric(0); // left
- $destArray->items[] = new Zend_Pdf_Element_Numeric(10); // bottom
- $destArray->items[] = new Zend_Pdf_Element_Numeric(595); // right
- $destArray->items[] = new Zend_Pdf_Element_Numeric(842); // top
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertEquals($destination->getLeftEdge(), 0);
- $destination->setLeftEdge(5);
- $this->assertEquals($destination->getLeftEdge(), 5);
- $this->assertEquals($destination->getBottomEdge(), 10);
- $destination->setBottomEdge(20);
- $this->assertEquals($destination->getBottomEdge(), 20);
- $this->assertEquals($destination->getRightEdge(), 595);
- $destination->setRightEdge(590);
- $this->assertEquals($destination->getRightEdge(), 590);
- $this->assertEquals($destination->getTopEdge(), 842);
- $destination->setTopEdge(825);
- $this->assertEquals($destination->getTopEdge(), 825);
- // Zend_Pdf_Destination_FitBoundingBoxHorizontally
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('FitBH');
- $destArray->items[] = new Zend_Pdf_Element_Numeric(842); // top
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertEquals($destination->getTopEdge(), 842);
- $destination->setTopEdge(825);
- $this->assertEquals($destination->getTopEdge(), 825);
- // Zend_Pdf_Destination_FitBoundingBoxVertically
- $destArray = new Zend_Pdf_Element_Array();
- $destArray->items[] = $page2->getPageDictionary();
- $destArray->items[] = new Zend_Pdf_Element_Name('FitBV');
- $destArray->items[] = new Zend_Pdf_Element_Numeric(0); // left
- $destination = Zend_Pdf_Destination::load($destArray);
- $this->assertEquals($destination->getLeftEdge(), 0);
- $destination->setLeftEdge(5);
- $this->assertEquals($destination->getLeftEdge(), 5);
- }
- public function testCreate()
- {
- $pdf = new Zend_Pdf();
- $page1 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
- $page2 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
- $destination = Zend_Pdf_Destination_Zoom::create($page2, 0, 842, 0.5);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_Zoom);
- $this->assertEquals($destination->getResource()->toString(), '[4 0 R /XYZ 0 842 0.5 ]');
- $destination = Zend_Pdf_Destination_Fit::create($page2);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_Fit);
- $this->assertEquals($destination->getResource()->toString(), '[4 0 R /Fit ]');
- $destination = Zend_Pdf_Destination_FitHorizontally::create($page2, 842);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_FitHorizontally);
- $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitH 842 ]');
- $destination = Zend_Pdf_Destination_FitVertically::create(2, 0);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_FitVertically);
- $this->assertEquals($destination->getResource()->toString(), '[2 /FitV 0 ]');
- $destination = Zend_Pdf_Destination_FitRectangle::create($page1, 0, 10, 595, 842);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_FitRectangle);
- $this->assertEquals($destination->getResource()->toString(), '[3 0 R /FitR 0 10 595 842 ]');
- $destination = Zend_Pdf_Destination_FitBoundingBox::create(1);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_FitBoundingBox);
- $this->assertEquals($destination->getResource()->toString(), '[1 /FitB ]');
- $destination = Zend_Pdf_Destination_FitBoundingBoxHorizontally::create($page2, 842);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_FitBoundingBoxHorizontally);
- $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitBH 842 ]');
- $destination = Zend_Pdf_Destination_FitBoundingBoxVertically::create($page2, 0);
- $this->assertTrue($destination instanceof Zend_Pdf_Destination_FitBoundingBoxVertically);
- $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitBV 0 ]');
- }
- }
|