Is this a bug in Batik's SVG generator?

I'm drawing an arc. If the arc is < 360 degrees, things work normally.
If the arc is 360 degrees, nothing is displayed.

The attached program demonstrates the problem. Change the definition
of "DEGREES" to see the behavior change.

Note: this is using Batik 1.6 plus the patch that fixed the previous
arc bug (where the arc was drawn on the wrong side of the curve).

Thanks,
-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com
import java.awt.*;
import java.awt.color.*;
import java.awt.geom.*;
import java.io.*;

import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.util.SVGConstants;
import org.apache.batik.util.XMLConstants;

import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;

public class BatikBug implements SVGConstants {

    // If = 360.0: nothing is displayed
    // If < 360.0: displays normally
    public static final double DEGREES = 360.0;

    public static final int WIDTH = 200;
    public static final int HEIGHT = 200;

    public static final String SVG_PUBLIC_ID
        = "-//W3C//DTD SVG 1.1//EN";
    public static final String SVG_DTD
        = "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd";;
    public static final String SVG_MEDIA_TYPE = "image/svg+xml";

    public DOMImplementation getDOMImplementation() {
        return new SVGDOMImplementation();
    }

    public Document createDocument() {
        DOMImplementation di = getDOMImplementation();
        //DocumentType dt = di.createDocumentType("svg", SVG_PUBLIC_ID, 
SVG_DTD);
        DocumentType dt = null;
        Document doc = di.createDocument(SVG_NAMESPACE_URI, "svg", null);
    /*
        doc.getDocumentElement().setAttribute(XMLNS_PREFIX, SVG_NAMESPACE_URI);
        doc.getDocumentElement().setAttribute(XMLNS_PREFIX + ":" + XLINK_PREFIX,
          XLINK_NAMESPACE_URI);
    */
        return doc;
    }

    public Transformer getTransformer() {
        Transformer transformer;
        try {
            transformer = TransformerFactory.newInstance().newTransformer();
        } catch (TransformerConfigurationException e) {
            throw new RuntimeException("can't create XML transformer", e);
        }
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, SVG_MEDIA_TYPE);
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        return transformer;
    }

    public void output(OutputStream out) {

        // Create document
        Document doc = createDocument();
        Element topSVG = doc.getDocumentElement();
        topSVG.setAttribute("viewBox", "0 0 " + WIDTH + " " + HEIGHT);
        topSVG.setAttribute("overflow", "visible");

        // Add inner <svg> node
        draw(topSVG);

        // Output document
        try {
            getTransformer().transform(new DOMSource(doc),
              new StreamResult(new BufferedOutputStream(out)));
        } catch (TransformerException e) {
            throw new RuntimeException("XML output failed", e);
        }
    }

    public void draw(Element parent) {

            // Create an embedded <svg> node
            Element svg = addElement(parent, "svg");
            svg.setAttribute("viewBox", "0 0 " + WIDTH + " " + HEIGHT);
            svg.setAttribute("overflow", "visible");

            // Create a Graphics2D -> SVG transcoder
            SVGGraphics2D g2 = new SVGGraphics2D(parent.getOwnerDocument());

            // Render image, converting it to SVG
            draw(g2, new Rectangle(WIDTH, HEIGHT));
            g2.getRoot(svg);

            // Discard converter
            g2.dispose();
    }

    public void draw(Graphics2D g2, Rectangle bounds) {
        Arc2D.Double arc = new Arc2D.Double(
          bounds, 0.0, DEGREES, Arc2D.PIE);
        g2.setPaint(Color.GREEN);
        g2.fill(arc);
    }

    protected Element addElement(Element parent, String name) {
        Element elem = parent.getOwnerDocument()
          .createElementNS(SVG_NAMESPACE_URI, name);
        parent.appendChild(elem);
        return elem;
    }

    public static void main(String[] args) throws Exception {
        System.setProperty("java.awt.headless", "true");
        BatikBug bb = new BatikBug();
        bb.output(new FileOutputStream("bb.svg"));
    }
}



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

Reply via email to