Package org.apache.batik.svggen

Examples of org.apache.batik.svggen.SVGGraphics2D


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

        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
        if (chart != null) {
          chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, 600,
              400), null);
          try {
            Writer out = new OutputStreamWriter(
                new FileOutputStream(file), "UTF-8");
            svgGenerator.stream(out, true);
          } catch (UnsupportedEncodingException e1) {
            JOptionPane.showMessageDialog(this,
                "Unsupported Encoding", "Error",
                JOptionPane.ERROR_MESSAGE);
          } catch (FileNotFoundException e1) {
View Full Code Here


        SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(this.document);
        ctx.setComment("Generated by " + userAgent.getProducer() + " with Batik SVG Generator");
        ctx.setEmbeddedFontsOn(true);

        // Create an instance of the SVG Generator
        this.svgGenerator = new SVGGraphics2D(ctx, true);
        Rectangle2D viewArea = pageViewport.getViewArea();
        Dimension dim = new Dimension();
        dim.setSize(viewArea.getWidth() / 1000, viewArea.getHeight() / 1000);
        this.svgGenerator.setSVGCanvasSize(dim);
View Full Code Here

            = SVGDOMImplementation.getDOMImplementation();

        Document doc = domImpl.createDocument(SVG_NAMESPACE_URI,
                                              SVG_SVG_TAG, null);

        SVGGraphics2D svgGenerator = new SVGGraphics2D(doc);

        painter.paint(svgGenerator);

        //
        // Set the size and viewBox on the output document
        //
        int vpX = currentStore.getVpX();
        int vpY = currentStore.getVpY();
        int vpW = currentStore.getVpW();
        int vpH = currentStore.getVpH();
        svgGenerator.setSVGCanvasSize(new Dimension(vpW, vpH));

        Element svgRoot = svgGenerator.getRoot();
        svgRoot.setAttributeNS(null, SVG_VIEW_BOX_ATTRIBUTE,
                               "" + vpX + " " + vpY + " " +
                               vpW + " " + vpH );

        //
View Full Code Here

     */
    public TestReport runImpl() throws Exception {
        DefaultTestReport report
            = new DefaultTestReport(this);

        SVGGraphics2D g2d = buildSVGGraphics2D();
        g2d.setSVGCanvasSize(CANVAS_SIZE);

        //
        // Generate SVG content
        //
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        OutputStreamWriter osw = new OutputStreamWriter(bos, "UTF-8");
        try{
            painter.paint(g2d);
            g2d.stream(osw);
            osw.flush();
            bos.flush();
            bos.close();
        }catch(Exception e){
            StringWriter trace = new StringWriter();
View Full Code Here

    protected SVGGraphics2D buildSVGGraphics2D(){
        // CSSDocumentHandler.setParserClassName(CSS_PARSER_CLASS_NAME);
        DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
        String namespaceURI = SVGDOMImplementation.SVG_NAMESPACE_URI;
        Document domFactory = impl.createDocument(namespaceURI, SVG_SVG_TAG, null);
        return new SVGGraphics2D(domFactory);
    }
View Full Code Here

        SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(this.document);
        ctx.setComment("Generated by " + userAgent.getProducer() + " with Batik SVG Generator");
        ctx.setEmbeddedFontsOn(true);

        // Create an instance of the SVG Generator
        this.svgGenerator = new SVGGraphics2D(ctx, true);
        Rectangle2D viewArea = pageViewport.getViewArea();
        Dimension dim = new Dimension();
        dim.setSize(viewArea.getWidth() / 1000, viewArea.getHeight() / 1000);
        this.svgGenerator.setSVGCanvasSize(dim);
View Full Code Here

        DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
        String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
        Document svgdocument = impl.createDocument(svgNS, "svg", null);

        SVGGraphics2D g = new SVGGraphics2D(svgdocument);

        g.setSVGCanvasSize(
          new Dimension(base.getWidth(), base.getHeight()));

        //g.setColor(Color.white);
        //g.fillRect(0, 0, base.getWidth(), base.getHeight());
        g.setColor(Color.black);

        base.paint(g);

        //if (antialiasing)
        //element.setAttribute("text-rendering", "optimizeLegibility");
        //else
        //element.setAttribute("text-rendering", "geometricPrecision");

        // this should be done in a better way
        Element root = g.getRoot();
        svgdocument = impl.createDocument(svgNS, "svg", null);
        Node node = svgdocument.importNode(root, true);
        ((org.apache.batik.dom.svg.SVGOMDocument) svgdocument).
        getRootElement().appendChild(node);
View Full Code Here

    OutputStreamWriter writer = new OutputStreamWriter(baos, "UTF-8");
    DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
    Document document = domImpl.createDocument("cewolf-svg", "svg", null);
    SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
    ctx.setComment("Generated by Cewolf using JFreeChart and Apache Batik SVG Generator");
    SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
    svgGenerator.setSVGCanvasSize(new Dimension(width, height));
    chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, width, height), null);
    svgGenerator.stream(writer, false);
    writer.close();
  }
View Full Code Here

    // Get a DOMImplementation
    org.w3c.dom.DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
    // Create an instance of org.w3c.dom.Document
    Document document = domImpl.createDocument( null, "svg", null ); //$NON-NLS-1$
    // Create an instance of the SVG Generator
    SVGGraphics2D svgGenerator = new SVGGraphics2D( document );
    // set the precision to avoid a null pointer exception in Batik 1.5
    svgGenerator.getGeneratorContext().setPrecision( 6 );
    // Ask the chart to render into the SVG Graphics2D implementation
    chart.draw( svgGenerator, new Rectangle2D.Double( 0, 0, width, height ), info );
    // Finally, stream out SVG to a file using UTF-8 character to byte
    // encoding
    boolean useCSS = true;
    Writer out =
        new OutputStreamWriter( new FileOutputStream( new File( path + ".svg" ) ), LocaleHelper.getSystemEncoding() ); //$NON-NLS-1$
    svgGenerator.stream( out, useCSS );
  }
View Full Code Here

        SVGGeneratorContext genCtx = SVGGeneratorContext.createDefault(document);
        genCtx.setComment("Generated by Apache Batik's SVGGraphics2D");
        genCtx.setEmbeddedFontsOn(true);

        // Create an instance of the SVG Generator
        SVGGraphics2D g2d = new SVGGraphics2D(genCtx, true);
        ImageSize size = src.getSize();
        Dimension dim = size.getDimensionMpt();
        g2d.setSVGCanvasSize(dim);
        //SVGGraphics2D doesn't generate the viewBox by itself
        root.setAttribute("viewBox", "0 0 " + dim.width + " " + dim.height);

        g2dImage.getGraphics2DImagePainter().paint(g2d,
                new Rectangle2D.Float(0, 0, dim.width, dim.height));
        //Populate the document root with the generated SVG content.
        g2d.getRoot(root);

        //Return the generated SVG image
        ImageXMLDOM svgImage = new ImageXMLDOM(src.getInfo(), document, BatikImageFlavors.SVG_DOM);
        g2d.dispose();
        return svgImage;
    }
View Full Code Here

TOP

Related Classes of org.apache.batik.svggen.SVGGraphics2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.