public function format(Nodes\Node $node, Document $document)
 {
     $boundary = $node->getBoundary();
     list($x, $y) = $node->getFirstPoint()->toArray();
     $boundary->reset();
     $boundary->setNext($x, $y);
 }
Example #2
0
 private function setColumnMarginIfNecessary(Node $node, $marginType)
 {
     $margin = $node->getAttribute($marginType);
     $columnNumber = $node->getNumberOfColumn();
     if (!isset($this->marginsOfColumns[$marginType][$columnNumber]) || $margin > $this->marginsOfColumns[$marginType][$columnNumber]) {
         $this->marginsOfColumns[$marginType][$columnNumber] = $margin;
     }
 }
 private function getVerticalTranslation(Node $node, $minYCoord, $verticalAlign)
 {
     $difference = $minYCoord - ($node->getDiagonalPoint()->getY() + $node->getPaddingBottom());
     if ($verticalAlign == Node::VERTICAL_ALIGN_MIDDLE) {
         $difference /= 2;
     }
     return $difference;
 }
 private function getMaxXCoord(Node $node)
 {
     for ($parent = $node->getParent(); $parent && !$parent->getWidth(); $parent = $parent->getParent()) {
     }
     if (!$node->getWidth() && $parent && $parent->getWidth()) {
         $node = $parent;
     }
     return $node->getFirstPoint()->getX() + $node->getWidth() - $node->getPaddingRight();
 }
 public function format(Node $node, Document $document)
 {
     $node->convertRelativeWidthsOfColumns();
     $node->reduceColumnsWidthsByMargins();
     $columnsWidths = $node->getWidthsOfColumns();
     $columnsMarginsLeft = $node->getMarginsLeftOfColumns();
     $columnsMarginsRight = $node->getMarginsRightOfColumns();
     $numberOfColumns = $node->getNumberOfColumns();
     $totalColumnsWidth = array_sum($columnsWidths);
     $tableWidth = $node->getWidth();
     $enlargeColumnWidth = $numberOfColumns ? ($tableWidth - $totalColumnsWidth) / count($columnsWidths) : 0;
     foreach ($columnsWidths as $index => $width) {
         $columnsWidths[$index] += $enlargeColumnWidth;
     }
     foreach ($node->getChildren() as $row) {
         foreach ($row->getChildren() as $cell) {
             $column = $cell->getNumberOfColumn();
             $colspan = $cell->getColspan();
             $newWidth = 0;
             for ($i = 0; $i < $colspan; $i++) {
                 $newWidth += $columnsWidths[$column + $i];
             }
             $horizontalPaddings = $cell->getPaddingLeft() + $cell->getPaddingRight();
             $cell->setWidth($newWidth - $horizontalPaddings);
             $cell->setMarginLeft($columnsMarginsLeft[$column]);
             $cell->setMarginRight($columnsMarginsRight[$column + $colspan - 1]);
         }
     }
 }
Example #6
0
 public function apply(Node $node)
 {
     $attributes = $this->getAll();
     foreach ($attributes as $name => $value) {
         if (is_array($value)) {
             $node->mergeComplexAttributes($name, $value);
         } else {
             $node->setAttribute($name, $value);
         }
     }
 }
Example #7
0
 public function format(Node $node, Document $document)
 {
     $position = $node->getAttribute('list-position');
     $node->assignEnumerationStrategyFromFactory();
     if ($position === BasicList::LIST_POSITION_INSIDE) {
         $widthOfEnumerationChar = $node->getEnumerationStrategy()->getWidthOfTheBiggestPosibleEnumerationElement($document, $node);
         foreach ($node->getChildren() as $child) {
             $marginLeft = $widthOfEnumerationChar + $child->getMarginLeft();
             $child->setAttribute('margin-left', $marginLeft);
         }
     }
 }
