コード例 #1
0
 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);
 }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
 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);
         }
     }
 }