コード例 #1
0
 /**
  * Function: updateBoundingBox
  * 
  * Updates the bounding box in the given cell state.
  */
 function updateBoundingBox($state)
 {
     // Gets the cell bounds and adds shadows and markers
     $rect = new mxRectangle($state->x, $state->y, $state->width, $state->height);
     $style = $state->style;
     // Adds extra pixels for the marker and stroke assuming
     // that the border stroke is centered around the bounds
     // and the first pixel is drawn inside the bounds
     $strokeWidth = max(1, mxUtils::getNumber($style, mxConstants::$STYLE_STROKEWIDTH, 1) * $this->scale);
     $strokeWidth -= max(1, $strokeWidth / 2);
     if ($this->graph->model->isEdge($state->cell)) {
         $ms = 0;
         if (isset($style[mxConstants::$STYLE_ENDARROW]) || isset($style[mxConstants::$STYLE_STARTARROW])) {
             $ms = round(mxConstants::$DEFAULT_MARKERSIZE * $this->scale);
         }
         // Adds the strokewidth
         $rect->grow($ms + $strokeWidth);
         // Adds worst case border for an arrow shape
         if (mxUtils::getValue($style, mxConstants::$STYLE_SHAPE) == mxConstants::$SHAPE_ARROW) {
             $rect->grow(mxConstants::$ARROW_WIDTH / 2);
         }
     } else {
         $rect->grow($strokeWidth);
     }
     // Adds extra pixels for the shadow
     if (mxUtils::getValue($style, mxConstants::$STYLE_SHADOW, false) == true) {
         $rect->width += mxConstants::$SHADOW_OFFSETX;
         $rect->height += mxConstants::$SHADOW_OFFSETY;
     }
     // Adds oversize images in labels
     if (mxUtils::getValue($style, mxConstants::$STYLE_SHAPE) == mxConstants::$SHAPE_LABEL) {
         if (mxUtils::getValue($style, mxConstants::$STYLE_IMAGE) != null) {
             $w = mxUtils::$getValue($style, mxConstants::$STYLE_IMAGE_WIDTH, mxConstants::$DEFAULT_IMAGESIZE) * $this->scale;
             $h = mxUtils::$getValue($style, mxConstants::$STYLE_IMAGE_HEIGHT, mxConstants::$DEFAULT_IMAGESIZE) * $this->scale;
             $x = $state->x;
             $y = 0;
             $imgAlign = mxUtils::getValue($style, mxConstants::$STYLE_IMAGE_ALIGN, mxConstants::$ALIGN_CENTER);
             $imgValign = mxUtils::getValue(style, mxConstants::$STYLE_IMAGE_VERTICAL_ALIGN, mxConstants::$ALIGN_MIDDLE);
             if ($imgAlign == mxConstants::$ALIGN_RIGHT) {
                 $x += $state->width - $w;
             } else {
                 if ($imgAlign == mxConstants::$ALIGN_CENTER) {
                     $x += ($state->width - $w) / 2;
                 }
             }
             if ($imgValign == mxConstants::$ALIGN_TOP) {
                 $y = $state->y;
             } else {
                 if ($imgValign == mxConstants::$ALIGN_BOTTOM) {
                     $y = $state->y + $state->height - $h;
                 } else {
                     $y = $state->y + ($state->height - $h) / 2;
                 }
             }
             $rect->add(new mxRectangle($x, $y, $w, $h));
         }
     }
     // No need to add rotated rectangle bounds here because
     // GD does not support rotation
     // Unifies the cell bounds and the label bounds
     $rect->add($state->labelBounds);
     $state->boundingBox = $rect;
     return $rect;
 }
コード例 #2
0
ファイル: mxCellState.php プロジェクト: yangchaogit/mxgraph
 /**
  * Function: getPerimeterBounds
  * 
  * Returns the <mxRectangle> that should be used as the perimeter of the
  * cell.
  */
 function getPerimeterBounds($border = 0)
 {
     $bounds = new mxRectangle($this->x, $this->y, $this->width, $this->height);
     if ($border != 0) {
         $bounds->grow($border);
     }
     return $bounds;
 }