xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Magic Finger" <magic.fin...@gmx.de>
Subject Re: storing SVG DOM tree contents to a file by method org.apache.batik.svggen.SVGGraphics2D.stream(...) very slow !
Date Sat, 07 Feb 2004 10:55:48 GMT
oh, I forgot to mention that increasing the buffersize also does not help to
accelerate svg file writing, the problem is most probably the implementation
of node traversal inside SVGGraphics2D.stream(...) by using the class
org.apache.batik.svggenXmlWriter.

Best regards,
Maik

----- Original Message ----- 
From: "Magic Finger" <magic.finger@gmx.de>
To: "Batik Users" <batik-users@xml.apache.org>
Sent: Saturday, February 07, 2004 11:38 AM
Subject: Re: storing SVG DOM tree contents to a file by method
org.apache.batik.svggen.SVGGraphics2D.stream(...) very slow !


> I had a closer look into Batik's source code for methods
> SVGGraphics2D.stream and DOMUtilities.writeDocument and saw that they use
> different node traversal methods:
>
> DOMUtilities.writeDocument(...)  uses
>     Node n = doc.getFirstChild();
> and loops over
>     n = n.getNextSibling();
>
> whereas
>
> SVGGraphics2D.stream(...) uses
>     NodeList childList = docFragment.getChildNodes();
> and loops over
>     Node child = childList.item(i);
>
> Probably this is the reason for the different behaviour, so that in my
case
> only SVGGraphics2D.stream(...) works.
> But I have not debugged the code to gain further explanations...
>
> Best regards,
> Maik
> ----- Original Message ----- 
> From: "Bibek Sahu" <scorpio@dodds.net>
> To: "Batik Users" <batik-users@xml.apache.org>
> Sent: Friday, February 06, 2004 8:53 PM
> Subject: Re: storing SVG DOM tree contents to a file by method
> org.apache.batik.svggen.SVGGraphics2D.stream(...) very slow !
>
>
> >
> > 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
> >
>
>
> ---------------------------------------------------------------------
> 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