Example #8
0
 private function getParentBookmarkIdentifier(Node $node)
 {
     if ($this->options['parentId']) {
         return $this->options['parentId'];
     }
     for ($parent = $node->getParent(); $parent !== null; $parent = $parent->getParent()) {
         foreach ($parent->getBehaviours() as $behaviour) {
             if ($behaviour instanceof Bookmark) {
                 return $behaviour->getUniqueId();
             }
         }
     }
     return null;
 }
 public function format(Node $node, Document $document)
 {
     $this->lastVerticalTranslation = 0;
     $nodes = $node instanceof ColumnableContainer ? array($node) : $node->getChildren();
     foreach ($nodes as $node) {
         if ($node instanceof ColumnableContainer) {
             $container = $this->moveAllChildrenToSingleContainer($node);
             $this->breakContainerIntoColumns($node, $container);
             $this->resizeColumnableContainer($node);
             $this->staticBreakYCoord = null;
             $this->stopBreaking = false;
         }
     }
 }
 private function setDimensionsFromParent(EngineImage $sourceImage, Node $node)
 {
     $parent = $node->getParent();
     $width = $sourceImage->getOriginalWidth();
     $height = $sourceImage->getOriginalHeight();
     if ($width > $parent->getWidth() || $height > $parent->getHeight()) {
         if ($parent->getWidth() > $parent->getHeight()) {
             $height = $parent->getHeight();
             $width = null;
         } else {
             $width = $parent->getWidth();
             $height = null;
         }
     }
     return array($width, $height);
 }
 public function format(Node $node, Document $document)
 {
     if (!$node instanceof Page) {
         throw new InvalidArgumentException('ElasticPageFormatter works only with PHPPdf\\Core\\Node\\Page class.');
     }
     $lastChild = null;
     foreach ($node->getChildren() as $child) {
         if (!$lastChild || $lastChild->getDiagonalPoint()->getY() - $lastChild->getMarginBottom() > $child->getDiagonalPoint()->getY() - $child->getMarginBottom()) {
             $lastChild = $child;
         }
     }
     $lastNodeYCoord = $lastChild ? $lastChild->getDiagonalPoint()->getY() - $lastChild->getMarginBottom() : $node->getRealHeight();
     $height = $node->getRealHeight() - $lastNodeYCoord + $node->getMarginBottom();
     $translate = $node->getRealHeight() - $height;
     $node->setPageSize($node->getRealWidth(), $height);
     foreach ($node->getChildren() as $child) {
         $child->translate(0, $translate);
     }
     $node->removeGraphicsContext();
 }
 public function format(Node $node, Document $document)
 {
     $boundary = $node->getBoundary();
     list($x, $y) = $boundary->getFirstPoint()->toArray();
     list($parentX, $parentY) = $node->getParent()->getStartDrawingPoint();
     $lineSizes = $node->getLineSizes();
     $lineHeight = $node->getLineHeightRecursively();
     $startX = $x;
     $currentX = $x;
     $currentY = $y;
     foreach ($lineSizes as $rowNumber => $width) {
         $newX = $x + $width;
         $newY = $currentY - $lineHeight;
         if ($currentX !== $newX) {
             $boundary->setNext($newX, $currentY);
         }
         $boundary->setNext($newX, $newY);
         $currentX = $newX;
         $currentY = $newY;
         $x = $parentX + $node->getMarginLeft();
     }
     $boundary->setNext($x, $currentY);
     $currentY = $currentY + (count($lineSizes) - 1) * $lineHeight;
     $boundary->setNext($x, $currentY);
     $boundary->setNext($startX, $currentY);
     $boundary->close();
 }
 public function format(Nodes\Node $node, Document $document)
 {
     $boundary = $node->getBoundary();
     if (!$boundary->isClosed()) {
         list($x, $y) = $boundary->getFirstPoint()->toArray();
         $attributesSnapshot = $node->getAttributesSnapshot();
         $diffWidth = $node->getWidth() - $attributesSnapshot['width'];
         $width = $node->getWidth();
         $x += $width;
         $yEnd = $y - $node->getHeight();
         $boundary->setNext($x, $y)->setNext($x, $yEnd)->setNext($x - $width, $yEnd)->close();
         if ($node->hadAutoMargins()) {
             $node->translate(-$diffWidth / 2, 0);
         }
     }
 }
