private function getVerticalTranslation(Node $node, $minYCoord, $verticalAlign)
 {
     $difference = $minYCoord - ($node->getDiagonalPoint()->getY() + $node->getPaddingBottom());
     if ($verticalAlign == Node::VERTICAL_ALIGN_MIDDLE) {
         $difference /= 2;
     }
     return $difference;
 }
Beispiel #2
0
 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);
     }
 }
 private function shouldBeBroken(Node $node, $pageYCoordEnd)
 {
     $yEnd = $node->getDiagonalPoint()->getY();
     return $yEnd < $pageYCoordEnd;
 }
Beispiel #4
0
 private function getDiagonalPoint(Node $node)
 {
     if ($this->useRealDimension) {
         return $node->getRealDiagonalPoint();
     }
     return $node->getDiagonalPoint();
 }