Hi James.

James M Banasiak:
> First, Thank you for providing Batik, I find it very useful.  
>  
> I was wondering if there is any documentation on changing the color of an
> SVG element by using the 'transcoder' engine in java.
> So basically I have a SVG, and to simplify it has four squares in it.  The
> squares are labeled a,b,c,d respectively within the SVG.
> Now, how can I change the color of square a to red, b to blue, c to green
> and d to yellow without providing css.

Well, if you are in Java you can modify the document as you wish before
passing it off to the transcoder.  You can use the standard DOM methods
to set the fill attribute for each square.

Take the example at
http://xmlgraphics.apache.org/batik/using/transcoder.html in section
“Generating an image from an SVG DOM tree”.  It shows you how to take an
SVG DOM tree and pass it to the transcoder.  Instead of creating the
document from scratch in the createDocument() method, you could load the
document using SAXSVGDocumentFactory.createDocument
(http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/dom/svg/SAXSVGDocumentFactory.html#createDocument%28java.lang.String%29)
and then modify it.

> Can I instruct the transcoder to paint those areas with the appropriate
> color, by interfacing with paint() event or somehow.
> Or can you provide a css example to instruct batik-rasterizer to color
> different areas within a PNG.

If you are running the rasteriser from the command line, then using CSS
would be easier.  Have your document like this:

  <svg …>

    <rect id='rectA' …/>
    <text>…</text>

    <rect id='rectB' …/>
    <text>…</text>

    <rect id='rectC' …/>
    <text>…</text>
  </svg>

and then use the -cssUser command line argument to give some CSS that
will style the rects.  Either write this out as a file, like:

  #rectA { fill: red; }
  #rectB { fill: green; }
  #rectC { fill: blue; }

call it styles.css, and do:

  java -jar batik-rasterizer.jar -cssUser style.css myfile.svg

or you could encode the whole stylesheet using the data: URI scheme and
give it in the command like, like:

  java -jar batik-rasterizer.jar -cssUser 
data:text/css,%23rectA%20%7B%20fill%3A%20red%3B%20%7D%0D%0A%23rectB%20%7B%20fill%3A%20green%3B%20%7D%0D%0A%23rectC%20%7B%20fill%3A%20blue%3B%20%7D%0D%0A
 myfile.svg

Not so pretty, but it should work.

(See en.wikipedia.org/wiki/Data:_URI_scheme and 
http://software.hixie.ch/utilities/cgi/data/data)

-- 
Cameron McCormack, http://mcc.id.au/
        xmpp:[EMAIL PROTECTED]  ▪  ICQ 26955922  ▪  MSN [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to