src/main/java/com/mxgraph/canvas/mxSvgCanvas.java
public Object drawText(String text, int x, int y, int w, int h,
			Map<String, Object> style)
	{
		Element elem = null;
		String fontColor = mxUtils.getString(style,
				mxConstants.STYLE_FONTCOLOR, "black");
		String fontFamily = mxUtils.getString(style,
				mxConstants.STYLE_FONTFAMILY, mxConstants.DEFAULT_FONTFAMILIES);
		int fontSize = (int) (mxUtils.getInt(style, mxConstants.STYLE_FONTSIZE,
				mxConstants.DEFAULT_FONTSIZE) * scale);

		if (text != null && text.length() > 0)
		{
			float strokeWidth = (float) (mxUtils.getFloat(style,
					mxConstants.STYLE_STROKEWIDTH, 1) * scale);

			// Applies the opacity
			float opacity = mxUtils.getFloat(style,
					mxConstants.STYLE_TEXT_OPACITY, 100);

			// Draws the label background and border
			String bg = mxUtils.getString(style,
					mxConstants.STYLE_LABEL_BACKGROUNDCOLOR);
			String border = mxUtils.getString(style,
					mxConstants.STYLE_LABEL_BORDERCOLOR);

			String transform = null;

			if (!mxUtils.isTrue(style, mxConstants.STYLE_HORIZONTAL, true))
			{
				double cx = x + w / 2;
				double cy = y + h / 2;
				transform = "rotate(270 " + cx + " " + cy + ")";
			}

			if (bg != null || border != null)
			{
				Element background = document.createElement("rect");

				background.setAttribute("x", String.valueOf(x));
				background.setAttribute("y", String.valueOf(y));
				background.setAttribute("width", String.valueOf(w));
				background.setAttribute("height", String.valueOf(h));

				if (bg != null)
				{
					background.setAttribute("fill", bg);
				}
				else
				{
					background.setAttribute("fill", "none");
				}

				if (border != null)
				{
					background.setAttribute("stroke", border);
				}
				else
				{
					background.setAttribute("stroke", "none");
				}

				background.setAttribute("stroke-width",
						String.valueOf(strokeWidth));

				if (opacity != 100)
				{
					String value = String.valueOf(opacity / 100);
					background.setAttribute("fill-opacity", value);
					background.setAttribute("stroke-opacity", value);
				}

				if (transform != null)
				{
					background.setAttribute("transform", transform);
				}

				appendSvgElement(background);
			}

			elem = document.createElement("text");

			int fontStyle = mxUtils.getInt(style, mxConstants.STYLE_FONTSTYLE);
			String weight = ((fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD) ? "bold"
					: "normal";
			elem.setAttribute("font-weight", weight);
			
			String txtDecor = "";
			
			if ((fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
		    {
				txtDecor = "underline";
		    }
		    
		    if ((fontStyle & mxConstants.FONT_STRIKETHROUGH) == mxConstants.FONT_STRIKETHROUGH)
		    {
		    	txtDecor += " line-through";
		    }

	    	elem.setAttribute("font-decoration", txtDecor.length() > 0 ? txtDecor : "none");

			if ((fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC)
			{
				elem.setAttribute("font-style", "italic");
			}

			elem.setAttribute("font-size", String.valueOf(fontSize));
			elem.setAttribute("font-family", fontFamily);
			elem.setAttribute("fill", fontColor);

			if (opacity != 100)
			{
				String value = String.valueOf(opacity / 100);
				elem.setAttribute("fill-opacity", value);
				elem.setAttribute("stroke-opacity", value);
			}

			int swingFontStyle = ((fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD) ? Font.BOLD
					: Font.PLAIN;
			swingFontStyle += ((fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC) ? Font.ITALIC
					: Font.PLAIN;

			String[] lines = text.split("\n");
			y += fontSize
					+ (h - lines.length * (fontSize + mxConstants.LINESPACING))
					/ 2 - 2;

			String align = mxUtils.getString(style, mxConstants.STYLE_ALIGN,
					mxConstants.ALIGN_CENTER);
			String anchor = "start";

			if (align.equals(mxConstants.ALIGN_RIGHT))
			{
				anchor = "end";
				x += w - mxConstants.LABEL_INSET * scale;
			}
			else if (align.equals(mxConstants.ALIGN_CENTER))
			{
				anchor = "middle";
				x += w / 2;
			}
			else
			{
				x += mxConstants.LABEL_INSET * scale;
			}

			elem.setAttribute("text-anchor", anchor);

			for (int i = 0; i < lines.length; i++)
			{
				Element tspan = document.createElement("tspan");

				tspan.setAttribute("x", String.valueOf(x));
				tspan.setAttribute("y", String.valueOf(y));

				tspan.appendChild(document.createTextNode(lines[i]));
				elem.appendChild(tspan);

				y += fontSize + mxConstants.LINESPACING;
			}

			if (transform != null)
			{
				elem.setAttribute("transform", transform);
			}

			appendSvgElement(elem);
		}

		return elem;
	}
/**
	 * Draws the specified text either using drawHtmlString or using drawString.
	 * 
	 * @param text Text to be painted.
	 * @param x X-coordinate of the text.
	 * @param y Y-coordinate of the text.
	 * @param w Width of the text.
	 * @param h Height of the text.
	 * @param style Style to be used for painting the text.
	 */
Draws the specified text either using drawHtmlString or using drawString.

@param text Text to be painted.
@param x X-coordinate of the text.
@param y Y-coordinate of the text.
@param w Width of the text.
@param h Height of the text.
@param style Style to be used for painting the text.
Draws the specified text either using drawHtmlString or using drawString . @param text Text to be painted . @param x X - coordinate of the text . @param y Y - coordinate of the text . @param w Width of the text . @param h Height of the text . @param style Style to be used for painting the text .
public Object drawText(String text, int x, int y, int w, int h,
			Map<String, Object> style)
	{
		Element elem = null;
		String fontColor = mxUtils.getString(style,
				mxConstants.STYLE_FONTCOLOR, "black");
		String fontFamily = mxUtils.getString(style,
				mxConstants.STYLE_FONTFAMILY, mxConstants.DEFAULT_FONTFAMILIES);
		int fontSize = (int) (mxUtils.getInt(style, mxConstants.STYLE_FONTSIZE,
				mxConstants.DEFAULT_FONTSIZE) * scale);
		if (text != null && text.length() > 0)
		{
			float strokeWidth = (float) (mxUtils.getFloat(style,
					mxConstants.STYLE_STROKEWIDTH, 1) * scale);
			float opacity = mxUtils.getFloat(style,
					mxConstants.STYLE_TEXT_OPACITY, 100);
			String bg = mxUtils.getString(style,
					mxConstants.STYLE_LABEL_BACKGROUNDCOLOR);
			String border = mxUtils.getString(style,
					mxConstants.STYLE_LABEL_BORDERCOLOR);
			String transform = null;
			if (!mxUtils.isTrue(style, mxConstants.STYLE_HORIZONTAL, true))
			{
				double cx = x + w / 2;
				double cy = y + h / 2;
				transform = "rotate(270 " + cx + " " + cy + ")";
			}
			if (bg != null || border != null)
			{
				Element background = document.createElement("rect");
				background.setAttribute("x", String.valueOf(x));
				background.setAttribute("y", String.valueOf(y));
				background.setAttribute("width", String.valueOf(w));
				background.setAttribute("height", String.valueOf(h));
				if (bg != null)
				{
					background.setAttribute("fill", bg);
				}
				else
				{
					background.setAttribute("fill", "none");
				}
				if (border != null)
				{
					background.setAttribute("stroke", border);
				}
				else
				{
					background.setAttribute("stroke", "none");
				}
				background.setAttribute("stroke-width",
						String.valueOf(strokeWidth));
				if (opacity != 100)
				{
					String value = String.valueOf(opacity / 100);
					background.setAttribute("fill-opacity", value);
					background.setAttribute("stroke-opacity", value);
				}
				if (transform != null)
				{
					background.setAttribute("transform", transform);
				}
				appendSvgElement(background);
			}
			elem = document.createElement("text");
			int fontStyle = mxUtils.getInt(style, mxConstants.STYLE_FONTSTYLE);
			String weight = ((fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD) ? "bold"
					: "normal";
			elem.setAttribute("font-weight", weight);
			String txtDecor = "";
			if ((fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
		    {
				txtDecor = "underline";
		    }
		    if ((fontStyle & mxConstants.FONT_STRIKETHROUGH) == mxConstants.FONT_STRIKETHROUGH)
		    {
		    	txtDecor += " line-through";
		    }
	    	elem.setAttribute("font-decoration", txtDecor.length() > 0 ? txtDecor : "none");
			if ((fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC)
			{
				elem.setAttribute("font-style", "italic");
			}
			elem.setAttribute("font-size", String.valueOf(fontSize));
			elem.setAttribute("font-family", fontFamily);
			elem.setAttribute("fill", fontColor);
			if (opacity != 100)
			{
				String value = String.valueOf(opacity / 100);
				elem.setAttribute("fill-opacity", value);
				elem.setAttribute("stroke-opacity", value);
			}
			int swingFontStyle = ((fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD) ? Font.BOLD
					: Font.PLAIN;
			swingFontStyle += ((fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC) ? Font.ITALIC
					: Font.PLAIN;
			String[] lines = text.split("\n");
			y += fontSize
					+ (h - lines.length * (fontSize + mxConstants.LINESPACING))
					/ 2 - 2;
			String align = mxUtils.getString(style, mxConstants.STYLE_ALIGN,
					mxConstants.ALIGN_CENTER);
			String anchor = "start";
			if (align.equals(mxConstants.ALIGN_RIGHT))
			{
				anchor = "end";
				x += w - mxConstants.LABEL_INSET * scale;
			}
			else if (align.equals(mxConstants.ALIGN_CENTER))
			{
				anchor = "middle";
				x += w / 2;
			}
			else
			{
				x += mxConstants.LABEL_INSET * scale;
			}
			elem.setAttribute("text-anchor", anchor);
			for (int i = 0; i < lines.length; i++)
			{
				Element tspan = document.createElement("tspan");
				tspan.setAttribute("x", String.valueOf(x));
				tspan.setAttribute("y", String.valueOf(y));
				tspan.appendChild(document.createTextNode(lines[i]));
				elem.appendChild(tspan);
				y += fontSize + mxConstants.LINESPACING;
			}
			if (transform != null)
			{
				elem.setAttribute("transform", transform);
			}
			appendSvgElement(elem);
		}
		return elem;
	}
public Object drawText ( String text , int x , int y , int w , int h , Map < String , Object > style ) { Element elem = null ; String fontColor = mxUtils . getString ( style , mxConstants . STYLE_FONTCOLOR , "black" ) ; String fontFamily = mxUtils . getString ( style , mxConstants . STYLE_FONTFAMILY , mxConstants . DEFAULT_FONTFAMILIES ) ; int fontSize = ( int ) ( mxUtils . getInt ( style , mxConstants . STYLE_FONTSIZE , mxConstants . DEFAULT_FONTSIZE ) * scale ) ; if ( text != null && text . length ( ) > 0 ) { float strokeWidth = ( float ) ( mxUtils . getFloat ( style , mxConstants . STYLE_STROKEWIDTH , 1 ) * scale ) ; float opacity = mxUtils . getFloat ( style , mxConstants . STYLE_TEXT_OPACITY , 100 ) ; String bg = mxUtils . getString ( style , mxConstants . STYLE_LABEL_BACKGROUNDCOLOR ) ; String border = mxUtils . getString ( style , mxConstants . STYLE_LABEL_BORDERCOLOR ) ; String transform = null ; if ( ! mxUtils . isTrue ( style , mxConstants . STYLE_HORIZONTAL , true ) ) { double cx = x + w / 2 ; double cy = y + h / 2 ; transform = "rotate(270 " + cx + " " + cy + ")" ; } if ( bg != null || border != null ) { Element background = document . createElement ( "rect" ) ; background . setAttribute ( "x" , String . valueOf ( x ) ) ; background . setAttribute ( "y" , String . valueOf ( y ) ) ; background . setAttribute ( "width" , String . valueOf ( w ) ) ; background . setAttribute ( "height" , String . valueOf ( h ) ) ; if ( bg != null ) { background . setAttribute ( "fill" , bg ) ; } else { background . setAttribute ( "fill" , "none" ) ; } if ( border != null ) { background . setAttribute ( "stroke" , border ) ; } else { background . setAttribute ( "stroke" , "none" ) ; } background . setAttribute ( "stroke-width" , String . valueOf ( strokeWidth ) ) ; if ( opacity != 100 ) { String value = String . valueOf ( opacity / 100 ) ; background . setAttribute ( "fill-opacity" , value ) ; background . setAttribute ( "stroke-opacity" , value ) ; } if ( transform != null ) { background . setAttribute ( "transform" , transform ) ; } appendSvgElement ( background ) ; } elem = document . createElement ( "text" ) ; int fontStyle = mxUtils . getInt ( style , mxConstants . STYLE_FONTSTYLE ) ; String weight = ( ( fontStyle & mxConstants . FONT_BOLD ) == mxConstants . FONT_BOLD ) ? "bold" : "normal" ; elem . setAttribute ( "font-weight" , weight ) ; String txtDecor = "" ; if ( ( fontStyle & mxConstants . FONT_UNDERLINE ) == mxConstants . FONT_UNDERLINE ) { txtDecor = "underline" ; } if ( ( fontStyle & mxConstants . FONT_STRIKETHROUGH ) == mxConstants . FONT_STRIKETHROUGH ) { txtDecor += " line-through" ; } elem . setAttribute ( "font-decoration" , txtDecor . length ( ) > 0 ? txtDecor : "none" ) ; if ( ( fontStyle & mxConstants . FONT_ITALIC ) == mxConstants . FONT_ITALIC ) { elem . setAttribute ( "font-style" , "italic" ) ; } elem . setAttribute ( "font-size" , String . valueOf ( fontSize ) ) ; elem . setAttribute ( "font-family" , fontFamily ) ; elem . setAttribute ( "fill" , fontColor ) ; if ( opacity != 100 ) { String value = String . valueOf ( opacity / 100 ) ; elem . setAttribute ( "fill-opacity" , value ) ; elem . setAttribute ( "stroke-opacity" , value ) ; } int swingFontStyle = ( ( fontStyle & mxConstants . FONT_BOLD ) == mxConstants . FONT_BOLD ) ? Font . BOLD : Font . PLAIN ; swingFontStyle += ( ( fontStyle & mxConstants . FONT_ITALIC ) == mxConstants . FONT_ITALIC ) ? Font . ITALIC : Font . PLAIN ; String [ ] lines = text . split ( "\n" ) ; y += fontSize + ( h - lines . length * ( fontSize + mxConstants . LINESPACING ) ) / 2 - 2 ; String align = mxUtils . getString ( style , mxConstants . STYLE_ALIGN , mxConstants . ALIGN_CENTER ) ; String anchor = "start" ; if ( align . equals ( mxConstants . ALIGN_RIGHT ) ) { anchor = "end" ; x += w - mxConstants . LABEL_INSET * scale ; } else if ( align . equals ( mxConstants . ALIGN_CENTER ) ) { anchor = "middle" ; x += w / 2 ; } else { x += mxConstants . LABEL_INSET * scale ; } elem . setAttribute ( "text-anchor" , anchor ) ; for ( int i = 0 ; i < lines . length ; i ++ ) { Element tspan = document . createElement ( "tspan" ) ; tspan . setAttribute ( "x" , String . valueOf ( x ) ) ; tspan . setAttribute ( "y" , String . valueOf ( y ) ) ; tspan . appendChild ( document . createTextNode ( lines [ i ] ) ) ; elem . appendChild ( tspan ) ; y += fontSize + mxConstants . LINESPACING ; } if ( transform != null ) { elem . setAttribute ( "transform" , transform ) ; } appendSvgElement ( elem ) ; } return elem ; }
Draws the specified text either using drawHtmlString or using drawString.
Draws the specified text either using drawHtmlString or using drawString .
// Applies the opacity // Draws the label background and border