예제 #1
0
 private function designateLinesOfWords(Node $node)
 {
     $currentPoint = $node->getFirstPoint();
     $partsOfLine = array();
     $yTranslation = 0;
     $line = new Line($node, 0, $yTranslation);
     foreach ($node->getChildren() as $textNode) {
         $words = $textNode->getWords();
         $wordsSizes = $textNode->getWordsSizes();
         $currentWordLine = array();
         $currentWidthOfLine = 0;
         $numberOfWords = count($words);
         $first = true;
         $lineWidth = 0;
         foreach ($words as $index => $word) {
             $wordSize = $wordsSizes[$index];
             $newLineWidth = $currentWidthOfLine + $wordSize;
             $endXCoord = $newLineWidth + $currentPoint->getX();
             $maxLineXCoord = $this->getMaxXCoord($node);
             $isEndOfLine = $endXCoord > $maxLineXCoord;
             if ($isEndOfLine) {
                 if ($currentWordLine) {
                     $partOfLine = new LinePart($currentWordLine, $currentWidthOfLine, $currentPoint->getX() - $node->getFirstPoint()->getX(), $textNode);
                     $partsOfLine[] = $partOfLine;
                     $line->addParts($partsOfLine);
                     $node->addLine($line);
                     $yTranslation += $line->getHeight();
                     $line = new Line($node, 0, $yTranslation);
                     $partsOfLine = array();
                     $currentWidthOfLine = 0;
                     $currentWordLine = array();
                 } else {
                     $line->addParts($partsOfLine);
                     $node->addLine($line);
                     $yTranslation += $line->getHeight();
                     $line = new Line($node, 0, $yTranslation);
                     $partsOfLine = array();
                 }
                 $currentPoint = Point::getInstance($node->getFirstPoint()->getX(), 0);
             }
             $currentWidthOfLine = $currentWidthOfLine + $wordSize;
             $currentWordLine[] = $word;
         }
         if ($currentWordLine) {
             $partOfLine = new LinePart($currentWordLine, $currentWidthOfLine, $currentPoint->getX() - $node->getFirstPoint()->getX(), $textNode);
             $partsOfLine[] = $partOfLine;
             $currentPoint = $currentPoint->translate($currentWidthOfLine, 0);
         }
     }
     if ($partsOfLine) {
         $yTranslation += $line->getHeight();
         $line = new Line($node, 0, $yTranslation);
         $line->addParts($partsOfLine);
         $node->addLine($line);
     }
 }
