xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Randall Parker" <randa...@nls.net>
Subject Re: What happens to the Document that SVGGenerator uses?
Date Fri, 17 Aug 2001 15:08:20 GMT
Dinkar,

I see that you are using JDOM as your outputter. I haven't tried that but would like to know
how to do that. 

However, I have been using SVGGraphics2D stream() method with some success. Try:

   boolean UseCSS = true;
   svgGenerator(StreamOut,UseCSS);

Here is the stream method from SVGGraphics2D (and this demonstrates yet again how great it
is to have open source 
btw). See that they do more to prepare the document before they stream it out. Try adding
some stuff from the try clause 
here before you stream it out with JDOM:.


    public void stream(Element svgRoot, Writer writer, boolean useCss)
        throws SVGGraphics2DIOException {
        try {
            PrintWriter out = new PrintWriter(writer);
            DocumentFragment svgDocument =
                svgRoot.getOwnerDocument().createDocumentFragment();
            svgDocument.appendChild(svgRoot);

            /*if(useCss){
              Node svgCssDocument = svgDocument;
              SVGCSSStyler.style(svgCssDocument);
              XmlWriter.writeXml(svgCssDocument, writer);
              writer.flush();
              }
              else{
              XmlWriter.writeXml(svgDocument, writer);
              writer.flush();
              }*/
            if (useCss)
                SVGCSSStyler.style(svgDocument);

            XmlWriter.writeXml(svgDocument, writer);
            writer.flush();
        } catch (SVGGraphics2DIOException e) {
            // this catch prevents from catching an SVGGraphics2DIOException
            // and wrapping it again in another SVGGraphics2DIOException
            // as would do the second catch (XmlWriter throws SVGGraphics2DIO
            // Exception but flush throws IOException)
            generatorCtx.errorHandler.
                handleError(e);
        } catch (IOException io) {
            generatorCtx.errorHandler.
                handleError(new SVGGraphics2DIOException(io));
        }
    }


On Thu, 16 Aug 2001 17:47:33 -0400, Dinkar Ganti wrote:

>public class SVGTest {
>
>    public void paint(Graphics2D g2d) {
>        g2d.setPaint(Color.red);
>        g2d.fill(new Rectangle(10, 10, 100, 100));
>    }
>
>    public static void main(String [] args) throws IOException {
>
>        // Get a DOMImplementation
>        DOMImplementation domImpl =
>            GenericDOMImplementation.getDOMImplementation();
>
>        // Create an instance of org.w3c.dom.Document
>        org.w3c.dom.Document document = domImpl.createDocument(null, "svg",
>null);
>
>        // Create an instance of the SVG Generator
>        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
>
>        // Ask the test to render into the SVG Graphics2D implementation
>        SVGTest test = new SVGTest();
>        test.paint(svgGenerator);
>
>        // Finally, stream out SVG to the standard output using UTF-8
>        // character to byte encoding
>	//        boolean useCSS = true; // we want to use CSS style attribute
>        //Writer out = new OutputStreamWriter(System.out, "UTF-8");
>        //svgGenerator.stream(out, useCSS);
>	DOMBuilder builder = new DOMBuilder();
>	XMLOutputter outputter = new XMLOutputter();
>
>	org.jdom.Document jdomDocument = builder.build(document);
>	outputter.output(jdomDocument, System.out);
>    }
>}




---------------------------------------------------------------------
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