xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cameron McCormack <...@mcc.id.au>
Subject Re: setting attributes dynamically
Date Fri, 09 Mar 2007 06:21:49 GMT
Hi Leo.

Leo Lim:
> Is it possible to set attributes (fill, stroke) dynamically?

Sure.

> The g elements in my svg file have already defined the stroke element as you
> can see below,

No, the g element doesn’t define a stroke.  The two path elements do.

> <g id="Rudder_Trim_Knob">
> 
> <path i:knockout="Off" fill="#B2B2B2" stroke="#000000" stroke-width="0.9684"
> d="M202.786,159.913
> 
>  
> c59.836,0,108.342,48.437,108.342,108.184c0,59.75-48.506,108.189-108.342,108.
> 189c-59.834,0-108.342-48.439-108.342-108.189
> 
>             C94.444,208.35,142.952,159.913,202.786,159.913z"/>
> 
>             <path i:knockout="Off" fill="#F2F2F2" stroke="#000000"
> stroke-width="0.9684" d="M175.799,166.63
> 
> .
> 
> </g>
> 
>  
> 
> With this setup, is it possible to call
> target.setAttribute(SVGConstants.SVG_STROKE_ATTRIBUTE, "green");
> 
> I tried this one and nothing happened. However, when I removed the stroke
> definitions above, I was able
> 
> to set it successfully using setAttribute.

If target is actually the g element, then that is the expected
behaviour, since the stroke property inherits down the tree.  The path
elements then override the stroke with the stroke="#000000" attributes.

So if you want to be able to set both paths’ stroke to green at once,
you should put stroke="#000000" on the g element to begin with, and then
update it from your script.

Cameron

-- 
Cameron McCormack, http://mcc.id.au/
	xmpp:heycam@jabber.org  ▪  ICQ 26955922  ▪  MSN cam@mcc.id.au

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message