xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leonardo Kenji Shikida" <shik...@gmail.com>
Subject tiling a SVG from XML document
Date Fri, 21 Sep 2007 15:33:53 GMT
Hi

I am trying to generate tiled Jpegs from my SVG but it's generating blank images

My assumption is that

Document doc = domImpl.createDocument(svgNS, "svg", null);
SVGGraphics2D svg = new SVGGraphics2D(doc);

actually means that, when the app draws something in the graphical
context (svg), actually, nodes are being added to the SVG DOM
representation (doc)

but when I try to generate JPEGs from the DOM, all I've got are blank
tiles, while the SVG generation works well.

what am I doing wrong? (please check the code, I've left some comments there)

by the way, just another questions

- Is there a way to save my SVG as a PDF document?
- My SVG can become quite large, so I am afraid a in-memory DOM will
give me a OutOfMemory exception. Is there any workaroud? Like some
sort of file-based structure that can bypass the JVM 32-bit limitation
of addressing about up to (almost) 2 GB in the heap? What's the usual
approach for this?

my code looks like this

//create DOM

        DOMImplementation domImpl =
            GenericDOMImplementation.getDOMImplementation();
        String svgNS = "http://www.w3.org/2000/svg";
        Document doc = domImpl.createDocument(svgNS, "svg", null);

        SVGGraphics2D svg = new SVGGraphics2D(doc);

//paint something in the graphical context
       	paintComponent(svg);

        SaveAsJPEGTiles p = new SaveAsJPEGTiles();
        int dw2 = documentWidth / 2;
        int dh2 = documentHeight / 2;

//generate 4 JPEG tiles - these tiles are being generated with the
right size, but all blank. why?

        p.tile(doc, "/tmp/tileTopLeft.jpg", new Rectangle(0, 0, dw2, dh2));
        p.tile(doc, "/tmp/tileTopRight.jpg", new Rectangle(dw2, 0, dw2, dh2));
        p.tile(doc, "/tmp/tileBottomLeft.jpg", new Rectangle(0, dh2, dw2, dh2));
        p.tile(doc, "/tmp/tileBottomRight.jpg", new Rectangle(dw2,
dh2, dw2, dh2));

//then generate the SVG file, this image is being generated successfully

        boolean useCSS = true;
        FileOutputStream fos = new FileOutputStream(new File("/tmp/mySVG.svg"));
        Writer out = new OutputStreamWriter(fos, "UTF-8");
        svg.stream(out, useCSS);

//where tile() is
    private void tile(org.w3c.dom.Document doc,
                     String outputFilename,
                     Rectangle aoi) throws Exception {
        trans.addTranscodingHint(JPEGTranscoder.KEY_WIDTH,
                                 new Float(aoi.width));
        trans.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT,
                                 new Float(aoi.height));
        trans.addTranscodingHint(JPEGTranscoder.KEY_AOI, aoi);

        TranscoderInput input = new TranscoderInput(doc);
        OutputStream ostream = new FileOutputStream(outputFilename);
        TranscoderOutput output = new TranscoderOutput(ostream);
        trans.transcode(input, output);

        ostream.flush();
        ostream.close();
    }

thanks in advance

Kenji
_______________________
http://kenjiria.blogspot.com
http://gaitabh.blogspot.com

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


Mime
View raw message