Hi gang, 

this is driving me nuts ;o( Once you have passed a SVG document to the
ImageTranscoder, modifying the 'visibility'-attributes has no impact
anymore on the transcoder output. It only has impact on the output when
you modify the attributes before passing the document object the first
time.

I know there are some points to remember when using JSVGCanvas [ see
http://koala.ilog.fr/batik/mlists/batik-users/archives/msg03051.html ],
however I can't seem to find the reason for this odd behaviour when
using the ImageTranscoder.

Here is a modified DOMRasterizer-Example taken from Batik's website to
illustrate the problem (see source comments for more information)

Any ideas or workarounds ?

ralf ...

-------------------------------------------------------------------------------------------
DOMRasterizer.java
-------------------------------------------------------------------------------------------

import java.io.FileOutputStream;
import java.io.OutputStream;

import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.JPEGTranscoder;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class DOMRasterizer {

        public Document createDocument() {
                DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
                String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
                Document document = impl.createDocument(svgNS, "svg", null);
                Element root = document.getDocumentElement();
                root.setAttributeNS(null, "width", "450");
                root.setAttributeNS(null, "height", "500");

                Element e;
                e = document.createElementNS(svgNS, "rect");
                e.setAttributeNS(null, "id", "rect");
                e.setAttributeNS(null, "x", "10");
                e.setAttributeNS(null, "y", "10");
                e.setAttributeNS(null, "width", "200");
                e.setAttributeNS(null, "height", "300");
                e.setAttributeNS(null, "style",
"fill:red;stroke:black;stroke-width:4");
                root.appendChild(e);

                e = document.createElementNS(svgNS, "circle");
                e.setAttributeNS(null, "id", "circle");
                e.setAttributeNS(null, "cx", "225");
                e.setAttributeNS(null, "cy", "250");
                e.setAttributeNS(null, "r", "100");
                e.setAttributeNS(null, "style", "fill:green;fill-opacity:.5");
                root.appendChild(e);

                return document;
        }

        public void save(Document document, String filename) throws Exception {
                JPEGTranscoder t = new JPEGTranscoder();
                t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8));
                TranscoderInput input = new TranscoderInput(document);
                OutputStream ostream = new FileOutputStream(filename);
                TranscoderOutput output = new TranscoderOutput(ostream);
                t.transcode(input, output);
                ostream.flush();
                ostream.close();
        }

        public static void main(String[] args) throws Exception {
                
                DOMRasterizer rasterizer = new DOMRasterizer();
                Document document = rasterizer.createDocument();
                
                /*
                 * FIRST RENDERING
                 */             
                document.getElementById("rect").setAttribute("visibility", "visible");
                document.getElementById("circle").setAttribute("visibility",
"hidden");
                
                /* 
                 * This JPEG contains the rectangular shape only, which is fine
                 */
                rasterizer.save(document, "rect.jpg"); 
                
                /*
                 * SECOND RENDERING
                 */
                
                /* 
                 * ===============================================================
                 * PROBLEM: Setting the visibility-attributes has no impact if the
                 * SVG document was passed to the transcoder a *second* time
                 * ===============================================================
                 */
                document.getElementById("rect").setAttribute("visibility", "hidden");
                document.getElementById("circle").setAttribute("visibility",
"visible");
                
                // This JPEG contains the rectangular shape only, but it should show
the circle
                rasterizer.save(document, "circle.jpg");
                
                System.out.println("Ready");
                
                System.exit(0);
        }
}

-------------------------------------------------------------------------------------------

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

Reply via email to