function preRender($im, &$map) { // don't bother drawing if it's a template if ($this->isTemplate()) { return; } // apparently, some versions of the gd extension will crash if we continue... if ($this->label == '' && $this->iconfile == '') { return; } $iconObj = null; $labelObj = null; $labelFillColour = $this->calculateFillColour(); $iconFillColour = $this->calculateIconFillColour(); // start these off with sensible values, so that bbox // calculations are easier. $icon_x1 = $this->x; $icon_x2 = $this->x; $icon_y1 = $this->y; $icon_y2 = $this->y; $label_x1 = $this->x; $label_x2 = $this->x; $label_y1 = $this->y; $label_y2 = $this->y; $boxWidth = 0; $boxHeight = 0; $icon_w = 0; $icon_h = 0; // figure out a bounding rectangle for the label if ($this->label != '') { $labelObj = new WMNodeLabel($this); $this->processedLabel = $map->ProcessString($this->label, $this, true, true); // if screenshot_mode is enabled, wipe any letters to X and wipe any IP address to 127.0.0.1 // hopefully that will preserve enough information to show cool stuff without leaking info if ($map->get_hint('screenshot_mode') == 1) { $this->processedLabel = WMUtility::stringAnonymise($this->processedLabel); } $labelObj->calculateGeometry($this->processedLabel, $this->labelfont); $labelObj->preRender($labelFillColour, $this->labeloutlinecolour, $this->labelfontshadowcolour, $this->labelfontcolour); } // figure out a bounding rectangle for the icon if ($this->iconfile != '') { $iconImageRef = null; $icon_w = 0; $icon_h = 0; if (WMNodeArtificialIcon::isAICONName($this->iconfile)) { $aiconFillColour = $this->aiconfillcolour; $aiconInkColour = $this->aiconoutlinecolour; // if useiconscale isn't defined, use the static colours defined by AICONFILLCOLOR and AICONOUTLINECOLOR // (or copy the colour from the label fill colour) if ($this->useiconscale == 'none') { if ($aiconFillColour->isCopy() && !$labelFillColour->isNone()) { $aiconFillColour = $labelFillColour; } } else { // if useiconscale IS defined, use that to figure out the file colour $aiconFillColour = $this->calculateIconFillColour(); } $iconObj = new WMNodeArtificialIcon($this, $aiconInkColour, $aiconFillColour, $iconFillColour, $labelFillColour); } else { $iconObj = new WMNodeImageIcon($this); } $iconObj->calculateGeometry(); $iconObj->preRender(); $iconImageRef = $iconObj->getImageRef(); if ($iconImageRef) { $icon_w2 = imagesx($iconImageRef) / 2; $icon_h2 = imagesy($iconImageRef) / 2; $iconRect = new WMRectangle(-$icon_w2, -$icon_h2, $icon_w2, $icon_h2); $iconRect->translate($this->x, $this->y); $icon_w = imagesx($iconImageRef); $icon_h = imagesy($iconImageRef); $icon_x1 = $this->x - $icon_w / 2; $icon_y1 = $this->y - $icon_h / 2; $icon_x2 = $this->x + $icon_w / 2; $icon_y2 = $this->y + $icon_h / 2; $this->width = imagesx($iconImageRef); $this->height = imagesy($iconImageRef); $this->boundingboxes[] = array($icon_x1, $icon_y1, $icon_x2, $icon_y2); } } // do any offset calculations $deltaX = 0; $deltaY = 0; if ($this->labeloffset != '' && $this->iconfile != '') { $this->labeloffsetx = 0; $this->labeloffsety = 0; list($deltaX, $deltaY) = WMUtility::calculateOffset($this->labeloffset, $icon_w + $boxWidth - 1, $icon_h + $boxHeight); } $label_x1 += $this->labeloffsetx + $deltaX; $label_x2 += $this->labeloffsetx + $deltaX; $label_y1 += $this->labeloffsety + $deltaY; $label_y2 += $this->labeloffsety + $deltaY; if ($this->label != '') { $this->boundingboxes[] = array($label_x1, $label_y1, $label_x2, $label_y2); } // work out the bounding box of the whole thing $totalBoundingBox = new WMBoundingBox(); // $totalBoundingBox->addRectangle(); // $totalBoundingBox->addRectangle(); $bbox_x1 = min($label_x1, $icon_x1); $bbox_x2 = max($label_x2, $icon_x2) + 1; $bbox_y1 = min($label_y1, $icon_y1); $bbox_y2 = max($label_y2, $icon_y2) + 1; // create TWO imagemap entries - one for the label and one for the icon // (so we can have close-spaced icons better) $temp_width = $bbox_x2 - $bbox_x1; $temp_height = $bbox_y2 - $bbox_y1; // create an image of that size and draw into it $node_im = imagecreatetruecolor($temp_width, $temp_height); // ImageAlphaBlending($node_im, false); imageSaveAlpha($node_im, true); $nothing = imagecolorallocatealpha($node_im, 128, 0, 0, 127); imagefill($node_im, 0, 0, $nothing); $label_x1 -= $bbox_x1; $label_x2 -= $bbox_x1; $label_y1 -= $bbox_y1; $label_y2 -= $bbox_y1; $icon_x1 -= $bbox_x1; $icon_y1 -= $bbox_y1; // Draw the icon, if any if (isset($iconImageRef)) { $iconObj->draw($node_im, $icon_x1, $icon_y1); // imagecopy($node_im, $iconImageRef, $icon_x1, $icon_y1, 0, 0, imagesx($iconImageRef), imagesy($iconImageRef)); // imagedestroy($iconImageRef); } // Draw the label, if any if ($this->label != '') { $labelObj->translate(-$bbox_x1 + $deltaX + $this->labeloffsetx, -$bbox_y1 + $deltaY + $this->labeloffsety); $labelObj->draw($node_im); } $this->centre_x = $this->x - $bbox_x1; $this->centre_y = $this->y - $bbox_y1; $this->image = $node_im; }
function preRender($im, &$map) { // don't bother drawing if it's a template if ($this->isTemplate()) { return; } // apparently, some versions of the gd extension will crash if we continue... if ($this->label == '' && $this->iconfile == '') { return; } $iconObj = null; $labelObj = null; $labelFillColour = $this->calculateFillColour(); $iconFillColour = $this->calculateIconFillColour(); // start these off with sensible values, so that bbox // calculations are easier. $icon_x1 = $this->x; $icon_x2 = $this->x; $icon_y1 = $this->y; $icon_y2 = $this->y; $label_x1 = $this->x; $label_x2 = $this->x; $label_y1 = $this->y; $label_y2 = $this->y; $boxWidth = 0; $boxHeight = 0; $icon_w = 0; $icon_h = 0; // figure out a bounding rectangle for the label if ($this->label != '') { $labelObj = new WMNodeLabel($this); $this->processedLabel = $map->ProcessString($this->label, $this, true, true); // if screenshot_mode is enabled, wipe any letters to X and wipe any IP address to 127.0.0.1 // hopefully that will preserve enough information to show cool stuff without leaking info if ($map->get_hint('screenshot_mode') == 1) { $this->processedLabel = WMUtility::stringAnonymise($this->processedLabel); } $labelObj->calculateGeometry($this->processedLabel, $this->labelfont); $labelObj->preRender($labelFillColour, $this->labeloutlinecolour, $this->labelfontshadowcolour, $this->labelfontcolour); // $padding = 4.0; // $padFactor = 1.0; // // // list($stringWidth, $stringHeight) = $map->myimagestringsize($this->labelfont, $this->processedLabel); // // if ($this->labelangle == 90 || $this->labelangle == 270) { // $boxWidth = ($stringHeight * $padFactor) + $padding; // $boxHeight = ($stringWidth * $padFactor) + $padding; // } else { // $boxWidth = ($stringWidth * $padFactor) + $padding; // $boxHeight = ($stringHeight * $padFactor) + $padding; // } // // $halfWidth = $boxWidth / 2; // $halfHeight = $boxHeight / 2; // // $label_x1 = $this->x - $halfWidth; // $label_y1 = $this->y - $halfHeight; // // $label_x2 = $this->x + $halfWidth; // $label_y2 = $this->y + $halfHeight; // // wm_debug("Node->pre_render: " . $this->name . " Label Metrics are: $stringWidth x $stringHeight -> $boxWidth x $boxHeight\n"); // // if ($this->labelangle == 90) { // $txt_x = $this->x + ($stringHeight / 2); // $txt_y = $this->y + ($stringWidth / 2); // } // // if ($this->labelangle == 270) { // $txt_x = $this->x - ($stringHeight / 2); // $txt_y = $this->y - ($stringWidth / 2); // } // // if ($this->labelangle == 0) { // $txt_x = $this->x - ($stringWidth / 2); // $txt_y = $this->y + ($stringHeight / 2); // } // // if ($this->labelangle == 180) { // $txt_x = $this->x + ($stringWidth / 2); // $txt_y = $this->y - ($stringHeight / 2); // } // // $this->width = $boxWidth; // $this->height = $boxHeight; } // figure out a bounding rectangle for the icon if ($this->iconfile != '') { $iconImageRef = null; $icon_w = 0; $icon_h = 0; // $artificialIconNames = array('rbox', 'round', 'box', 'inpie', 'outpie', 'gauge', 'nink'); //if (in_array($this->iconfile, $artificialIconNames)) { if (WMNodeArtificialIcon::isAICONName($this->iconfile)) { $iconObj = new WMNodeArtificialIcon($this, $aiconInkColour, $aiconFillColour, $iconFillColour, $aiconOutlineColour, $labelFillColour); } else { $iconObj = new WMNodeImageIcon($this); } $iconObj->calculateGeometry(); $iconObj->preRender(); $iconImageRef = $iconObj->getImageRef(); if ($iconImageRef) { $icon_w2 = imagesx($iconImageRef) / 2; $icon_h2 = imagesy($iconImageRef) / 2; $iconRect = new WMRectangle(-$icon_w2, -$icon_h2, $icon_w2, $icon_h2); $iconRect->translate($this->x, $this->y); $icon_w = imagesx($iconImageRef); $icon_h = imagesy($iconImageRef); $icon_x1 = $this->x - $icon_w / 2; $icon_y1 = $this->y - $icon_h / 2; $icon_x2 = $this->x + $icon_w / 2; $icon_y2 = $this->y + $icon_h / 2; $this->width = imagesx($iconImageRef); $this->height = imagesy($iconImageRef); $this->boundingboxes[] = array($icon_x1, $icon_y1, $icon_x2, $icon_y2); } } // do any offset calculations $deltaX = 0; $deltaY = 0; if ($this->labeloffset != '' && $this->iconfile != '') { $this->labeloffsetx = 0; $this->labeloffsety = 0; list($deltaX, $deltaY) = WMUtility::calculateOffset($this->labeloffset, $icon_w + $boxWidth - 1, $icon_h + $boxHeight); } $label_x1 += $this->labeloffsetx + $deltaX; $label_x2 += $this->labeloffsetx + $deltaX; $label_y1 += $this->labeloffsety + $deltaY; $label_y2 += $this->labeloffsety + $deltaY; if ($this->label != '') { $this->boundingboxes[] = array($label_x1, $label_y1, $label_x2, $label_y2); } // work out the bounding box of the whole thing $totalBoundingBox = new WMBoundingBox(); // $totalBoundingBox->addRectangle(); // $totalBoundingBox->addRectangle(); $bbox_x1 = min($label_x1, $icon_x1); $bbox_x2 = max($label_x2, $icon_x2) + 1; $bbox_y1 = min($label_y1, $icon_y1); $bbox_y2 = max($label_y2, $icon_y2) + 1; // create TWO imagemap entries - one for the label and one for the icon // (so we can have close-spaced icons better) $temp_width = $bbox_x2 - $bbox_x1; $temp_height = $bbox_y2 - $bbox_y1; // create an image of that size and draw into it $node_im = imagecreatetruecolor($temp_width, $temp_height); // ImageAlphaBlending($node_im, false); imageSaveAlpha($node_im, true); $nothing = imagecolorallocatealpha($node_im, 128, 0, 0, 127); imagefill($node_im, 0, 0, $nothing); $label_x1 -= $bbox_x1; $label_x2 -= $bbox_x1; $label_y1 -= $bbox_y1; $label_y2 -= $bbox_y1; $icon_x1 -= $bbox_x1; $icon_y1 -= $bbox_y1; $labelObj->translate(-$bbox_x1 + $deltaX + $this->labeloffsetx, -$bbox_y1 + $deltaY + $this->labeloffsety); // Draw the icon, if any if (isset($iconImageRef)) { $iconObj->draw($node_im); // imagecopy($node_im, $iconImageRef, $icon_x1, $icon_y1, 0, 0, imagesx($iconImageRef), imagesy($iconImageRef)); // imagedestroy($iconImageRef); } // Draw the label, if any if ($this->label != '') { $labelObj->draw($node_im); } $this->centre_x = $this->x - $bbox_x1; $this->centre_y = $this->y - $bbox_y1; $this->image = $node_im; }