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) { $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(); }
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; }
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; }