private function createTextNode(array $wordsSizes, $fontSize, Paragraph $paragraph) { $textNode = new Text(); list($words, $sizes) = $wordsSizes; $textNode->setWordsSizes($words, $sizes); $textNode->setFontSize($fontSize); $paragraph->add($textNode); return $textNode; }
private function startsWithWhiteChars(Text $text) { return ltrim($text->getText()) != $text->getText(); }
public function setText(Text $text) { if ($this->text !== $text) { $oldText = $this->text; if ($oldText) { $oldText->removeLinePart($this); } $this->text = $text; $text->addLinePart($this); } }
private function setTextBoundary(Text $text) { $lineParts = $text->getLineParts(); $points = array(); foreach ($lineParts as $part) { $points[] = $part->getFirstPoint(); } list($x, $y) = $points[0]->toArray(); $text->getBoundary()->setNext($points[0]); list($parentX, $parentY) = $text->getParent()->getFirstPoint()->toArray(); $startX = $x; $currentX = $x; $currentY = $y; $boundary = $text->getBoundary(); $totalHeight = 0; foreach ($lineParts as $rowNumber => $part) { $height = $part->getText()->getLineHeightRecursively(); $totalHeight += $height; $width = $part->getWidth(); $startPoint = $points[$rowNumber]; $newX = $startPoint->getX() + $width; $newY = $currentY - $height; if ($currentX !== $newX) { $boundary->setNext($newX, $currentY); } $boundary->setNext($newX, $newY); $currentX = $newX; $currentY = $newY; $x = $startPoint->getX(); } $boundary->setNext($x, $currentY); $currentY = $currentY + $totalHeight; $boundary->setNext($x, $currentY); $boundary->setNext($startX, $currentY); $boundary->close(); $text->setHeight($text->getFirstPoint()->getY() - $text->getDiagonalPoint()->getY()); }
/** * @test */ public function zeroStrindIsNotTreatedAsEmptyString() { $xml = <<<XML <pdf>0</pdf> XML; $textNode = new Text(); $paragraphNode = new Paragraph(); $nodeFactoryMock = $this->getNodeFactoryMock(array(array('paragraph', $paragraphNode), array('text', $textNode))); $this->parser->setNodeFactory($nodeFactoryMock); $pages = $this->parser->parse($xml); $this->assertEquals('0', $textNode->getText()); }
/** * @test */ public function removeLinePart() { $text = new Text(); $linePart1 = $this->getMockBuilder('PHPPdf\\Core\\Node\\Paragraph\\LinePart')->disableOriginalConstructor()->getMock(); $linePart2 = $this->getMockBuilder('PHPPdf\\Core\\Node\\Paragraph\\LinePart')->disableOriginalConstructor()->getMock(); $text->addLinePart($linePart1); $text->addLinePart($linePart2); $this->assertEquals(2, count($text->getLineParts())); $text->removeLinePart($linePart1); $this->assertEquals(1, count($text->getLineParts())); $text->removeLinePart($linePart1); $this->assertEquals(1, count($text->getLineParts())); }
public function __construct($text, Font $font) { parent::__construct($text); $this->font = $font; }
public function getPage() { if ($this->page !== null) { return $this->page; } return parent::getPage(); }
/** * _____________________________ * | | * | ______________| * |_____________| | <- 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); } } }