This helps!
Thanks a lot!
Bishop, Michael W. CONTR J9C880 wrote:
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:[EMAIL PROTECTED]
Sent: Monday, April 02, 2007 9:37 AM
To: [email protected]
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: [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]