Hi Michael,
"Bishop, Michael W. CONTR J9C880" <[EMAIL PROTECTED]> wrote on
09/15/2006 11:49:59 AM:
> 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:
This is using the CSS DOM, so you need to make sure that you
have booted the CSS and SVG Dom's (see the wiki).
> <rect fill="white" .../>
>
> Do all the color values have to be in the CSS like <rect style="..."
> ..../>?
No getting computed style should calculate the fill for any
element.
> Is there another method to extract color information from a single
> attribute that will work regardless of how the color information is
> specified?
The given method should do this. You should be aware that there
cases where the SVG fill will not map to a simple java.awt.Color
(gradients, patterns).
> I get an NPE at the line where the SVGPaint object is declared.
Well if you provided the stack trace it would help.
But I could believe that you might get the NPE here if
the CSS DOM wasn't booted.
> -----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]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]