- Platform Windows XP
  - JDK 1.4.2
  - Batik 1.6

Hi

  I am attempting to render some data to an SVG file which is produced as a
Java3d
TriangleStripArray. I do this by parsing through the individual triangles
and appending them
to a GeneralPath as follows:

        path.moveTo(xTri1[0], yTri1[0]);
        path.lineTo(xTri1[1], yTri1[1]);
        path.lineTo(xTri1[2], yTri1[2]);

Then I close and fill the GeneralPath

The resulting SVG file looks great when viewed through the Adobe SVG plugin,
but when I view
it through squiggle, there are narrow gaps between all of the triangles.
When I use the
batik PNGTranscoder to convert the SVG file to a PNG, the narrow gaps become
a pixel wide and
the resulting image looks a mess.

If I fill the triangles individually rather than by appending them to a
general path, the
result is fine, but over tens of thousands of triangles there is a massive
loss in
performance and increase in file size. Can anyone suggest a way forward?

I have attached a segment of code which illustrates the problem:

import java.awt.Dimension;
import java.awt.Polygon;
import java.awt.geom.GeneralPath;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;

import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.svggen.SVGGraphics2DIOException;
import org.apache.batik.dom.GenericDOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Element;

public class SVGTest {
        public SVGTest()
                throws
                        SVGGraphics2DIOException,
                        IOException,
                        UnsupportedEncodingException
        {
                DOMImplementation domImpl =
                        GenericDOMImplementation.getDOMImplementation();
                Document document =
                        domImpl.createDocument(null, "svg", null);
                SVGGraphics2D graphics2d = new SVGGraphics2D(document);

                int width  = 200;
                int height = 200;
                Dimension size = new Dimension(width, height);
                graphics2d.setSVGCanvasSize(size);

                GeneralPath path =
                        new GeneralPath(GeneralPath.WIND_EVEN_ODD);

                // Define triangle coordinates
                int[] xTri1 = {120, 140, 130};
                int[] yTri1 = {120, 120, 140};
                int[] xTri2 = {120, 100, 130};
                int[] yTri2 = {120, 140, 140};

                // Draw triangle1
                path.moveTo(xTri1[0], yTri1[0]);
                path.lineTo(xTri1[1], yTri1[1]);
                path.lineTo(xTri1[2], yTri1[2]);

                // Draw triangle2
                path.moveTo(xTri2[0], yTri2[0]);
                path.lineTo(xTri2[1], yTri2[1]);
                path.lineTo(xTri2[2], yTri2[2]);

                // Close and fill path
                path.closePath();
                graphics2d.fill(path);

                Element svgRoot = ((SVGGraphics2D)graphics2d).getRoot();
                svgRoot.setAttributeNS(null, "viewBox",
                        "0, 0, " + String.valueOf(width) + ", " +
                        String.valueOf(height));
                BufferedOutputStream outStream =
                        new BufferedOutputStream(
                                new FileOutputStream("c:/test.svg"));
                Writer outWriter =
                        new OutputStreamWriter(outStream, "UTF-8");

                graphics2d.stream(svgRoot, outWriter, true);

                outWriter.flush();
                outWriter.close();
        }

        public static void main(String[] args) {
                try {
                        SVGTest test = new SVGTest();
                } catch (IOException e) {
                        System.err.println("Doh! " + e);
                }

        }
}


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

Reply via email to