Hello, I have serious performance problems when writing out the SVG DOM tree by the Batik SVG-Generator method org.apache.batik.svggen.SVGGraphics2D.stream(...).
Writing out ~ 20.000 lines to a SVG file by method SVGGraphics2D.stream(...) with BufferedWriter takes ~3 minutes -- that's unbelievable slow. The resulting size of the SVG file is ~1.3 MB. Does anybody can tell me how to accelerate file writing, or is it just a normal, poor behaviour of Batik's internal SVGGraphics2D.XmlWriter ? And any idea how to give a "I am working..." feedback to users while streaming out the DOM tree contents to an SVG file, e.g. by showing a progressbar ? The DOM tree contents are just lines and the resulting SVG file looks like this: -------------------------------------------------------------------------- <?xml version="1.0"?> <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'> <svg fill-opacity="1" xmlns:xlink="http://www.w3.org/1999/xlink" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke- linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" xmlns="http://www.w3.org/2000/svg" font-family="'sansserif'" font-style="normal" stroke-linejoin="miter" font-size="12" stroke-dashoffset="0" image-rendering="auto"> <!--Generated by Foo--> <defs id="genericDefs" /> <g> <g fill="white" stroke="white"> <rect width="562" x="0" height="378" y="0" stroke="none" /> </g> <g stroke-linecap="round" fill="rgb(204,255,204)" text-rendering="optimizeLegibility" stroke-linejoin="round" stroke="rgb(204,255,204)" stroke- width="0.375"> <line y2="217" fill="none" x1="222" x2="222" y1="217" /> ... <line fill="none" x1="60" x2="61" y1="153" y2="153" stroke="blue" stroke-width="0.5" /> ... <line fill="none" x1="477" x2="477" y1="258" y2="258" stroke="black" stroke-width="2" /> ... </g> </g> </svg> -------------------------------------------------------------------------- The lines were generated for a JPanel by explicetely calling its paintComponent(Graphics g) method with an instance of SVGGraphics2D as the parameter 'g' (please see code snippets below): -------------------------------------------------------------------------- ... File svgFile; ... DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); Document myFactory = domImpl.createDocument(/*null*/SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", null); SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(myFactory); ctx.setComment("Generated by Foo"); SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false); ... MyJPanel panel = new MyJPanel(); .... panel.paintComponent(svgGenerator); .... FileOutputStream fileout = new FileOutputStream(svgFile); Writer out = new BufferedWriter(new OutputStreamWriter(fileout, "UTF-8"), 131072/*buffersize=128kB*/); boolean useCSS = false; // CSS style attribute svgGenerator.stream(out, useCSS); ... -------------------------------------------------------------------------- class MyJPanel extends JPanel { ... BasicStroke strokeLine = new BasicStroke(thicknessLine, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); ... public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; int maxX = this.getSize().width; int maxY = this.getSize().height; // set white background g2.setColor(Color.white); g2.fillRect(0, 0, maxX, maxY); ... // loop over ~ 20.000 lines with different colors and strokes ... g2.setColor(colorLine); g2.setStroke(strokeLine); g2.draw(new Line2D.Double(line[i].startX, line[i].startY, line[i].endX, line[i].endY)); ... } } -------------------------------------------------------------------------- Thanks in advance for any help or tips !!! Maik Diergardt extreme.soft --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
