xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bishop, Michael W. CONTR J9C880" <Michael.Bis...@je.jfcom.mil>
Subject RE: JSVGCanvas background
Date Fri, 15 Sep 2006 15:49:59 GMT
Hi, I'm actually interested in reversing the color attributes in an SVG
document to java.awt.Color objects.  I don't entirely understand this
method, but it doesn't seem to work for me:

<rect fill="white" .../>

Do all the color values have to be in the CSS like <rect style="..."
..../>?

Is there another method to extract color information from a single
attribute that will work regardless of how the color information is
specified?

I get an NPE at the line where the SVGPaint object is declared.

Michael Bishop

-----Original Message-----
From: V. de Weger [mailto:batik@beno-delft.nl] 
Sent: Monday, September 11, 2006 6:54 PM
To: batik-users@xmlgraphics.apache.org
Subject: Re: JSVGCanvas background


Sometimes it's so simple... yes that works. 

I've found an old post which does someting like this:

	public static Color getFillColor(Element element) {
		Document doc = element.getOwnerDocument();
		ViewCSS viewCSS = (ViewCSS) element.getOwnerDocument()
				.getDocumentElement();

		CSSStyleDeclaration computedStyle =
viewCSS.getComputedStyle(element,
				null);
		SVGPaint svgPaint = (SVGPaint) computedStyle
	
..getPropertyCSSValue(SVGConstants.SVG_FILL_ATTRIBUTE);
		Color color = null;
		if (svgPaint.getPaintType() ==
SVGPaint.SVG_PAINTTYPE_RGBCOLOR) {
			RGBColor rgb = svgPaint.getRGBColor();
			float r =
rgb.getRed().getFloatValue(CSSValue.CSS_PRIMITIVE_VALUE);
			float g = rgb.getGreen()
	
..getFloatValue(CSSValue.CSS_PRIMITIVE_VALUE);
			float b =
rgb.getBlue().getFloatValue(CSSValue.CSS_PRIMITIVE_VALUE);
			color = new Color(r / 255, g / 255, b / 255);
		}
		
		return color;
	}

It doesn't compile yet, but it's probably close isn't it?

Vincent
-- 
View this message in context:
http://www.nabble.com/JSVGCanvas-background-tf2239369.html#a6256717
Sent from the Batik - Users forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message