use of org.apache.batik.svggen.SVGGraphics2D in project propane by ruby-processing.
the class PGraphicsSVG method endDraw.
@Override
public void endDraw() {
Writer writer;
// Also need to pop the matrix since the matrix doesn't reset on each run
// http://dev.processing.org/bugs/show_bug.cgi?id=1227
popMatrix();
// can be inserted, because SVG doesn't support multiple pages.
if (output == null) {
if (path == null) {
throw new RuntimeException("setOutput() or setPath() must be " + "used with the SVG renderer");
} else {
// insert the frame number and create intermediate directories
File save = parent.saveFile(parent.insertFrame(path));
try {
output = new FileOutputStream(save);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
}
// This needs to be overridden so that the endDraw() from PGraphicsJava2D
// is not inherited (it calls loadPixels).
// http://dev.processing.org/bugs/show_bug.cgi?id=1169
// Finally, stream out SVG to the standard output using UTF-8 encoding.
// we want to use CSS style attributes
boolean useCSS = true;
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)));
try {
((SVGGraphics2D) g2).stream(writer, useCSS);
} catch (SVGGraphics2DIOException e) {
}
try {
writer.flush();
writer.close();
} catch (IOException e) {
} finally {
output = null;
}
try {
writer.close();
} catch (IOException ex) {
Logger.getLogger(PGraphicsSVG.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of org.apache.batik.svggen.SVGGraphics2D in project pentaho-platform by pentaho.
the class JFreeChartEngine method saveChartAsSVG.
/**
* Create an SVG image file from a JFreeChart object
*
* @param chart
* The chart object to create an image from
* @param path
* The path and name of the image file to create
* @param width
* The width of the image in pixels
* @param height
* The height of the image in pixels
* @throws IOException
*/
private static void saveChartAsSVG(final JFreeChart chart, final String path, final int width, final int height, final ChartRenderingInfo info) throws IOException {
// THE FOLLOWING CODE BASED ON THE EXAMPLE IN THE BATIK DOCUMENTATION...
// Get a DOMImplementation
org.w3c.dom.DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
// $NON-NLS-1$
Document document = domImpl.createDocument(null, "svg", null);
// 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 = // $NON-NLS-1$
new OutputStreamWriter(new FileOutputStream(new File(path + ".svg")), LocaleHelper.getSystemEncoding());
svgGenerator.stream(out, useCSS);
}
use of org.apache.batik.svggen.SVGGraphics2D in project dkpro-lab by dkpro.
the class ChartUtil method writeChartAsSVG.
/**
* Exports a JFreeChart to a SVG file.
*
* @param chart JFreeChart to export
* @param aOS stream to write to.
* @param aWidth width of the chart in pixels
* @param aHeight height of the chart in pixels
* @throws IOException if writing the svgFile fails.
* @see <a href="http://dolf.trieschnigg.nl/jfreechart/">Saving JFreeChart as SVG vector images
* using Batik</a>
*/
public static void writeChartAsSVG(OutputStream aOS, JFreeChart chart, int aWidth, int aHeight) throws IOException {
// Get a DOMImplementation and create an XML document
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
Document document = domImpl.createDocument(null, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
// draw the chart in the SVG generator
chart.draw(svgGenerator, new Rectangle(aWidth, aHeight));
// Write svg file
Writer out = new OutputStreamWriter(aOS, "UTF-8");
svgGenerator.stream(out, true);
out.flush();
out.close();
}
use of org.apache.batik.svggen.SVGGraphics2D in project freeplane by freeplane.
the class ExportPdf method export.
public void export(MapModel map, File chosenFile) {
if (!ExportController.getContoller().checkCurrentMap(map)) {
return;
}
try {
final MapView view = (MapView) Controller.getCurrentController().getMapViewManager().getMapViewComponent();
if (view == null) {
return;
}
Controller.getCurrentController().getViewController().setWaitingCursor(true);
final SVGGraphics2D g2d = fillSVGGraphics2D(view);
final PDFTranscoder pdfTranscoder = new PDFTranscoder();
/*
* according to https: &aid=1921334&group_id=7118 Submitted By:
* Frank Spangenberg (f_spangenberg) Summary: Large mind maps
* produce invalid PDF
*/
pdfTranscoder.addTranscodingHint(SVGAbstractTranscoder.KEY_MAX_HEIGHT, new Float(19200));
pdfTranscoder.addTranscodingHint(SVGAbstractTranscoder.KEY_MAX_WIDTH, new Float(19200));
pdfTranscoder.addTranscodingHint(ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, 25.4f / 72f / UITools.FONT_SCALE_FACTOR);
/* end patch */
final Document doc = g2d.getDOMFactory();
final Element rootE = doc.getDocumentElement();
g2d.getRoot(rootE);
final TranscoderInput input = new TranscoderInput(doc);
final FileOutputStream ostream = new FileOutputStream(chosenFile);
final BufferedOutputStream bufStream = new BufferedOutputStream(ostream);
final TranscoderOutput output = new TranscoderOutput(bufStream);
pdfTranscoder.transcode(input, output);
ostream.flush();
ostream.close();
} catch (final Exception ex) {
org.freeplane.core.util.LogUtils.warn(ex);
UITools.errorMessage(ex.getLocalizedMessage());
} finally {
Controller.getCurrentController().getViewController().setWaitingCursor(false);
}
}
use of org.apache.batik.svggen.SVGGraphics2D in project freeplane by freeplane.
the class ExportVectorGraphic method fillSVGGraphics2D.
/**
*/
protected SVGGraphics2D fillSVGGraphics2D(final MapView view) {
// work around svg/pdf-Export problems when exporting with Gtk or Nimbus L&Fs
final String previousLnF = UIManager.getLookAndFeel().getClass().getName();
setLnF(view, UIManager.getCrossPlatformLookAndFeelClassName());
try {
final DOMImplementation impl = GenericDOMImplementation.getDOMImplementation();
final String namespaceURI = SVGConstants.SVG_NAMESPACE_URI;
final Document domFactory = impl.createDocument(namespaceURI, "svg", null);
final SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(domFactory);
ctx.setEmbeddedFontsOn(true);
final GraphicContextDefaults defaults = new GraphicContextDefaults();
defaults.setFont(new Font("Arial", Font.PLAIN, 12));
ctx.setGraphicContextDefaults(defaults);
ctx.setPrecision(12);
final SVGGraphics2D g2d = new SVGGraphics2D(ctx, false);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
view.preparePrinting();
final Rectangle innerBounds = view.getInnerBounds();
g2d.setSVGCanvasSize(new Dimension(innerBounds.width, innerBounds.height));
g2d.translate(-innerBounds.x, -innerBounds.y);
view.print(g2d);
view.endPrinting();
return g2d;
} finally {
setLnF(view, previousLnF);
}
}
Aggregations