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());
 }
Exemple #2
0
 /**
  * @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()));
 }