/** * @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()); }
private function getContainerStub($start, $end, array $methods = array()) { $stub = new Container(); $stub->setHeight($start[1] - $end[1]); $stub->getBoundary()->setNext($start[0], $start[1])->setNext($end[0], $start[1])->setNext($end[0], $end[1])->setNext($start[0], $end[1])->close(); $boundary = new Boundary(); $boundary->setNext($start[0], $start[1])->setNext($end[0], $start[1])->setNext($end[0], $end[1])->setNext($start[0], $end[1])->close(); return $stub; }
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; }
/** * @test */ public function convertColor() { $color = 'color'; $result = '#000000'; $node = new Container(); $node->setAttribute('color', $color); $document = $this->getMockBuilder('PHPPdf\\Core\\Document')->setMethods(array('getColorFromPalette'))->disableOriginalConstructor()->getMock(); $document->expects($this->once())->method('getColorFromPalette')->with($color)->will($this->returnValue($result)); $this->formatter->format($node, $document); $this->assertEquals($result, $node->getAttribute('color')); }
/** * @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()); }
/** * @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()); }
protected function setAttributeDirectly($name, $value) { $oldValue = $this->getAttributeDirectly($name); parent::setAttributeDirectly($name, $value); foreach ($this->listeners as $listener) { $listener->attributeChanged($this, $name, $oldValue); } }
private function createContainers(array $heights, $parent = null) { $parent = $parent ? $parent : $this->column; $width = 100; $yStart = 0; $containers = array(); foreach ($heights as $height) { $container = new Container(); $container->setHeight($height); $container->setWidth($width); $parent->add($container); $this->injectBoundary($container, $yStart); $yStart += $height; $containers[] = $container; } return $containers; }
/** * @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()); }
protected function doBreakAt($height) { $broken = parent::doBreakAt($height); if ($broken) { $height = 0; foreach ($this->getChildren() as $row) { $height += $row->getHeight() + $row->getMarginTop() + $row->getMarginBottom(); } $oldHeight = $this->getHeight(); $this->setHeight($height); $diff = $oldHeight - $height; $boundary = $this->getBoundary(); $boundary->pointTranslate(2, 0, -$diff); $boundary->pointTranslate(3, 0, -$diff); } return $broken; }
/** * @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]); }
/** * @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); } }
public function reset() { parent::reset(); $this->numberOfColumns = 0; }
private function translateProductOfBroke(Container $productOfBroke, Container $originalContainer) { $columnableContainer = $originalContainer->getParent(); $numberOfContainers = count($columnableContainer->getChildren()); $numberOfColumns = $columnableContainer->getAttribute('number-of-columns'); $isInTheSameRowAsOriginalContainer = $numberOfContainers % $numberOfColumns != 1; if ($isInTheSameRowAsOriginalContainer) { $xCoordTranslate = $originalContainer->getWidth() + $columnableContainer->getAttribute('margin-between-columns'); $firstPoint = $originalContainer->getFirstPoint()->translate($xCoordTranslate, 0); } else { $xCoordTranslate = $numberOfColumns * $originalContainer->getWidth() + ($numberOfColumns - 1) * $columnableContainer->getAttribute('margin-between-columns'); $firstPoint = $originalContainer->getDiagonalPoint()->translate(-$xCoordTranslate, 0); } $xCoordTranslate = $firstPoint->getX() - $productOfBroke->getFirstPoint()->getX(); $yCoordTranslate = $productOfBroke->getFirstPoint()->getY() - $firstPoint->getY(); $productOfBroke->translate($xCoordTranslate, $yCoordTranslate); }
protected static function initializeType() { parent::initializeType(); static::setAttributeSetters(array('equals-columns' => 'setEqualsColumns')); }
public function getRealWidth() { return $this->getAttributeDirectly('real-width') ?: parent::getRealWidth(); }
public function copy() { $node = parent::copy(); $node->setOmitEnumerationOfFirstElement(false); return $node; }
public function flush() { $placeholders = array('footer', 'header', 'watermark'); foreach ($placeholders as $placeholder) { if ($this->{$placeholder}) { $this->{$placeholder}->flush(); $this->{$placeholder} = null; } } parent::flush(); }
/** * @test */ public function watermarkShouldBeInTheMiddleOfPage() { $watermark = new Container(); $watermark->setHeight(100); $this->page->setWatermark($watermark); $this->assertEquals(Node::VERTICAL_ALIGN_MIDDLE, $watermark->getAttribute('vertical-align')); $this->assertEquals($this->page->getHeight(), $watermark->getHeight()); $this->assertEquals($this->page->getWidth(), $watermark->getWidth()); }
public function flush() { foreach ($this->lines as $line) { $line->flush(); } $this->lines = array(); parent::flush(); }
/** * _____________________________ * | | * | ______________| * |_____________| | <- breaking here * | | * |____________________________| * * @test */ public function breaking() { $x = 0; $y = 500; $width = 500; $height = 500; $firstPoint = Point::getInstance($x, $y); $paragraphParent = new Container(); $paragraphParent->setWidth($width); $paragraphParent->setHeight($height); $paragraph = new Paragraph(); $paragraph->setParent($paragraphParent); $text1 = new Text(); $text1->getBoundary()->setNext($firstPoint)->setNext($firstPoint->translate($width, 0))->setNext($firstPoint->translate($width, 200))->setNext($firstPoint->translate($width / 2, 200))->setNext($firstPoint->translate($width / 2, 250))->setNext($firstPoint->translate(0, 250))->close(); $text2 = new Text(); $text2->getBoundary()->setNext($firstPoint->translate($width / 2, 200))->setNext($firstPoint->translate($width, 200))->setNext($firstPoint->translate($width, 500))->setNext($firstPoint->translate(0, 500))->setNext($firstPoint->translate(0, 250))->setNext($firstPoint->translate($width / 2, 250))->close(); $text1->setWidth(500); $text1->setHeight(250); $text2->setWidth(500); $text2->setHeight(300); $text1->setAttribute('line-height', 100); $text2->setAttribute('line-height', 100); for ($i = 0; $i < 2; $i++) { $line = new Line($paragraph, 0, $i * 100); $part = new LinePart('', 500, 0, $text1); $line->addPart($part); $paragraph->addLine($line); } $line = new Line($paragraph, 0, 200); $line->addPart(new LinePart('', $width / 2, 0, $text1)); $line->addPart(new LinePart('', $width / 2, 250, $text2)); $paragraph->addLine($line); for ($i = 0; $i < 2; $i++) { $line = new Line($paragraph, 0, ($i + 3) * 100); $part = new LinePart('', 500, 0, $text2); $line->addPart($part); $paragraph->addLine($line); } $paragraph->add($text1); $paragraph->add($text2); $paragraph->getBoundary()->setNext($firstPoint)->setNext($firstPoint->translate($width, 0))->setNext($firstPoint->translate($width, 500))->setNext($firstPoint->translate(0, 500))->close(); $paragraph->setHeight(500); $paragraphProduct = $paragraph->breakAt(225); $this->assertEquals(200, $paragraph->getHeight()); $this->assertEquals(200, $paragraph->getFirstPoint()->getY() - $paragraph->getDiagonalPoint()->getY()); $this->assertEquals(300, $paragraphProduct->getHeight()); $this->assertEquals(300, $paragraphProduct->getFirstPoint()->getY() - $paragraphProduct->getDiagonalPoint()->getY()); $this->assertTrue($paragraphProduct !== null); $this->assertEquals(200, $paragraph->getHeight()); $this->assertEquals(2, count($paragraph->getLines())); $this->assertEquals(3, count($paragraphProduct->getLines())); $this->assertEquals(1, count($paragraph->getChildren())); $this->assertEquals(2, count($paragraphProduct->getChildren())); foreach ($paragraphProduct->getLines() as $i => $line) { $this->assertEquals($i * 100, $line->getYTranslation()); foreach ($line->getParts() as $part) { // $this->assertTrue($part->getText() !== $text1); // $this->assertTrue($part->getText() !== $text2); } } }