예제 #2
0
 /**
  * @test
  */
 public function firstPointIsTranslatedFirstPointOfParagraph()
 {
     $yTranslation = 21;
     $xTranslation = 10;
     $paragraph = $this->getMockBuilder('PHPPdf\\Core\\Node\\Paragraph')->setMethods(array('getFirstPoint'))->getMock();
     $firstPoint = Point::getInstance(100, 100);
     $paragraph->expects($this->once())->method('getFirstPoint')->will($this->returnValue($firstPoint));
     $line = new Line($paragraph, $xTranslation, $yTranslation);
     $this->assertEquals(array(110, 79), $line->getFirstPoint()->toArray());
 }
 /**
  * @test
  */
 public function setFirstPointAsFirstPointOfParent()
 {
     $firstPoint = Point::getInstance(0, 500);
     $parent = $this->getMock('PHPPdf\\Core\\Node\\Container', array('getFirstPoint'));
     $parent->expects($this->atLeastOnce())->method('getFirstPoint')->will($this->returnValue($firstPoint));
     $boundary = $this->getMock('PHPPdf\\Core\\Boundary', array('setNext'));
     $boundary->expects($this->once())->method('setNext')->with($firstPoint);
     $node = $this->getMock('PHPPdf\\Core\\Node\\Container', array('getParent', 'getBoundary'));
     $node->expects($this->atLeastOnce())->method('getParent')->will($this->returnValue($parent));
     $node->expects($this->atLeastOnce())->method('getBoundary')->will($this->returnValue($boundary));
     $this->formatter->format($node, $this->createDocumentStub());
 }
 private function getTextMock($lineSizes, $parentFirstPoint, $firstXCoord = null)
 {
     $parentMock = $this->getMock('\\PHPPdf\\Core\\Node\\Node', array('getStartDrawingPoint'));
     $parentMock->expects($this->once())->method('getStartDrawingPoint')->will($this->returnValue(array(0, 700)));
     $mock = $this->getMock('\\PHPPdf\\Core\\Node\\Text', array('getParent', 'getLineHeightRecursively', 'getLineSizes', 'getStartDrawingPoint', 'getBoundary'));
     $mock->expects($this->atLeastOnce())->method('getParent')->will($this->returnValue($parentMock));
     $boundaryMock = $this->getMock('\\PHPPdf\\Core\\Boundary', array('getFirstPoint', 'setNext', 'close'));
     $firstXCoord = $firstXCoord ? $firstXCoord : $parentFirstPoint[0];
     $boundaryMock->expects($this->atLeastOnce())->method('getFirstPoint')->will($this->returnValue(Point::getInstance($firstXCoord, $parentFirstPoint[1])));
     $this->addBoundaryPointsAsserts($boundaryMock, $lineSizes, $parentFirstPoint[1]);
     $mock->expects($this->atLeastOnce())->method('getBoundary')->will($this->returnValue($boundaryMock));
     $mock->expects($this->atLeastOnce())->method('getBoundary')->will($this->returnValue($boundaryMock));
     $mock->expects($this->once())->method('getLineHeightRecursively')->will($this->returnValue(self::TEXT_LINE_HEIGHT));
     $mock->expects($this->once())->method('getLineSizes')->will($this->returnValue($lineSizes));
     return $mock;
 }
예제 #5
0
 /**
  * @test
  */
 public function attachGoToActionToGraphicsContext()
 {
     $x = 0;
     $y = 500;
     $width = 100;
     $height = 100;
     $firstPoint = Point::getInstance(400, 300);
     $destination = $this->getMockBuilder('PHPPdf\\Core\\Node\\Container')->setMethods(array('getFirstPoint', 'getGraphicsContext', 'getNode'))->getMock();
     $destination->expects($this->atLeastOnce())->method('getFirstPoint')->will($this->returnValue($firstPoint));
     $destination->expects($this->atLeastOnce())->method('getNode')->will($this->returnValue($destination));
     $gc = $this->getMockBuilder('PHPPdf\\Core\\Engine\\GraphicsContext')->getMock();
     $gc->expects($this->once())->method('goToAction')->with($gc, $x, $y, $x + $width, $y - $height, $firstPoint->getY());
     $destination->expects($this->atLeastOnce())->method('getGraphicsContext')->will($this->returnValue($gc));
     $nodeStub = $this->getNodeStub($x, $y, $width, $height);
     $behaviour = new GoToInternal($destination);
     $behaviour->attach($gc, $nodeStub);
 }
 public function integerProvider()
 {
     return array(array(5, Point::getInstance(10, 30), BasicList::LIST_POSITION_OUTSIDE, 20, $this->getElementPattern(0)), array(12, Point::getInstance(100, 300), BasicList::LIST_POSITION_INSIDE, 40, $this->getElementPattern(1)), array(12, Point::getInstance(100, 300), BasicList::LIST_POSITION_INSIDE, 40, $this->getElementPattern(1), 5));
 }
예제 #7
0
 private function expectDrawLine($gc, $color, Point $startPoint, Point $endPoint)
 {
     $gc->expects($this->once())->method('setLineColor')->id('color')->with($color);
     $gc->expects($this->once())->method('setLineWidth')->id('line')->with(0.5);
     $gc->expects($this->once())->after('color')->method('drawLine')->with($startPoint->getX(), $startPoint->getY(), $endPoint->getX(), $endPoint->getY());
 }
예제 #8
0
 private static function getTranslatedPointOf(Node $node, Point $point)
 {
     $translation = $node->getPositionTranslation();
     return $point->translate($translation->getX(), $translation->getY());
 }
