Search in sources :

Example 1 with SVGTranscoder

use of org.apache.batik.transcoder.svg2svg.SVGTranscoder in project gephi by gephi.

the class SVGExporter method execute.

@Override
public boolean execute() {
    PreviewController controller = Lookup.getDefault().lookup(PreviewController.class);
    controller.getModel(workspace).getProperties().putValue(PreviewProperty.VISIBILITY_RATIO, 1.0);
    controller.refreshPreview(workspace);
    PreviewProperties props = controller.getModel(workspace).getProperties();
    props.putValue(SVGTarget.SCALE_STROKES, scaleStrokes);
    props.putValue(PreviewProperty.MARGIN, new Float((float) margin));
    target = (SVGTarget) controller.getRenderTarget(RenderTarget.SVG_TARGET, workspace);
    if (target instanceof LongTask) {
        ((LongTask) target).setProgressTicket(progress);
    }
    try {
        controller.render(target, workspace);
        // creates SVG-to-SVG transcoder
        SVGTranscoder t = new SVGTranscoder();
        t.addTranscodingHint(SVGTranscoder.KEY_XML_DECLARATION, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        // sets transcoder input and output
        TranscoderInput input = new TranscoderInput(target.getDocument());
        // performs transcoding
        try {
            TranscoderOutput output = new TranscoderOutput(writer);
            t.transcode(input, output);
        } finally {
            writer.close();
            props.removeSimpleValue(PreviewProperty.MARGIN);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    Progress.finish(progress);
    return !cancel;
}
Also used : PreviewProperties(org.gephi.preview.api.PreviewProperties) TranscoderOutput(org.apache.batik.transcoder.TranscoderOutput) LongTask(org.gephi.utils.longtask.spi.LongTask) TranscoderInput(org.apache.batik.transcoder.TranscoderInput) PreviewController(org.gephi.preview.api.PreviewController) SVGTranscoder(org.apache.batik.transcoder.svg2svg.SVGTranscoder)

Aggregations

TranscoderInput (org.apache.batik.transcoder.TranscoderInput)1 TranscoderOutput (org.apache.batik.transcoder.TranscoderOutput)1 SVGTranscoder (org.apache.batik.transcoder.svg2svg.SVGTranscoder)1 PreviewController (org.gephi.preview.api.PreviewController)1 PreviewProperties (org.gephi.preview.api.PreviewProperties)1 LongTask (org.gephi.utils.longtask.spi.LongTask)1