List Info

Thread: java.awt.Color ->SVG




java.awt.Color ->SVG
user name
2007-04-02 08:36:40
Hi,

What is the best way to convert back and forth from
java.awt.Color instances to SVG attributes.

Thanks a lot!
Daniel

------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org


RE: java.awt.Color ->SVG
country flaguser name
United States
2007-04-02 09:16:50
java.awt.Color -> SVG:

    public static Map convertColor(Document document, Color
color) {
        final SVGGeneratorContext svgContext =
            SVGGeneratorContext.createDefault(document);
        final SVGColor svgColor = new SVGColor(svgContext);

        return svgColor.toSVG(color,
svgContext).getAttributeMap(null);
    }

SVG -> java.awt.Color (attribute is the attribute of the
element you
want to get a color value for):

    public static Color getColor(Element element, String
attribute) {
        Color returnColor = null;
        final Document document =
element.getOwnerDocument();
        final ViewCSS viewCSS = (ViewCSS)
document.getDocumentElement();
        final CSSStyleDeclaration computedStyle =
            viewCSS.getComputedStyle(element, null);
        final SVGPaint svgPaint =
            (SVGPaint)
computedStyle.getPropertyCSSValue(attribute);

        if (svgPaint.getPaintType() ==
SVGPaint.SVG_PAINTTYPE_RGBCOLOR)
{
            final RGBColor rgb = svgPaint.getRGBColor();
            final float red =
 
rgb.getRed().getFloatValue(CSSValue.CSS_PRIMITIVE_VALUE);
            final float green =
 
rgb.getGreen().getFloatValue(CSSValue.CSS_PRIMITIVE_VALUE);
            final float blue =
 
rgb.getBlue().getFloatValue(CSSValue.CSS_PRIMITIVE_VALUE);
            returnColor = new Color(red / 255, green / 255,
blue / 255);
        }

        return returnColor;
    }

Michael Bishop

-----Original Message-----
From: Daniel Meyer [mailto:daniel.meyerpt.lu] 
Sent: Monday, April 02, 2007 9:37 AM
To: batik-usersxmlgraphics.apache.org
Subject: java.awt.Color ->SVG

Hi,

What is the best way to convert back and forth from
java.awt.Color instances to SVG attributes.

Thanks a lot!
Daniel

------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )