private function createText($text)
 {
     $page = new Page(array('page-size' => self::TEXT_WIDTH . ':100'));
     $textNode = new TextDimensionFormatterTest_Text($text, new TextDimensionFormatterTest_Font());
     $textNode->setFontSize(self::FONT_SIZE);
     $textNode->setWidth(self::TEXT_WIDTH);
     $page->add($textNode);
     return $textNode;
 }
 private function createText($text, $parentWidth = null, $parentMaxWidth = null)
 {
     $page = new Page();
     $container = new Container(array('width' => $parentWidth, 'max-width' => $parentMaxWidth));
     $textNode = new TextDimensionFormatterTest_Text($text, new TextDimensionFormatterTest_Font());
     $textNode->setFontSize(self::FONT_SIZE);
     $container->add($textNode);
     $page->add($container);
     return $textNode;
 }
 /**
  * @test
  */
 public function percentageConvert()
 {
     $page = new Page();
     $unitConverter = new PdfUnitConverter();
     $node = new Container(array('width' => 200, 'height' => 100), $unitConverter);
     $child = new Container(array('width' => '70%', 'height' => '50%'), $unitConverter);
     $node->add($child);
     $page->add($node);
     $node->setHeight(100);
     $node->setWidth(200);
     $this->formatter->format($child, $this->document);
     $this->assertEquals(200 * 0.7, $child->getWidth());
     $this->assertEquals(100 * 0.5, $child->getHeight());
 }
Example #4
0
 /**
  * @test
  */
 public function dontIgnorePaddingBottom()
 {
     $page = new Page();
     $paddingBottom = 10;
     $leftFloatedContainerHeight = 20;
     $rightFloatedContainerHeight = 40;
     $containerHeight = $paddingBottom + $leftFloatedContainerHeight + $rightFloatedContainerHeight;
     $container = new Container();
     $container->makeAttributesSnapshot();
     $container->setPaddingBottom($paddingBottom);
     $container->setHeight($containerHeight);
     $container->setWidth($page->getWidth());
     $this->invokeMethod($container, 'setBoundary', array($this->objectMother->getBoundaryStub(0, $page->getFirstPoint()->getY(), $page->getWidth(), $containerHeight)));
     $leftFloatedContainer = new Container();
     $leftFloatedContainer->setFloat(Node::FLOAT_LEFT);
     $leftFloatedContainer->setHeight($leftFloatedContainerHeight);
     $leftFloatedContainer->setWidth(10);
     $this->invokeMethod($leftFloatedContainer, 'setBoundary', array($this->objectMother->getBoundaryStub(0, $page->getFirstPoint()->getY(), 10, $leftFloatedContainerHeight)));
     $rightFloatedContainer = new Container();
     $rightFloatedContainer->setFloat(Node::FLOAT_RIGHT);
     $rightFloatedContainer->setHeight($rightFloatedContainerHeight);
     $rightFloatedContainer->setWidth(10);
     $this->invokeMethod($rightFloatedContainer, 'setBoundary', array($this->objectMother->getBoundaryStub(0, $page->getFirstPoint()->getY() + $leftFloatedContainerHeight, 10, $rightFloatedContainerHeight)));
     $page->add($container->add($leftFloatedContainer)->add($rightFloatedContainer));
     $this->formatter->format($container, $this->document);
     $expectedHeight = $paddingBottom + $rightFloatedContainerHeight;
     $this->assertEquals($expectedHeight, $container->getHeight());
     $this->assertEquals($expectedHeight, $container->getFirstPoint()->getY() - $container->getDiagonalPoint()->getY());
 }
 /**
  * @test
  * @dataProvider sizeProvider
  */
 public function calculateSecondSize($width, $height)
 {
     $page = new Page();
     $imageWidth = 100;
     $imageHeight = 120;
     $imagePath = 'image/path';
     $imageResource = $this->createImageResourceMock($imageWidth, $imageHeight);
     $this->document->expects($this->atLeastOnce())->method('createImage')->with($imagePath)->will($this->returnValue($imageResource));
     $image = new Image(array('src' => $imagePath, 'width' => $width, 'height' => $height));
     $page->add($image);
     $this->formatter->format($image, $this->document);
     $ratio = $imageWidth / $imageHeight;
     if (!$height) {
         $ratio = 1 / $ratio;
     }
     $excepted = $ratio * ($width ? $width : $height);
     $this->assertEquals($excepted, $width ? $image->getHeight() : $image->getWidth());
 }
 /**
  * @test
  * @dataProvider correctHeightOfPageProvider
  */
 public function correctHeightOfPage($originalHeight, array $childrenDiagonalYCoord)
 {
     $page = new Page(array('page-size' => '500:' . $originalHeight));
     foreach ($childrenDiagonalYCoord as $yCoord) {
         $node = $this->nodeObjectMother->getNodeStub(0, $page->getHeight(), 100, $page->getHeight() - $yCoord);
         $page->add($node);
     }
     $minYCoord = $childrenDiagonalYCoord ? min($childrenDiagonalYCoord) : $originalHeight;
     $this->formatter->format($page, $this->document);
     $expectedHeight = $originalHeight - $minYCoord;
     $translation = $originalHeight - $expectedHeight;
     $this->assertEquals($expectedHeight, $page->getRealHeight());
     foreach ($page->getChildren() as $i => $child) {
         $expectedDiagonalYCoord = $childrenDiagonalYCoord[$i] - $translation;
         $actualDiagonalYCoord = $child->getDiagonalPoint()->getY();
         $this->assertEquals($expectedDiagonalYCoord, $actualDiagonalYCoord);
     }
 }
 /**
  * @test
  */
 public function nodeWithAutoMarginPositioning()
 {
     $node = new Container(array('width' => 100, 'height' => 100));
     $node->hadAutoMargins(true);
     $node->makeAttributesSnapshot();
     $node->setWidth(110);
     $child = new Container(array('width' => 50, 'height' => 50));
     $node->add($child);
     $page = new Page();
     $page->add($node);
     $node->getBoundary()->setNext($page->getFirstPoint());
     $child->getBoundary()->setNext($page->getFirstPoint());
     foreach (array($node, $child) as $g) {
         $this->formatter->format($g, $this->createDocumentStub());
     }
     $nodeBoundary = $node->getBoundary();
     $childBoundary = $child->getBoundary();
     $pageBoundary = $page->getBoundary();
     $this->assertEquals($pageBoundary[0]->translate(-5, 0), $nodeBoundary[0]);
     $this->assertEquals($pageBoundary[0]->translate(105, 0), $nodeBoundary[1]);
     $this->assertEquals($pageBoundary[0]->translate(105, 100), $nodeBoundary[2]);
     $this->assertEquals($pageBoundary[0]->translate(-5, 100), $nodeBoundary[3]);
 }
