/** * Function: getScaledLabelBounds * * Returns the bounds for a label for the given location and size, taking * into account the alignment and spacing in the specified style, as well * as the width and height of the rectangle that contains the label. * (For edge labels this width and height is 0.) The scale is used to scale * the given size and the spacings in the specified style. */ static function getScaledLabelBounds($x, $y, $size, $outerWidth, $outerHeight, $style, $scale) { // Adds an inset of 3 pixels $inset = mxConstants::$LABEL_INSET * $scale; // Scales the size of the label $width = $size->width * $scale + 2 * $inset; $height = $size->height * $scale; // Gets the global spacing and orientation $horizontal = mxUtils::getValue($style, mxConstants::$STYLE_HORIZONTAL, true); $spacing = mxUtils::getNumber($style, mxConstants::$STYLE_SPACING) * $scale; // Gets the alignment settings $align = mxUtils::getValue($style, mxConstants::$STYLE_ALIGN, mxConstants::$ALIGN_CENTER); $valign = mxUtils::getValue($style, mxConstants::$STYLE_VERTICAL_ALIGN, mxConstants::$ALIGN_MIDDLE); // Gets the vertical spacing $top = mxUtils::getNumber($style, mxConstants::$STYLE_SPACING_TOP) * $scale; $bottom = mxUtils::getNumber($style, mxConstants::$STYLE_SPACING_BOTTOM) * $scale; // Gets the horizontal spacing $left = mxUtils::getNumber($style, mxConstants::$STYLE_SPACING_LEFT) * $scale; $right = mxUtils::getNumber($style, mxConstants::$STYLE_SPACING_RIGHT) * $scale; // Applies the orientation to the spacings and dimension if (!$horizontal) { $tmp = $top; $top = $right; $right = $bottom; $bottom = $left; $left = $tmp; $tmp = $width; $width = $height; $height = $tmp; } // Computes the position of the label for the horizontal alignment if ($horizontal && $align == mxConstants::$ALIGN_CENTER || !$horizontal && $valign == mxConstants::$ALIGN_MIDDLE) { $x += ($outerWidth - $width) / 2 + $left - $right; } else { if ($horizontal && $align == mxConstants::$ALIGN_RIGHT || !$horizontal && $valign == mxConstants::$ALIGN_BOTTOM) { $x += $outerWidth - $width - $spacing - $right; } else { $x += $spacing + $left; } } // Computes the position of the label for the vertical alignment if (!$horizontal && $align == mxConstants::$ALIGN_CENTER || $horizontal && $valign == mxConstants::$ALIGN_MIDDLE) { $y += ($outerHeight - $height) / 2 + $top - $bottom; } else { if (!$horizontal && $align == mxConstants::$ALIGN_LEFT || $horizontal && $valign == mxConstants::$ALIGN_BOTTOM) { $y += $outerHeight - $height - $spacing - $bottom; } else { $y += $spacing + $top; } } return new mxRectangle($x, $y, $width, $height); }
/** * Function: drawShape * * Draws the given shape. */ function drawShape($x, $y, $w, $h, $style) { // Draws the shape $shape = mxUtils::getValue($style, mxConstants::$STYLE_SHAPE); $image = $shape == mxConstants::$SHAPE_IMAGE; // Redirects background styles for image shapes $fillStyle = $image ? mxConstants::$STYLE_IMAGE_BACKGROUND : mxConstants::$STYLE_FILLCOLOR; $strokeStyle = $image ? mxConstants::$STYLE_IMAGE_BORDER : mxConstants::$STYLE_STROKECOLOR; // Prepares the background and foreground $stroke = mxUtils::getValue($style, $strokeStyle); $fill = mxUtils::getValue($style, $fillStyle); if ($stroke == "none") { $stroke = null; } if ($fill == "none") { $fill = null; } if ($fill != null || $stroke != null || $image) { $shadow = mxUtils::getValue($style, mxConstants::$STYLE_SHADOW); $strokeWidth = mxUtils::getValue($style, mxConstants::$STYLE_STROKEWIDTH, 1) * $this->scale; if (isset($this->image)) { imagesetthickness($this->image, $strokeWidth); } if ($shape == mxConstants::$SHAPE_ELLIPSE) { $this->drawOval($x, $y, $w, $h, $fill, $stroke, $shadow); } else { if ($shape == mxConstants::$SHAPE_LINE) { $direction = mxUtils::getValue($style, mxConstants::$STYLE_DIRECTION, mxConstants::$DIRECTION_EAST); if ($direction == mxConstants::$DIRECTION_EAST || $direction == mxConstants::$DIRECTION_WEST) { $mid = $y + $h / 2; $this->drawLine($x, $mid, $x + $w, $mid, $stroke); } else { $mid = $x + $w / 2; $this->drawLine($mid, $y, $mid, $y + $h, $stroke); } } else { if ($shape == mxConstants::$SHAPE_DOUBLE_ELLIPSE) { $this->drawOval($x, $y, $w, $h, $fill, $stroke, $shadow); $inset = (3 + 1) * $this->scale; $x += $inset; $y += $inset; $w -= 2 * $inset; $h -= 2 * $inset; $this->drawOval($x, $y, $w, $h, null, $stroke, false); } else { if ($shape == mxConstants::$SHAPE_RHOMBUS) { $this->drawRhombus($x, $y, $w, $h, $fill, $stroke, $shadow); } else { if ($shape == mxConstants::$SHAPE_TRIANGLE) { $dir = mxUtils::getValue($style, mxConstants::$STYLE_DIRECTION); $this->drawTriangle($x, $y, $w, $h, $fill, $stroke, $shadow, $dir); } else { if ($shape == mxConstants::$SHAPE_HEXAGON) { $dir = mxUtils::getValue($style, mxConstants::$STYLE_DIRECTION); $this->drawHexagon($x, $y, $w, $h, $fill, $stroke, $shadow, $dir); } else { if ($shape == mxConstants::$SHAPE_CYLINDER) { $this->drawCylinder($x, $y, $w, $h, $fill, $stroke, $shadow); } else { if ($shape == mxConstants::$SHAPE_CLOUD) { $this->drawCloud($x, $y, $w, $h, $fill, $stroke, $shadow); } else { if ($shape == mxConstants::$SHAPE_ACTOR) { $this->drawActor($x, $y, $w, $h, $fill, $stroke, $shadow); } else { $rounded = mxUtils::getValue($style, mxConstants::$STYLE_ROUNDED); $dashed = mxUtils::getNumber($style, mxConstants::$STYLE_DASHED); $this->drawRect($x, $y, $w, $h, $fill, $stroke, $shadow, $rounded, $dashed); // Draws the image as a shape if ($image) { $img = $this->getImageForStyle($style); if ($img != null) { $aspect = mxGdCanvas::$PRESERVE_IMAGE_ASPECT; $flipH = mxUtils::getValue($style, mxConstants::$STYLE_IMAGE_FLIPH, 0); $flipV = mxUtils::getValue($style, mxConstants::$STYLE_IMAGE_FLIPV, 0); $this->drawImage($x, $y, $w, $h, $img, $aspect, $flipH, $flipV); } } // Draws the image of the label inside the label shape if ($shape == mxConstants::$SHAPE_LABEL) { $image = $this->getImageForStyle($style); if ($image != null) { $imgAlign = mxUtils::getValue($style, mxConstants::$STYLE_IMAGE_ALIGN); $imgValign = mxUtils::getValue($style, mxConstants::$STYLE_IMAGE_VERTICAL_ALIGN); $imgWidth = mxUtils::getNumber($style, mxConstants::$STYLE_IMAGE_WIDTH, mxConstants::$DEFAULT_IMAGESIZE) * $this->scale; $imgHeight = mxUtils::getNumber($style, mxConstants::$STYLE_IMAGE_HEIGHT, mxConstants::$DEFAULT_IMAGESIZE) * $this->scale; $spacing = mxUtils::getNumber($style, mxConstants::$STYLE_SPACING, 2) * $this->scale; $imgX = $x; if ($imgAlign == mxConstants::$ALIGN_LEFT) { $imgX += $spacing; } else { if ($imgAlign == mxConstants::$ALIGN_RIGHT) { $imgX += $w - $imgWidth - $spacing; } else { $imgX += ($w - $imgWidth) / 2; } } $imgY = $y; if ($imgValign == mxConstants::$ALIGN_TOP) { $imgY += $spacing; } else { if ($imgValign == mxConstants::$ALIGN_BOTTOM) { $imgY += $h - $imgHeight - $spacing; } else { $imgY += ($h - $imgHeight) / 2; } } $this->drawImage($imgX, $imgY, $imgWidth, $imgHeight, $image); } } } } } } } } } } } if (isset($this->image)) { imagesetthickness($this->image, 1); } } }
/** * Function: parseState * * Parses the bounds, absolute points and label information from the style * of the state into its respective fields and returns the label of the * cell. */ function parseState($state, $edge) { $style = $state->style; // Parses the bounds $state->x = mxUtils::getNumber($style, "x"); $state->y = mxUtils::getNumber($style, "y"); $state->width = mxUtils::getNumber($style, "width"); $state->height = mxUtils::getNumber($style, "height"); // Parses the absolute points list $tmp = mxUtils::getValue($style, "points"); if (strlen($tmp) > 0) { $pts = $this->parsePoints($tmp); if (sizeof($pts) > 0) { $state->absolutePoints = $pts; } } // Parses the label and label bounds $label = mxUtils::getValue($style, "label"); if ($label != null && strlen($label) > 0) { $offset = new mxPoint(mxUtils::getNumber($style, "dx"), mxUtils::getNumber($style, "dy")); $vertexBounds = !$edge ? $state : null; $state->labelBounds = mxUtils::getLabelPaintBounds($label, $style, mxUtils::getValue($style, "html", false), $offset, $vertexBounds, $this->scale); } return $label; }
/** * Function: getPerimeterBounds * * Returns the perimeter bounds for the given terminal, edge pair as an * <mxRectangle>. */ function getPerimeterBounds($terminal, $edge, $isSource) { $border = 0; if ($edge != null) { $border = mxUtils::getNumber($edge->style, mxConstants::$STYLE_PERIMETER_SPACING); $border += mxUtils::getNumber($edge->style, $isSource ? mxConstants::$STYLE_SOURCE_PERIMETER_SPACING : mxConstants::$STYLE_TARGET_PERIMETER_SPACING); } if ($terminal != null) { $border += mxUtils::getNumber($terminal->style, mxConstants::$STYLE_PERIMETER_SPACING); } return $terminal->getPerimeterBounds($border * $this->scale); }
/** * Function: drawShape * * Draws the given shape. */ function drawShape($shape, $x, $y, $w, $h, $fill = null, $stroke = null, $style = null) { $shadow = mxUtils::getValue($style, mxConstants::$STYLE_SHADOW); if ($shape == mxConstants::$SHAPE_IMAGE) { $image = $this->getImageForStyle($style); if ($image != null) { $this->drawImage($x, $y, $w, $h, $image); } } else { if ($shape == mxConstants::$SHAPE_ELLIPSE) { $this->drawOval($x, $y, $w, $h, $fill, $stroke, $shadow); } else { if ($shape == mxConstants::$SHAPE_LINE) { $direction = mxUtils::getValue($style, mxConstants::$STYLE_DIRECTION, mxConstants::$STYLE_EAST); if ($direction == mxConstants::$STYLE_EAST || $direction == mxConstants::$STYLE_WEST) { $mid = $y + $h / 2; $this->drawLine($x, $mid, $x + $w, $mid, $stroke); } else { $mid = $x + $w / 2; $this->drawLine($mid, $y, $mid, $y + $h, $stroke); } } else { if ($shape == mxConstants::$SHAPE_DOUBLE_ELLIPSE) { $this->drawOval($x, $y, $w, $h, $fill, $stroke, $shadow); $inset = (3 + 1) * $this->scale; $x += $inset; $y += $inset; $w -= 2 * $inset; $h -= 2 * $inset; $this->drawOval($x, $y, $w, $h, null, $stroke, false); } else { if ($shape == mxConstants::$SHAPE_RHOMBUS) { $this->drawRhombus($x, $y, $w, $h, $fill, $stroke, $shadow); } else { if ($shape == mxConstants::$SHAPE_TRIANGLE) { $dir = mxUtils::getValue($style, mxConstants::$STYLE_DIRECTION); $this->drawTriangle($x, $y, $w, $h, $fill, $stroke, $shadow, $dir); } else { if ($shape == mxConstants::$SHAPE_HEXAGON) { $dir = mxUtils::getValue($style, mxConstants::$STYLE_DIRECTION); $this->drawHexagon($x, $y, $w, $h, $fill, $stroke, $shadow, $dir); } else { if ($shape == mxConstants::$SHAPE_CYLINDER) { $this->drawCylinder($x, $y, $w, $h, $fill, $stroke, $shadow); } else { if ($shape == mxConstants::$SHAPE_CLOUD) { $this->drawCloud($x, $y, $w, $h, $fill, $stroke, $shadow); } else { if ($shape == mxConstants::$SHAPE_ACTOR) { $this->drawActor($x, $y, $w, $h, $fill, $stroke, $shadow); } else { $round = mxUtils::getValue($style, mxConstants::$STYLE_ROUNDED); $this->drawRect($x, $y, $w, $h, $fill, $stroke, $shadow, $round); if ($shape == mxConstants::$SHAPE_LABEL) { $image = $this->getImageForStyle($style); if ($image != null) { $imgAlign = mxUtils::getValue($style, mxConstants::$STYLE_IMAGE_ALIGN); $imgValign = mxUtils::getValue($style, mxConstants::$STYLE_IMAGE_VERTICAL_ALIGN); $imgWidth = mxUtils::getNumber($style, mxConstants::$STYLE_IMAGE_WIDTH, mxConstants::$DEFAULT_IMAGESIZE) * $this->scale; $imgHeight = mxUtils::getNumber($style, mxConstants::$STYLE_IMAGE_HEIGHT, mxConstants::$DEFAULT_IMAGESIZE) * $this->scale; $spacing = mxUtils::getNumber($style, mxConstants::$STYLE_SPACING, 2) * $this->scale; $imgX = $x; if ($imgAlign == mxConstants::$ALIGN_LEFT) { $imgX += $spacing; } else { if ($imgAlign == mxConstants::$ALIGN_RIGHT) { $imgX += $w - $imgWidth - $spacing; } else { $imgX += ($w - $imgWidth) / 2; } } $imgY = $y; if ($imgValign == mxConstants::$ALIGN_TOP) { $imgY += $spacing; } else { if ($imgValign == mxConstants::$ALIGN_BOTTOM) { $imgY += $h - $imgHeight - $spacing; } else { $imgY += ($h - $imgHeight) / 2; } } $this->drawImage($imgX, $imgY, $imgWidth, $imgHeight, $image); } } } } } } } } } } } } }
/** * Function: getPerimeterBounds * * Returns the perimeter bounds for the given terminal, edge pair as an * <mxRectangle>. * * Parameters: * * terminal - <mxCellState> that represents the terminal. * border - Number that adds a border between the shape and the perimeter. */ function getPerimeterBounds($terminal, $border = 0) { if ($terminal != null) { $border += mxUtils::getNumber($terminal->style, mxConstants::$STYLE_PERIMETER_SPACING); } return $terminal->getPerimeterBounds($border * $this->scale); }
/** * Function: drawLabel * * Draws the specified label using the canvas. */ function drawLabel($isEdge, $attrs) { $label = mxUtils::getValue($attrs, "label"); if (isset($label) && strlen($label) > 0) { $offset = new mxPoint(mxUtils::getNumber($attrs, "dx"), mxUtils::getNumber($attrs, "dy")); $vertexBounds = !$isEdge ? new mxRectangle(mxUtils::getNumber($attrs, "x"), mxUtils::getNumber($attrs, "y"), mxUtils::getNumber($attrs, "width"), mxUtils::getNumber($attrs, "height")) : null; $bounds = mxUtils::getLabelPaintBounds($label, $attrs, mxUtils::getValue($attrs, "html", false), $offset, $vertexBounds, $this->scale); $this->canvas->drawLabel($label, $bounds->x, $bounds->y, $bounds->width, $bounds->height, $attrs, false); } }