Example #1
0
 public function alignInside(BoundingBox $container, Alignment $align = NULL, $mode = self::ALIGN_MODE_CENTER, $disableZoom = false)
 {
     if ($align === NULL) {
         $align = Alignment::center();
     }
     $scaleW = $this->width / $container->width;
     $scaleH = $this->height / $container->height;
     $scale = 1;
     switch ($mode) {
         case self::ALIGN_MODE_CENTER:
             $scale = 1;
             break;
         case self::ALIGN_MODE_CONTAIN:
             $scale = max($scaleW, $scaleH);
             break;
         case self::ALIGN_MODE_COVER:
             $scale = min($scaleW, $scaleH);
             break;
     }
     if ($disableZoom && $scale < 1) {
         $scale = 1;
     }
     $newWidth = $container->width * $scale;
     $newHeight = $container->height * $scale;
     if ($align->isHorizontalCenter()) {
         $this->left += round(($this->width - $newWidth) / 2);
     } elseif ($align->isRight()) {
         $this->left += $this->width - $newWidth;
     }
     if ($align->isVerticalCenter()) {
         $this->top += round(($this->height - $newHeight) / 2);
     } elseif ($align->isBottom()) {
         $this->top += $this->height - $newHeight;
     }
     $this->width = $newWidth;
     $this->height = $newHeight;
 }