use of org.apache.batik.svggen.SVGGraphics2DIOException in project tdi-studio-se by Talend.
the class SVGImageExporter method export.
public static void export(GraphicalViewer viewer, OutputStream outputStream, List businessItems) {
/*
* 1. First get the figure whose visuals we want to save as image. So we would like to save the rooteditpart
* which actually hosts all the printable layers.
*
* NOTE: ScalableRootEditPart manages layers and is registered graphicalviewer's editpartregistry with the key
* LayerManager.ID ... well that is because ScalableRootEditPart manages all layers that are hosted on a
* FigureCanvas. Many layers exist for doing different things
*/
SimpleRootEditPart rootEditPart = (SimpleRootEditPart) viewer.getEditPartRegistry().get(LayerManager.ID);
// rootEditPart.
IFigure rootFigure = ((LayerManager) rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);
// getFigure();
Rectangle bounds = rootFigure.getBounds();
GraphicsSVG graphics = GraphicsSVG.getInstance(bounds.getTranslated(bounds.getLocation().negate()));
TalendSVGIDGenerator generator = new TalendSVGIDGenerator(businessItems);
graphics.getSVGGraphics2D().getGeneratorContext().setIDGenerator(generator);
graphics.translate(bounds.getLocation().negate());
rootFigure.paint(graphics);
try {
graphics.getSVGGraphics2D().stream(new BufferedWriter(new OutputStreamWriter(outputStream)));
} catch (SVGGraphics2DIOException e) {
ExceptionHandler.process(e);
}
}
use of org.apache.batik.svggen.SVGGraphics2DIOException in project Activiti by Activiti.
the class DefaultProcessDiagramCanvas method generateImage.
/**
* Generates an image of what currently is drawn on the canvas.
* <p>
* Throws an {@link ActivitiImageException} when {@link #close()} is already
* called.
*/
public InputStream generateImage() {
if (closed) {
throw new ActivitiImageException("ProcessDiagramGenerator already closed");
}
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Writer out;
out = new OutputStreamWriter(stream, "UTF-8");
g.stream(out, true);
return new ByteArrayInputStream(stream.toByteArray());
} catch (UnsupportedEncodingException | SVGGraphics2DIOException e) {
throw new ActivitiImageException("Error while generating process image", e);
}
}
use of org.apache.batik.svggen.SVGGraphics2DIOException 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);
}
}
Aggregations