Example #14
0
 private function getTemplateDrawingTasksAndFormatPlaceholders(Document $document)
 {
     $this->formatConvertAttributes($document);
     $this->getHeader()->format($document);
     $this->getFooter()->format($document);
     $this->getWatermark()->format($document);
     $tasks = new DrawingTaskHeap();
     $this->getDrawingTasksFromComplexAttributes($document, $tasks);
     $this->footer->collectOrderedDrawingTasks($document, $tasks);
     $this->header->collectOrderedDrawingTasks($document, $tasks);
     $this->watermark->collectOrderedDrawingTasks($document, $tasks);
     $this->footer->removeAll();
     $this->header->removeAll();
     $this->watermark->removeAll();
     return $tasks;
 }
Example #15
0
 public function format(Node $node, Document $document)
 {
     $widthsOfColumns = $node->getWidthsOfColumns();
     $tableWidth = $node->getWidthWithoutPaddings();
     $marginsLeft = $node->getMarginsLeftOfColumns();
     $marginsRight = $node->getMarginsRightOfColumns();
     $minWidthsOfColumns = $node->getMinWidthsOfColumns();
     $totalWidth = array_sum($widthsOfColumns);
     $totalMargins = array_sum($marginsLeft) + array_sum($marginsRight);
     $verticalAlignFormatter = $document->getFormatter('PHPPdf\\Core\\Formatter\\VerticalAlignFormatter');
     foreach ($node->getChildren() as $row) {
         $diffBetweenTableAndColumnsWidths = $tableWidth - $totalWidth - $totalMargins;
         $translate = 0;
         foreach ($row->getChildren() as $cell) {
             $column = $cell->getNumberOfColumn();
             $colspan = $cell->getColspan();
             $minWidth = $newWidth = 0;
             for ($i = 0; $i < $colspan; $i++) {
                 $realColumn = $column + $i;
                 $minWidth += $minWidthsOfColumns[$realColumn];
                 $newWidth += $widthsOfColumns[$realColumn];
                 if ($i > 0) {
                     $margins = $marginsRight[$realColumn] + $marginsLeft[$realColumn];
                     $minWidth += $margins;
                     $newWidth += $margins;
                 }
             }
             $diffBetweenNewAndMinWidth = $newWidth - $minWidth;
             if ($diffBetweenTableAndColumnsWidths < 0 && -$diffBetweenTableAndColumnsWidths >= $diffBetweenNewAndMinWidth) {
                 $newWidth = $minWidth;
                 $diffBetweenTableAndColumnsWidths += $diffBetweenNewAndMinWidth;
             } elseif ($diffBetweenTableAndColumnsWidths < 0) {
                 $newWidth += $diffBetweenTableAndColumnsWidths;
                 $diffBetweenTableAndColumnsWidths = 0;
             }
             $cell->convertScalarAttribute('width', $tableWidth);
             $currentWidth = $cell->getWidth();
             $diff = $newWidth - $currentWidth;
             $minWidth = $cell->getMinWidth();
             $cell->setWidth($newWidth);
             $translate += $marginsLeft[$column];
             $cell->translate($translate, 0);
             $cell->resize($diff, 0);
             $translate += $newWidth + $marginsRight[$column];
             $verticalAlignFormatter->format($cell, $document);
         }
     }
 }
 public function format(Node $node, Document $document)
 {
     $originalRatio = $node->getOriginalRatio();
     $currentRatio = $node->getCurrentRatio();
     if (!$this->floatEquals($originalRatio, $currentRatio)) {
         $width = $node->getWidth();
         $height = $node->getHeight();
         if ($originalRatio > $currentRatio) {
             $height = $originalRatio ? $width / $originalRatio : 0;
             $node->setHeight($height);
         } else {
             $width = $height * $originalRatio;
             $node->setWidth($width);
         }
     }
 }
 protected function convertColor(Node $node, Document $document)
 {
     $color = $node->getAttribute('color');
     if ($color) {
         $node->setAttribute('color', $document->getColorFromPalette($color));
     }
     if ($node->hasAttribute('chart-colors')) {
         $colors = $node->getAttribute('chart-colors');
         foreach ($colors as $key => $color) {
             $colors[$key] = $document->getColorFromPalette($color);
         }
         $node->setAttribute('chart-colors', $colors);
     }
 }
