/**
 * Copyright 2010-2013 Jingjing Li.
 *
 * This file is part of jplot2d.
 *
 * jplot2d is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or any later version.
 *
 * jplot2d is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with jplot2d. If not, see .
 */
package org.jplot2d.renderer;

import java.awt.*;
import java.io.*;
import java.util.Properties;
import javax.swing.*;
import java.awt.*;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import org.freehep.graphics2d.VectorGraphics;
import org.freehep.graphicsio.svg.*;

import org.jplot2d.element.impl.ComponentEx;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

/**
 * Export plot image to a VectorGraphics stream or file.
 * 
 * @author Jingjing Li
 * 
 */
public class VectorGraphicsExporter extends Renderer {

	private final OutputStream os;

	public VectorGraphicsExporter(String pathname) throws FileNotFoundException {
		this(new File(pathname));
	}

	public VectorGraphicsExporter(File file) throws FileNotFoundException {
		this(new FileOutputStream(file));
	}

	public VectorGraphicsExporter(OutputStream out) {
		super();
		os = new BufferedOutputStream(out);
	}

	@Override
	public void render(ComponentEx comp, List cacheBlockList) {


                Dimension size = getDeviceBounds(comp).getSize();
                Document document = new Document(new Rectangle(size.width, size.height), 0, 0, 0, 0);

                Properties properties = new Properties(); 
                properties.setProperty("PageSize","A5");
                JPanel jp = new JPanel(); 
                jp.setPreferredSize(size);  
                //VectorGraphics g = new SVGGraphics2D(os,(Component)jp); 

                //String outputfile="xxxx.svg";

/*
                SVGGraphics2D g=null;
                try {
                 g =
                  new SVGGraphics2D(new File(outputfile), size);

                 } catch (IOException a) {};


                //VectorGraphics g = new SVGGraphics2D(os,size);
                //g.create(0,0,size.width,size.height);  
                //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
                g.clipRect(0,0,size.width,size.height);
                g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

                //VectorGraphics g=getGraphics(os,(JComponent)jp,properties);
                //g.clipRect(0,0,size.width,size.height);
                // VectorGraphics g = new SVGGraphics2D(new File("Output.svg", new Dimension(400,300))); 


                int n=0;
                for (CacheableBlock cblock : cacheBlockList) {
                        List sublist = cblock.getSubcomps();
                        for (ComponentEx subcomp : sublist) {
                                subcomp.draw(g);
                                //if (n==0) break; 
                                //n++;
                        }
                }


                g.dispose();
*/

/*
                 try {
                Writer out=new OutputStreamWriter(os,"UTF-8");
                g.stream(out,true);
                os.flush();
                os.close();
                } catch (IOException a) {System.err.println("Error while exporting to SVGZ");};

*/
	}

}

 

Ads help maintain this website.