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); } }
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()); } }
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); } } }
public function format(Node $node, Document $document) { $children = $node->getChildren(); $attributesSnapshot = $node->getAttributesSnapshot(); $parentBottomYCoord = null; $positionCorrection = false; foreach ($children as $child) { $translateX = $translateY = 0; list($x, $y) = $child->getStartDrawingPoint(); if ($this->hasFloat($child)) { $sibling = $this->getPreviousSiblingWithFloat($child, $child->getFloat()); list($orgX, $orgY) = $child->getStartDrawingPoint(); if (!$sibling) { $previousSibling = $child->getPreviousSibling(); if ($previousSibling) { $y = $previousSibling->getDiagonalPoint()->getY() - $previousSibling->getMarginBottom() - $child->getMarginTop() - $child->getPaddingTop(); } } $this->setNodesWithFloatPosition($child, $x, $y, $sibling); $translateX = $x - $orgX; $translateY = -($y - $orgY); } elseif ($positionCorrection) { $siblings = $child->getSiblings(); $minYCoord = null; $previousSiblingWithMinBottomYCoord = null; foreach ($siblings as $sib) { if ($sib === $child) { break; } $previousSibling = $sib; $bottomYCoord = $previousSibling->getDiagonalPoint()->getY() - $previousSibling->getMarginBottom(); if ($minYCoord === null || $bottomYCoord < $minYCoord) { $minYCoord = $bottomYCoord; $previousSiblingWithMinBottomYCoord = $previousSibling; } } if ($minYCoord !== null) { $translateY = -($minYCoord - $y - $child->getMarginTop() - $child->getPaddingTop()); if ($child->isInline() && $previousSiblingWithMinBottomYCoord->isInline()) { $translateY -= $child instanceof Text ? $child->getLineHeightRecursively() : $child->getHeight(); } } } if ($translateX || $translateY) { $child->translate($translateX, $translateY); } $childBottomYCoord = $child->getDiagonalPoint()->getY() - $child->getMarginBottom(); if ($parentBottomYCoord === null || $childBottomYCoord < $parentBottomYCoord) { $parentBottomYCoord = $childBottomYCoord; } if ($translateY) { $positionCorrection = true; } } if ($positionCorrection && $parentBottomYCoord && !$node->getAttribute('static-size')) { $parentTranslate = $node->getDiagonalPoint()->getY() - $parentBottomYCoord + $node->getPaddingBottom(); $newHeight = $node->getHeight() + $parentTranslate; $oldHeight = isset($attributesSnapshot['height']) ? $attributesSnapshot['height'] : 0; if ($newHeight < $oldHeight) { $parentTranslate += $oldHeight - $newHeight; $newHeight = $oldHeight; } $node->setHeight($newHeight); $node->getBoundary()->pointTranslate(2, 0, $parentTranslate); $node->getBoundary()->pointTranslate(3, 0, $parentTranslate); } }