Example #18
0
 protected function doBreakAt($height)
 {
     $linesToMove = array();
     $numberOfLines = count($this->lines);
     foreach ($this->lines as $i => $line) {
         $lineEnd = $line->getYTranslation() + $line->getHeight();
         if ($lineEnd > $height) {
             $linesToMove[] = $line;
             unset($this->lines[$i]);
         }
     }
     if (!$linesToMove || count($linesToMove) == $numberOfLines) {
         return null;
     }
     $firstLineToMove = current($linesToMove);
     $yTranslation = $height - $firstLineToMove->getYTranslation();
     $height = $firstLineToMove->getYTranslation();
     $paragraphProduct = Node::doBreakAt($height);
     $paragraphProduct->removeAll();
     $replaceText = array();
     $textsToMove = array();
     foreach ($firstLineToMove->getParts() as $part) {
         $text = $part->getText();
         $textHeight = $text->getFirstPoint()->getY() - ($this->getFirstPoint()->getY() - $height);
         $textProduct = $text->breakAt($textHeight);
         if ($textProduct) {
             $replaceText[spl_object_hash($text)] = $textProduct;
             $paragraphProduct->add($textProduct);
             $part->setText($textProduct);
         } else {
             $replaceText[spl_object_hash($text)] = $text;
             $textsToMove[spl_object_hash($text)] = $text;
         }
     }
     foreach ($linesToMove as $line) {
         $line->setYTranslation($line->getYTranslation() - $height);
         $line->setParagraph($paragraphProduct);
         $paragraphProduct->addLine($line);
     }
     array_shift($linesToMove);
     foreach ($linesToMove as $line) {
         foreach ($line->getParts() as $part) {
             $text = $part->getText();
             $hash = spl_object_hash($text);
             if (isset($replaceText[$hash])) {
                 $part->setText($replaceText[$hash]);
             } else {
                 $textsToMove[$hash] = $text;
             }
         }
     }
     foreach ($textsToMove as $text) {
         $this->remove($text);
         $paragraphProduct->add($text);
     }
     $paragraphProduct->translate(0, $yTranslation);
     $paragraphProduct->resize(0, -$yTranslation);
     $paragraphProduct->resize(0, $yTranslation);
     return $paragraphProduct;
 }
Example #19
0
 protected function getTranslationAwareBoundary(Node $node, Boundary $boundary)
 {
     $positionTranslation = $node->getPositionTranslation();
     if ($positionTranslation && ($positionTranslation->getX() != 0 || $positionTranslation->getY() != 0)) {
         $boundary = clone $boundary;
         $boundary->translate($positionTranslation->getX(), $positionTranslation->getY());
     }
     return $boundary;
 }
 public function format(Node $node, Document $document)
 {
     $boundary = $node->getBoundary();
     $verticalMargins = $node->getMarginsBottomOfCells() + $node->getMarginsTopOfCells();
     $newHeight = $node->getMaxHeightOfCells() + $verticalMargins;
     $heightDiff = $newHeight - $node->getHeight();
     $boundary->pointTranslate(2, 0, $heightDiff)->pointTranslate(3, 0, $heightDiff);
     $node->setHeight($newHeight);
     foreach ((array) $node->getChildren() as $cell) {
         $heightDiff = $node->getMaxHeightOfCells() - $cell->getHeight();
         $cell->setHeight($node->getMaxHeightOfCells());
         $cell->getBoundary()->pointTranslate(2, 0, $heightDiff)->pointTranslate(3, 0, $heightDiff);
         $cell->translate(0, $node->getMarginsTopOfCells());
     }
 }
 private function isLineBreak(Node $node, Node $previousSibling)
 {
     return $node->getAttribute('line-break') && $previousSibling->getAttribute('line-break');
 }
