Exemplo n.º 1
0
 /**
  * Function: getFixedFontSize
  * 
  * Returns the fixed font size for GD (1 t0 5) for the given font properties
  */
 function getFixedFontSize($fontSize, $fontFamily, $fontStyle = null)
 {
     return mxUtils::getFixedFontSize($fontSize, $fontFamily);
 }
Exemplo n.º 2
0
 /**
  * Function: getSizeForString
  * 
  * Returns an <mxRectangle> with the size (width and height in pixels) of
  * the given string. The string may contain HTML markup. Newlines should be
  * converted to <br> before calling this method.
  * 
  * Parameters:
  * 
  * text - String whose size should be returned.
  * fontSize - Integer that specifies the font size in pixels. Default is
  * <mxConstants.DEFAULT_FONTSIZE>.
  * fontFamily - String that specifies the name of the font famil.y Default
  * is <mxConstants.DEFAULT_FONTFAMILY>.
  * 
  */
 static function getSizeForString($text, $fontSize = 0, $fontFamily = null)
 {
     if (is_string($text) && strlen($text) > 0) {
         if ($fontSize == 0) {
             $fontSize = mxConstants::$DEFAULT_FONTSIZE;
         }
         if ($fontFamily == null) {
             $fontFamily = mxConstants::$DEFAULT_FONTFAMILY;
         }
         $lines = explode("\n", $text);
         $lineCount = sizeof($lines);
         if (mxConstants::$TTF_ENABLED && function_exists("imagettfbbox")) {
             $bbox = imagettfbbox($fontSize * mxConstants::$TTF_SIZEFACTOR, 0, $fontFamily, $text);
             $textWidth = $bbox[2] - $bbox[0];
             $textHeight = ($fontSize + mxConstants::$DEFAULT_LINESPACING) * $lineCount;
             return new mxRectangle(0, 0, $textWidth, $textHeight);
         } else {
             if (function_exists("imageFontHeight") && function_exists("imageFontWidth")) {
                 $font = mxUtils::getFixedFontSize($fontSize, $fontFamily);
                 $textHeight = (imageFontHeight($font) + mxConstants::$DEFAULT_LINESPACING) * $lineCount;
                 $charWidth = imageFontWidth($font);
                 $textWidth = 0;
                 for ($i = 0; $i < sizeof($lines); $i++) {
                     $textWidth = max($textWidth, $charWidth * strlen($lines[$i]));
                 }
                 return new mxRectangle(0, 0, $textWidth, $textHeight);
             }
         }
     }
     return new mxRectangle();
 }