Hello,
I have made a small SVG-Document and want to change the fill-color of a
specific element dynamically. I have given this Element an ID-Attribut in
SVG to retrive it via getElementById()-Method. My problem is the fill-Attribute
now. As you surely know in SVG you can set this attribute either as an
attribute itself (as in fill="#000000") or as part of an style-Attribute (as in
style="fill:#000000"). whereas the style-attribute seems to have priority over
the fill-Attribute. To retrieve the fill-style I use
Value colorValue =
CSSUtilities.getComputedStyle(backgroundColorElement,SVGCSSEngine.FILL_INDEX);
which seems to work for both kinds of fill-attributes. To set a new fill-style
is what I could not figure out. To set the fill-style as an attribute could be
done via DOM with setAttribute() on the element, but since it has lower
priority this won't change the style if there is an style attribute. So I could
not
find how to set this style-attribute correcly via batik. At least I tried the
following, but it doesn't realy work. The resulting color was wrong:
if (backgroundColorElement instanceof CSSStylableElement) {
CSSStylableElement bceStylable = (CSSStylableElement)backgroundColorElement;
StyleMap sm = bceStylable.getComputedStyleMap(null);
if (sm != null) {
float[] rgbColors = Color.WHITE.getRGBColorComponents(null);
sm.putValue(SVGCSSEngine.FILL_INDEX,new RGBColorValue(
new FloatValue(
CSSPrimitiveValue.CSS_RGBCOLOR,
rgbColors[0]), new FloatValue(
CSSPrimitiveValue.CSS_RGBCOLOR,
rgbColors[1]), new FloatValue(
CSSPrimitiveValue.CSS_RGBCOLOR,
rgbColors[2])));
bceStylable.setComputedStyleMap(null, sm);
}
}
How can I set the fill-part of the style-attribute wothou parsing it for myself
?
Greetings
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]