/**
* 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.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.apache.xmlgraphics.java2d.GraphicContext;
import org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D;
import org.jplot2d.element.impl.ComponentEx;
/**
* Export plot image to a EPS stream or file.
*
* @author Jingjing Li
*
*/
public class EpsExporter extends Renderer {
private final OutputStream os;
public EpsExporter(String pathname) throws FileNotFoundException {
this(new File(pathname));
}
public EpsExporter(File file) throws FileNotFoundException {
this(new FileOutputStream(file));
}
public EpsExporter(OutputStream out) {
super();
os = new BufferedOutputStream(out);
}
@Override
public void render(ComponentEx comp, List cacheBlockList) {
Dimension size = getDeviceBounds(comp).getSize();
EPSDocumentGraphics2D g = new EPSDocumentGraphics2D(false);
g.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
try {
g.setupDocument(os, size.width, size.height);
} catch (IOException e) {
throw new RuntimeException("Error exporting EPS", e);
}
//Paint a bounding box
//g.drawRect(0, 0, size.width, size.height);
for (CacheableBlock cb : cacheBlockList) {
List sublist = cb.getSubcomps();
for (ComponentEx subcomp : sublist) {
subcomp.draw(g);
}
}
try {
g.finish();
} catch (IOException e) {
throw new RuntimeException("Error exporting EPS", e);
}
}
}
Ads help maintain this website.