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(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);
     }
 }
 private function getMinimumYCoordOfChildren(Node $node)
 {
     $minYCoord = $node->getFirstPoint()->getY() - $node->getPaddingTop();
     foreach ($node->getChildren() as $child) {
         $minYCoord = min($minYCoord, $child->getDiagonalPoint()->getY());
     }
     return $minYCoord;
 }