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)
 {
     $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]);
         }
     }
 }
 public function format(Nodes\Node $node, Document $document)
 {
     $minX = $maxX = $minY = $maxY = null;
     foreach ($node->getChildren() as $child) {
         $firstPoint = $child->getFirstPoint();
         $diagonalPoint = $child->getDiagonalPoint();
         $childMinX = $firstPoint->getX() - $child->getMarginLeft();
         $childMaxX = $diagonalPoint->getX() + $child->getMarginRight();
         $childMinY = $diagonalPoint->getY() - $child->getMarginBottom();
         $childMaxY = $firstPoint->getY() + $child->getMarginTop();
         $maxX = $this->changeValueIfIsLess($maxX, $childMaxX);
         $maxY = $this->changeValueIfIsLess($maxY, $childMaxY);
         $minX = $this->changeValueIfIsGreater($minX, $childMinX);
         $minY = $this->changeValueIfIsGreater($minY, $childMinY);
     }
     $paddingVertical = $node->getPaddingTop() + $node->getPaddingBottom();
     $paddingHorizontal = $node->getPaddingLeft() + $node->getPaddingRight();
     $realHeight = $paddingVertical + ($maxY - $minY);
     $realWidth = $paddingHorizontal + ($maxX - $minX);
     if ($realHeight > $node->getHeight()) {
         $node->setHeight($realHeight);
     }
     if ($node->isInline() || $realWidth > $node->getWidth()) {
         $node->setWidth($realWidth);
     }
 }
 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);
         }
     }
 }
 private function isNodeInSameRowAsPreviousSibling(Node $node, Node $previousSibling)
 {
     $oneOfNodesIsInline = $previousSibling->isInline() && $node->isInline();
     if (!$oneOfNodesIsInline) {
         return false;
     }
     $parent = $node->getParent();
     $parentBoundary = $parent->getBoundary();
     list($prevX) = $previousSibling->getEndDrawingPoint();
     $endX = $prevX + $previousSibling->getMarginRight() + $node->getMarginLeft() + $node->getWidth();
     $parentEndX = $parentBoundary->getFirstPoint()->getX() + $parent->getWidth();
     $rowIsOverflowed = !$node instanceof Nodes\Text && $parentEndX < $endX && $previousSibling->getFloat() !== Nodes\Node::FLOAT_RIGHT;
     return !$rowIsOverflowed;
 }
 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);
         }
     }
 }
示例#7
0
 private function setColumnWidthIfNecessary(Node $node)
 {
     $width = $node->getWidth();
     $columnNumber = $node->getNumberOfColumn();
     $colspan = $node->getAttribute('colspan');
     $isWidthRelative = strpos($width, '%') !== false;
     $currentWidth = 0;
     for ($i = 0; $i < $colspan; $i++) {
         $realColumnNumber = $columnNumber + $i;
         $currentWidth += isset($this->widthsOfColumns[$realColumnNumber]) ? $this->widthsOfColumns[$realColumnNumber] : 0;
     }
     $diff = ($width - $currentWidth) / $colspan;
     if ($isWidthRelative) {
         $diff .= '%';
     }
     if ($diff >= 0) {
         for ($i = 0; $i < $colspan; $i++) {
             $realColumnNumber = $columnNumber + $i;
             $this->widthsOfColumns[$realColumnNumber] = isset($this->widthsOfColumns[$realColumnNumber]) ? $this->widthsOfColumns[$realColumnNumber] + $diff : $diff;
         }
     }
 }
 private function isImageAndSizesArentSet(Node $node)
 {
     return $node instanceof Image && (!$node->getWidth() || !$node->getHeight());
 }
 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();
 }
示例#10
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;
 }
示例#11
0
 private function getWidth(Node $node)
 {
     if ($this->useRealDimension) {
         return $node->getRealWidth();
     }
     return $node->getWidth();
 }