src/main/java/com/mxgraph/canvas/mxGraphicsCanvas2D.java
protected void htmlText(double x, double y, double w, double h, String str,
			String align, String valign, boolean wrap, String format,
			String overflow, boolean clip, double rotation)
	{
		x += state.dx;
		y += state.dy;

		JLabel textRenderer = getTextRenderer();

		if (textRenderer != null && rendererPane != null)
		{
			// Use native scaling for HTML
			AffineTransform previous = state.g.getTransform();
			double rad = rotation * (Math.PI / 180);
			state.g.rotate(rad, x, y);
			state.g.scale(state.scale * HTML_SCALE, state.scale * HTML_SCALE);

			// Renders the scaled text with a correction factor
			// HTML_SCALE for the given HTML_UNIT
			boolean widthFill = false;
			boolean fill = false;

			String original = str;

			if (overflow != null)
			{
				widthFill = overflow.equals("width");
				fill = overflow.equals("fill");
			}

			str = createHtmlDocument(str, align, valign,
					(widthFill || fill) ? (int) Math.round(w) : 0,
					(fill) ? (int) Math.round(h) : 0, wrap, overflow, clip);
			textRenderer.setText(str);
			Dimension pref = textRenderer.getPreferredSize();
			int prefWidth = pref.width;
			int prefHeight = pref.height;

			// Poor man's max-width
			// TODO: Is this still needed?
			if (((clip || wrap) && prefWidth > w / HTML_SCALE && w > 0)
					|| (clip && prefHeight > h / HTML_SCALE && h > 0))
			{
				// TextWidthDelta is workaround for inconsistent word wrapping in Java
				int cw = (int) Math
						.round((w) + ((wrap) ? JAVA_TEXT_WIDTH_DELTA : 0));
				int ch = (int) Math.round(h);
				str = createHtmlDocument(original, align, valign, cw, ch, wrap,
						overflow, clip);
				textRenderer.setText(str);

				pref = textRenderer.getPreferredSize();
				prefWidth = pref.width;
				prefHeight = pref.height + 2;
			}

			// Matches HTML output
			if (clip && w > 0 && h > 0)
			{
				prefWidth = Math.min(pref.width, (int) (w / HTML_SCALE));
				prefHeight = Math.min(prefHeight, (int) (h / HTML_SCALE));
				h = prefHeight * HTML_SCALE;
			}
			else if (!clip && wrap && w > 0 && h > 0)
			{
				prefWidth = pref.width;
				w = Math.max(pref.width, (int) (w / HTML_SCALE));
				h = prefHeight * HTML_SCALE;
				prefHeight = Math.max(prefHeight, (int) (h / HTML_SCALE));
			}
			else if (!clip && !wrap)
			{
				if (w > 0 && w / HTML_SCALE < prefWidth)
				{
					w = prefWidth * HTML_SCALE;
				}

				if (h > 0 && h / HTML_SCALE < prefHeight)
				{
					h = prefHeight * HTML_SCALE;
				}
			}

			Point2D margin = getMargin(align, valign);
			x += margin.getX() * prefWidth * HTML_SCALE;
			y += margin.getY() * prefHeight * HTML_SCALE;

			if (w == 0)
			{
				w = prefWidth * HTML_SCALE;
			}

			if (h == 0)
			{
				h = prefHeight * HTML_SCALE;
			}

			rendererPane.paintComponent(state.g, textRenderer, rendererPane,
					(int) Math.round(x / HTML_SCALE),
					(int) Math.round(y / HTML_SCALE),
					(int) Math.round(w / HTML_SCALE),
					(int) Math.round(h / HTML_SCALE), true);

			state.g.setTransform(previous);
		}
	}
/**
	 * Draws the given HTML text.
	 */
Draws the given HTML text.
Draws the given HTML text .
protected void htmlText(double x, double y, double w, double h, String str,
			String align, String valign, boolean wrap, String format,
			String overflow, boolean clip, double rotation)
	{
		x += state.dx;
		y += state.dy;
		JLabel textRenderer = getTextRenderer();
		if (textRenderer != null && rendererPane != null)
		{
			AffineTransform previous = state.g.getTransform();
			double rad = rotation * (Math.PI / 180);
			state.g.rotate(rad, x, y);
			state.g.scale(state.scale * HTML_SCALE, state.scale * HTML_SCALE);
			boolean widthFill = false;
			boolean fill = false;
			String original = str;
			if (overflow != null)
			{
				widthFill = overflow.equals("width");
				fill = overflow.equals("fill");
			}
			str = createHtmlDocument(str, align, valign,
					(widthFill || fill) ? (int) Math.round(w) : 0,
					(fill) ? (int) Math.round(h) : 0, wrap, overflow, clip);
			textRenderer.setText(str);
			Dimension pref = textRenderer.getPreferredSize();
			int prefWidth = pref.width;
			int prefHeight = pref.height;
			if (((clip || wrap) && prefWidth > w / HTML_SCALE && w > 0)
					|| (clip && prefHeight > h / HTML_SCALE && h > 0))
			{
				int cw = (int) Math
						.round((w) + ((wrap) ? JAVA_TEXT_WIDTH_DELTA : 0));
				int ch = (int) Math.round(h);
				str = createHtmlDocument(original, align, valign, cw, ch, wrap,
						overflow, clip);
				textRenderer.setText(str);
				pref = textRenderer.getPreferredSize();
				prefWidth = pref.width;
				prefHeight = pref.height + 2;
			}
			if (clip && w > 0 && h > 0)
			{
				prefWidth = Math.min(pref.width, (int) (w / HTML_SCALE));
				prefHeight = Math.min(prefHeight, (int) (h / HTML_SCALE));
				h = prefHeight * HTML_SCALE;
			}
			else if (!clip && wrap && w > 0 && h > 0)
			{
				prefWidth = pref.width;
				w = Math.max(pref.width, (int) (w / HTML_SCALE));
				h = prefHeight * HTML_SCALE;
				prefHeight = Math.max(prefHeight, (int) (h / HTML_SCALE));
			}
			else if (!clip && !wrap)
			{
				if (w > 0 && w / HTML_SCALE < prefWidth)
				{
					w = prefWidth * HTML_SCALE;
				}
				if (h > 0 && h / HTML_SCALE < prefHeight)
				{
					h = prefHeight * HTML_SCALE;
				}
			}
			Point2D margin = getMargin(align, valign);
			x += margin.getX() * prefWidth * HTML_SCALE;
			y += margin.getY() * prefHeight * HTML_SCALE;
			if (w == 0)
			{
				w = prefWidth * HTML_SCALE;
			}
			if (h == 0)
			{
				h = prefHeight * HTML_SCALE;
			}
			rendererPane.paintComponent(state.g, textRenderer, rendererPane,
					(int) Math.round(x / HTML_SCALE),
					(int) Math.round(y / HTML_SCALE),
					(int) Math.round(w / HTML_SCALE),
					(int) Math.round(h / HTML_SCALE), true);
			state.g.setTransform(previous);
		}
	}