예제 #9
0
 public function compareCoordinationsProvider()
 {
     return array(array(Point::getInstance(1.12345678, 2.98765421), Point::getInstance(1.12345611, 2.98765422), 100000, 0, 0), array(Point::getInstance(1.12345678, 2.98765421), Point::getInstance(1.12345611, 2.98765432), 10000000, 1, -1), array(Point::getInstance(1.123456781, 2.987654291), Point::getInstance(1.123456791, 2.98765428), 100000000, -1, 1));
 }
예제 #10
0
 /**
  * @test
  */
 public function startPointOfEachLineShouldBeMovedWhileTranlateing()
 {
     $x = 10;
     $y = 15;
     $transX = 3;
     $transY = 5;
     $this->text->addLineOfWords(array('word'), 10, Point::getInstance($x, $y));
     $this->text->translate($transX, $transY);
     list($point) = $this->text->getPointsOfWordsLines();
     $this->assertEquals(array($x + $transX, $y - $transY), $point->toArray());
 }
 public function enumerationProvider()
 {
     return array(array(Point::getInstance(50, 200), BasicList::LIST_POSITION_INSIDE, 20, 10));
 }
예제 #12
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());
 }
예제 #13
0
 /**
  * @test
  */
 public function creation()
 {
     $this->boundary->setNext(Point::getInstance(10, 10))->setNext(20, 10)->setNext(20, 5)->setNext(Point::getInstance(10, 5));
     $this->boundary->close();
     $this->assertEquals(5, count($this->boundary));
 }
예제 #14
0
 public function createResizableBoundaryMock($width, $horizontalResizeBy, $verticalResizeBy, $initSequence = 1)
 {
     $boundary = $this->getMock('PHPPdf\\Core\\Boundary', array('pointTranslate', 'getDiagonalPoint', 'getFirstPoint'));
     $boundary->expects($this->atLeastOnce())->method('getDiagonalPoint')->will($this->returnValue(Point::getInstance($width, 0)));
     $boundary->expects($this->any())->method('getFirstPoint')->will($this->returnValue(Point::getInstance(0, 0)));
     if ($initSequence !== false) {
         $boundary->expects($this->at($initSequence++))->method('pointTranslate')->with(1, $horizontalResizeBy, 0);
         $boundary->expects($this->at($initSequence++))->method('pointTranslate')->with(2, $horizontalResizeBy, $verticalResizeBy);
         $boundary->expects($this->at($initSequence++))->method('pointTranslate')->with(3, 0, $verticalResizeBy);
     } else {
         $boundary->expects($this->never())->method('pointTranslate');
     }
     return $boundary;
 }
예제 #15
0
 /**
  * @return PHPPdf\Core\Point Point that divides line between first and diagonal points on half
  */
 public function getMiddlePoint()
 {
     $diagonalPoint = $this->getDiagonalPoint();
     if ($diagonalPoint === null) {
         return null;
     }
     $x = $this->getFirstPoint()->getX() + ($diagonalPoint->getX() - $this->getFirstPoint()->getX()) / 2;
     $y = $diagonalPoint->getY() + ($this->getFirstPoint()->getY() - $diagonalPoint->getY()) / 2;
     return Point::getInstance($x, $y);
 }
예제 #16
0
 /**
  * @test
  */
 public function drawCircleBackground()
 {
     $color = '#ffffff';
     $radius = 100;
     $centerPoint = Point::getInstance(100, 100);
     $background = new Background('#ffffff');
     $this->assertDrawCircle($background, $color, $radius, $centerPoint, GraphicsContext::SHAPE_DRAW_FILL);
 }
예제 #17
0
 private function translatePointByPosition(Point $point)
 {
     return $point->translate($this->getAttributeDirectly('left'), $this->getAttributeDirectly('top'));
 }
예제 #18
0
 /**
  * _____________________________
  * |                            |
  * |              ______________|
  * |_____________|              | <- 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);
         }
     }
 }