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:[EMAIL PROTECTED] Sent: Monday, September 11, 2006 6:54 PM To: [email protected] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
