Ejemplo n.º 1
0
 /**
  * @test
  */
 public function moveButNotResizeChildWithRightFloatOnResizing()
 {
     $width = 100;
     $height = 100;
     $this->node->setWidth($width);
     $this->node->setHeight($height);
     $boundary = $this->objectMother->getBoundaryStub(0, $height, $width, $height);
     $this->invokeMethod($this->node, 'setBoundary', array($boundary));
     $childWidth = 50;
     $childHeight = 100;
     $child = new Container(array('width' => $childWidth, 'height' => $childHeight, 'float' => 'right'));
     $childBoundary = $this->objectMother->getBoundaryStub($width - $childWidth, $childHeight, $childWidth, $childHeight);
     $this->invokeMethod($child, 'setBoundary', array($childBoundary));
     $this->node->add($child);
     $xResize = 20;
     $this->node->resize($xResize, 0);
     $expectedChildDiagonalXCoord = $width + $xResize;
     $this->assertEquals($expectedChildDiagonalXCoord, $child->getDiagonalPoint()->getX());
     $this->assertEquals($childWidth, $child->getWidth());
     $xResize = -40;
     $this->node->resize($xResize, 0);
     $expectedChildDiagonalXCoord = $expectedChildDiagonalXCoord + $xResize;
     $this->assertEquals($expectedChildDiagonalXCoord, $child->getDiagonalPoint()->getX());
     $this->assertEquals($childWidth, $child->getWidth());
 }
Ejemplo n.º 2
0
 public function add(Node $text)
 {
     $previousText = $this->getLastChild();
     parent::add($text);
     $text->setText(preg_replace('/[ \\t]+/', ' ', $text->getText()));
     if (!$previousText || $this->startsWithWhiteChars($text) && $this->endsWithWhiteChars($previousText)) {
         $text->setText(ltrim($text->getText()));
     }
     return $this;
 }
Ejemplo n.º 3
0
 public function add(Node $node)
 {
     if (!$node instanceof Row) {
         throw new InvalidArgumentException(sprintf('Invalid child node type, expected PHPPdf\\Core\\Node\\Table\\Row, %s given.', get_class($node)));
     }
     foreach ($node->getChildren() as $cell) {
         $this->updateColumnDataIfNecessary($cell);
     }
     return parent::add($node);
 }
Ejemplo n.º 4
0
 private function createParagraph($x, $y, $width, $height)
 {
     $parent = new Container();
     $parent->setWidth($width);
     $paragraph = new Paragraph();
     $parent->add($paragraph);
     $boundary = $this->objectMother->getBoundaryStub($x, $y, $width, $height);
     $this->invokeMethod($paragraph, 'setBoundary', array($boundary));
     return $paragraph;
 }
 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;
 }
 private function moveAllChildrenToSingleContainer(ColumnableContainer $columnableContainer)
 {
     $container = new Container();
     foreach ($columnableContainer->getChildren() as $child) {
         $container->add($child);
     }
     $columnableContainer->removeAll();
     $columnableContainer->add($container);
     $this->setDimension($columnableContainer, $container);
     return $container;
 }
 /**
  * @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());
 }
 /**
  * @test
  */
 public function drawingInSmallerContainer()
 {
     $page = new Page();
     $height = 100;
     $width = 120;
     $imagePath = 'image/path';
     $imageResource = $this->createImageResourceMock($width, $height);
     $this->document->expects($this->atLeastOnce())->method('createImage')->with($imagePath)->will($this->returnValue($imageResource));
     $image = new Image(array('src' => $imagePath));
     $container = new Container(array('width' => (int) ($width * 0.7), 'height' => (int) ($height * 0.5)));
     $container->add($image);
     $this->formatter->format($image, $this->document);
     $this->assertEquals($container->getHeight(), $image->getHeight());
     $this->assertTrue($container->getWidth() > $image->getWidth());
 }
Ejemplo n.º 9
0
 public function add(Node $node)
 {
     if (!$node instanceof Cell) {
         throw new InvalidArgumentException(sprintf('Invalid child node type, expected PHPPdf\\Core\\Node\\Table\\Cell, %s given.', get_class($node)));
     }
     $node->setNumberOfColumn($this->numberOfColumns);
     $this->numberOfColumns += $node->getColspan();
     $parent = $this->getParent();
     if ($parent) {
         $node->addListener($parent);
     }
     $node->addListener($this);
     $this->setMaxHeightOfCellsIfHeightOfPassedCellIsGreater($node);
     $this->setCellMarginIfNecessary($node, 'margin-top');
     $this->setCellMarginIfNecessary($node, 'margin-bottom');
     return parent::add($node);
 }
 /**
  * @test
  */
 public function nodeFormatter()
 {
     $composeNode = new Container();
     $composeNode->setWidth(140);
     $children = array();
     $children[] = $this->objectMother->getNodeStub(0, 500, 100, 200);
     $children[] = $this->objectMother->getNodeStub(0, 300, 200, 200);
     foreach ($children as $child) {
         $composeNode->add($child);
     }
     $this->formatter->format($composeNode, $this->createDocumentStub());
     $height = 0;
     foreach ($children as $child) {
         $height += $child->getHeight();
     }
     $this->assertEquals($height, $composeNode->getHeight());
     $this->assertEquals(200, $composeNode->getWidth());
 }
 /**
  * @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]);
 }
Ejemplo n.º 12
0
 /**
  * @test
  * @dataProvider positionProvider
  */
 public function getsClosestAncestorWithPosition($position, $expectedFalse)
 {
     $grandparent = new Container();
     $parent = new Container();
     $grandparent->add($parent);
     $parent->add($this->node);
     $grandparent->setAttribute('position', $position);
     $actualAncestor = $this->node->getClosestAncestorWithPosition();
     if ($expectedFalse) {
         $this->assertFalse($actualAncestor);
     } else {
         $this->assertEquals($grandparent, $actualAncestor);
     }
 }