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);
 }
 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;
 }
示例#3
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;
 }
 private function hasAutoMargins(Node $node)
 {
     $marginLeft = $node->getMarginLeft();
     $marginRight = $node->getMarginRight();
     return $marginLeft === Node::MARGIN_AUTO && $marginRight === Node::MARGIN_AUTO;
 }