Example #22
0
 public function flush()
 {
     $this->lineParts = array();
     parent::flush();
 }
Example #23
0
 private function drawCircleBorder(GraphicsContext $gc, Node $node, Document $document)
 {
     $size = $document->convertUnit($this->size);
     $gc->setLineWidth($size);
     $point = $node->getMiddlePoint();
     $translation = $node->getPositionTranslation();
     if (!$translation->isZero()) {
         $point = $point->translate($translation->getX(), $translation->getY());
     }
     $this->drawCircle($gc, $node->getAttribute('radius'), $point->getX(), $point->getY(), GraphicsContext::SHAPE_DRAW_STROKE);
 }
Example #24
0
 private static function getTranslatedPointOf(Node $node, Point $point)
 {
     $translation = $node->getPositionTranslation();
     return $point->translate($translation->getX(), $translation->getY());
 }
Example #25
0
 private function correctXCoordWithParent(Node $node)
 {
     $parent = $node->getParent();
     if ($node->getFloat() === Node::FLOAT_LEFT) {
         $preferredXCoord = $parent->getFirstPoint()->getX() + $parent->getPaddingLeft() + $node->getMarginLeft() + $node->getPaddingLeft();
     } else {
         $preferredXCoord = $parent->getDiagonalPoint()->getX() - $node->getWidth() + $node->getPaddingLeft() - $node->getMarginRight();
     }
     return $preferredXCoord;
 }
 public function format(Node $node, Document $document)
 {
     $parent = $node->getParent();
     if ($node->getWidth() === null && !$node->isInline() && $node->getFloat() === Node::FLOAT_NONE) {
         $parentWidth = $parent->getWidthWithoutPaddings();
         $marginLeft = $node->getMarginLeft();
         $marginRight = $node->getMarginRight();
         $node->setWidth($parentWidth - ($marginLeft + $marginRight));
         $node->setRelativeWidth('100%');
     } elseif ($node->isInline()) {
         $node->setWidth(0);
     }
     if ($node->getHeight() === null) {
         $node->setHeight(0);
     }
     $paddingLeft = $node->getPaddingLeft();
     $paddingRight = $node->getPaddingRight();
     $paddingTop = $node->getPaddingTop();
     $paddingBottom = $node->getPaddingBottom();
     $prefferedWidth = $node->getRealWidth() + $paddingLeft + $paddingRight;
     $parent = $node->getParent();
     $parentWidth = $parent ? $parent->getWidthWithoutPaddings() : null;
     if ($parent && $parentWidth < $prefferedWidth) {
         $prefferedWidth = $parentWidth;
     }
     $node->setWidth($prefferedWidth);
     $node->setHeight($node->getRealHeight() + $paddingTop + $paddingBottom);
 }
 public function format(Node $node, Document $document)
 {
     $parent = $node->getParent();
     $boundary = $node->getBoundary();
     $boundary->setNext($parent->getFirstPoint());
 }
Example #28
0
 private function setBehavioursFromReader(\XMLReader $reader, Node $node)
 {
     foreach ($this->behaviourFactory->getSupportedBehaviourNames() as $name) {
         $value = $reader->getAttribute($name);
         if ($value) {
             $node->addBehaviour($this->behaviourFactory->create($name, $value));
         }
     }
 }
Example #29
0
 public function initialize()
 {
     parent::initialize();
     $this->addAttribute('name-two');
     $this->addAttribute('name', 'value');
 }
Example #30
0
 protected static function initializeType()
 {
     static::setAttributeSetters(array('ignore-error' => 'setIgnoreError'));
     static::setAttributeSetters(array('keep-ratio' => 'setKeepRatio'));
     parent::initializeType();
 }