Search in sources :

Example 1 with SVGGraphics2DIOException

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);
    }
}
Also used : SimpleRootEditPart(org.eclipse.gef.editparts.SimpleRootEditPart) SVGGraphics2DIOException(org.apache.batik.svggen.SVGGraphics2DIOException) Rectangle(org.eclipse.draw2d.geometry.Rectangle) GraphicsSVG(org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.export.GraphicsSVG) OutputStreamWriter(java.io.OutputStreamWriter) LayerManager(org.eclipse.gef.editparts.LayerManager) IFigure(org.eclipse.draw2d.IFigure) BufferedWriter(java.io.BufferedWriter)

Example 2 with SVGGraphics2DIOException

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);
    }
}
Also used : SVGGraphics2DIOException(org.apache.batik.svggen.SVGGraphics2DIOException) ByteArrayInputStream(java.io.ByteArrayInputStream) ActivitiImageException(org.activiti.image.exception.ActivitiImageException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 3 with SVGGraphics2DIOException

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);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) SVGGraphics2DIOException(org.apache.batik.svggen.SVGGraphics2DIOException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) SVGGraphics2DIOException(org.apache.batik.svggen.SVGGraphics2DIOException) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter)

Aggregations

OutputStreamWriter (java.io.OutputStreamWriter)3 SVGGraphics2DIOException (org.apache.batik.svggen.SVGGraphics2DIOException)3 BufferedWriter (java.io.BufferedWriter)2 Writer (java.io.Writer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ActivitiImageException (org.activiti.image.exception.ActivitiImageException)1 SVGGraphics2D (org.apache.batik.svggen.SVGGraphics2D)1 IFigure (org.eclipse.draw2d.IFigure)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 LayerManager (org.eclipse.gef.editparts.LayerManager)1 SimpleRootEditPart (org.eclipse.gef.editparts.SimpleRootEditPart)1 GraphicsSVG (org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.export.GraphicsSVG)1