protected void htmlText ( double x , double y , double w , double h , String str , String align , String valign , boolean wrap , String format , String overflow , boolean clip , double rotation ) { x += state . dx ; y += state . dy ; JLabel textRenderer = getTextRenderer ( ) ; if ( textRenderer != null && rendererPane != null ) { AffineTransform previous = state . g . getTransform ( ) ; double rad = rotation * ( Math . PI / 180 ) ; state . g . rotate ( rad , x , y ) ; state . g . scale ( state . scale * HTML_SCALE , state . scale * HTML_SCALE ) ; boolean widthFill = false ; boolean fill = false ; String original = str ; if ( overflow != null ) { widthFill = overflow . equals ( "width" ) ; fill = overflow . equals ( "fill" ) ; } str = createHtmlDocument ( str , align , valign , ( widthFill || fill ) ? ( int ) Math . round ( w ) : 0 , ( fill ) ? ( int ) Math . round ( h ) : 0 , wrap , overflow , clip ) ; textRenderer . setText ( str ) ; Dimension pref = textRenderer . getPreferredSize ( ) ; int prefWidth = pref . width ; int prefHeight = pref . height ; if ( ( ( clip || wrap ) && prefWidth > w / HTML_SCALE && w > 0 ) || ( clip && prefHeight > h / HTML_SCALE && h > 0 ) ) { int cw = ( int ) Math . round ( ( w ) + ( ( wrap ) ? JAVA_TEXT_WIDTH_DELTA : 0 ) ) ; int ch = ( int ) Math . round ( h ) ; str = createHtmlDocument ( original , align , valign , cw , ch , wrap , overflow , clip ) ; textRenderer . setText ( str ) ; pref = textRenderer . getPreferredSize ( ) ; prefWidth = pref . width ; prefHeight = pref . height + 2 ; } if ( clip && w > 0 && h > 0 ) { prefWidth = Math . min ( pref . width , ( int ) ( w / HTML_SCALE ) ) ; prefHeight = Math . min ( prefHeight , ( int ) ( h / HTML_SCALE ) ) ; h = prefHeight * HTML_SCALE ; } else if ( ! clip && wrap && w > 0 && h > 0 ) { prefWidth = pref . width ; w = Math . max ( pref . width , ( int ) ( w / HTML_SCALE ) ) ; h = prefHeight * HTML_SCALE ; prefHeight = Math . max ( prefHeight , ( int ) ( h / HTML_SCALE ) ) ; } else if ( ! clip && ! wrap ) { if ( w > 0 && w / HTML_SCALE < prefWidth ) { w = prefWidth * HTML_SCALE ; } if ( h > 0 && h / HTML_SCALE < prefHeight ) { h = prefHeight * HTML_SCALE ; } } Point2D margin = getMargin ( align , valign ) ; x += margin . getX ( ) * prefWidth * HTML_SCALE ; y += margin . getY ( ) * prefHeight * HTML_SCALE ; if ( w == 0 ) { w = prefWidth * HTML_SCALE ; } if ( h == 0 ) { h = prefHeight * HTML_SCALE ; } rendererPane . paintComponent ( state . g , textRenderer , rendererPane , ( int ) Math . round ( x / HTML_SCALE ) , ( int ) Math . round ( y / HTML_SCALE ) , ( int ) Math . round ( w / HTML_SCALE ) , ( int ) Math . round ( h / HTML_SCALE ) , true ) ; state . g . setTransform ( previous ) ; } }
Draws the given HTML text.
Draws the given HTML text .
// Use native scaling for HTML // Renders the scaled text with a correction factor // HTML_SCALE for the given HTML_UNIT // Poor man's max-width // TODO: Is this still needed? // TextWidthDelta is workaround for inconsistent word wrapping in Java // Matches HTML output