Example #8
0
 /**
  * @test
  * @dataProvider getsPositionTranslationProvider
  */
 public function getsPositionTranslation($position, $positionPoint, $firstPoint, $parentPosition, $parentPositionTranslation, $parentFirstPoint, $expectedPositionTranslation)
 {
     $this->node->setAttribute('position', $position);
     $this->node->setAttribute('left', $positionPoint[0]);
     $this->node->setAttribute('top', $positionPoint[1]);
     $boundary = $this->objectMother->getBoundaryStub($firstPoint[0], $firstPoint[1], 100, 100);
     $this->writeAttribute($this->node, 'boundary', $boundary);
     $parent = $this->getMockBuilder('PHPPdf\\Core\\Node\\Container')->setMethods(array('getPositionTranslation'))->getMock();
     $parent->setAttribute('position', $parentPosition);
     $parent->expects($this->any())->method('getPositionTranslation')->will($this->returnValue(Point::getInstance($parentPositionTranslation[0], $parentPositionTranslation[1])));
     $parentBoundary = $this->objectMother->getBoundaryStub($parentFirstPoint[0], $parentFirstPoint[1], 100, 100);
     $this->writeAttribute($parent, 'boundary', $parentBoundary);
     $this->node->setParent($parent);
     $page = new Page();
     $page->setHeight(self::PAGE_HEIGHT);
     $parent->setParent($page);
     $expectedPositionTranslation = Point::getInstance($expectedPositionTranslation[0], $expectedPositionTranslation[1]);
     $this->assertEquals($expectedPositionTranslation, $this->node->getPositionTranslation());
 }
Example #9
0
 public function flush()
 {
     foreach ($this->pages as $page) {
         $page->flush();
     }
     $this->pages = array();
     $this->currentPage = null;
     parent::flush();
 }