xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bibek Sahu <scor...@dodds.net>
Subject Re: storing SVG DOM tree contents to a file by method org.apache.batik.svggen.SVGGraphics2D.stream(...) very slow !
Date Fri, 06 Feb 2004 19:53:49 GMT

Hrm... confusing.

Of course, the more I think about it, if there were high-performance code
in one of those methods, then it would probably also be in the other...
(and I think they both use the same underlying XmlWriter, so).  Silly
idea o' mine.  But that doesn't explain why the document contains no nodes
when you write it out with with DOMUtilities; the document should be the
same for both situation.

The only other suggestion I could make is to increase the size of your
write buffer.  I notice that it's "only" 128k.  If your files end up in
the 1.5MB range, you might see an improvement by kicking your buffer size
up to 1MB or so.  I notice that the code inside SVGGraphics2D.stream()
doesn't even use a BufferedWriter; I have no idea whether there's a reason
for that or not.

Good luck,
Bibek


On Fri, 6 Feb 2004, Magic Finger wrote:

> Thanks for your help Bibek, but unfortunately no elements were written out
> to SVG file when replacing in my code shown below the statement
>     svgGenerator.stream(out, useCSS);
> by your alternative suggestion
>     DOMUtilities.writeDocument(myFactory, out);
>
> It seems that 'myFactory' (which is an instance of org.w3c.dom.Document)
> contains no Node elements -- very strange !?
>
> Best regards,
> Maik
>
>
> ----- Original Message -----
> From: "Bibek Sahu" <scorpio@dodds.net>
> To: "Batik Users" <batik-users@xml.apache.org>
> Sent: Friday, February 06, 2004 4:23 PM
> Subject: Re: storing SVG DOM tree contents to a file by method
> org.apache.batik.svggen.SVGGraphics2D.stream(...) very slow !
>
>
> >
> > Another way is to use
> > org.apache.batik.dom.util.DOMUtilities.writeDocument(org.w3c.dom.Document
> doc, java.io.Writer w)
> >
> >
> > Don't know whether it's faster or not, but it's worth a shot.  It works
> > pretty well for me, but my SVGs are smaller than yours...
> >
> > Good luck!
> > - Bibek
> >
> >
> > On Fri, 6 Feb 2004, Magic Finger wrote:
> >
> > > 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="&apos;sansserif&apos;"
> > > 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: batik-users-unsubscribe@xml.apache.org
> > > For additional commands, e-mail: batik-users-help@xml.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> > For additional commands, e-mail: batik-users-help@xml.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Mime
View raw message