Search in sources :

Example 1 with TranscoderInput

use of org.apache.batik.transcoder.TranscoderInput 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)

Example 2 with TranscoderInput

use of org.apache.batik.transcoder.TranscoderInput in project Activiti by Activiti.

the class ModelSaveRestResource method saveModel.

@RequestMapping(value = "/model/{modelId}/save", method = RequestMethod.PUT)
@ResponseStatus(value = HttpStatus.OK)
public void saveModel(@PathVariable String modelId, @RequestBody MultiValueMap<String, String> values) {
    try {
        Model model = repositoryService.getModel(modelId);
        ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
        modelJson.put(MODEL_NAME, values.getFirst("name"));
        modelJson.put(MODEL_DESCRIPTION, values.getFirst("description"));
        model.setMetaInfo(modelJson.toString());
        model.setName(values.getFirst("name"));
        repositoryService.saveModel(model);
        repositoryService.addModelEditorSource(model.getId(), values.getFirst("json_xml").getBytes("utf-8"));
        InputStream svgStream = new ByteArrayInputStream(values.getFirst("svg_xml").getBytes("utf-8"));
        TranscoderInput input = new TranscoderInput(svgStream);
        PNGTranscoder transcoder = new PNGTranscoder();
        // Setup output
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        TranscoderOutput output = new TranscoderOutput(outStream);
        // Do the transformation
        transcoder.transcode(input, output);
        final byte[] result = outStream.toByteArray();
        repositoryService.addModelEditorSourceExtra(model.getId(), result);
        outStream.close();
    } catch (Exception e) {
        LOGGER.error("Error saving model", e);
        throw new ActivitiException("Error saving model", e);
    }
}
Also used : PNGTranscoder(org.apache.batik.transcoder.image.PNGTranscoder) ActivitiException(org.activiti.engine.ActivitiException) TranscoderOutput(org.apache.batik.transcoder.TranscoderOutput) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ByteArrayInputStream(java.io.ByteArrayInputStream) TranscoderInput(org.apache.batik.transcoder.TranscoderInput) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Model(org.activiti.engine.repository.Model) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ActivitiException(org.activiti.engine.ActivitiException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with TranscoderInput

use of org.apache.batik.transcoder.TranscoderInput in project dhis2-core by dhis2.

the class SvgConversionController method convertToPng.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void convertToPng(String svg, OutputStream out) throws TranscoderException {
    svg = replaceUnsafeSvgText(svg);
    PNGTranscoder transcoder = new PNGTranscoder();
    transcoder.addTranscodingHint(ImageTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE);
    TranscoderInput input = new TranscoderInput(new StringReader(svg));
    TranscoderOutput output = new TranscoderOutput(out);
    transcoder.transcode(input, output);
}
Also used : PNGTranscoder(org.apache.batik.transcoder.image.PNGTranscoder) TranscoderOutput(org.apache.batik.transcoder.TranscoderOutput) TranscoderInput(org.apache.batik.transcoder.TranscoderInput) StringReader(java.io.StringReader)

Example 4 with TranscoderInput

use of org.apache.batik.transcoder.TranscoderInput in project dhis2-core by dhis2.

the class SvgConversionController method convertToPdf.

private void convertToPdf(String svg, OutputStream out) throws TranscoderException {
    svg = replaceUnsafeSvgText(svg);
    PDFTranscoder transcoder = new PDFTranscoder();
    TranscoderInput input = new TranscoderInput(new StringReader(svg));
    TranscoderOutput output = new TranscoderOutput(out);
    transcoder.transcode(input, output);
}
Also used : TranscoderOutput(org.apache.batik.transcoder.TranscoderOutput) TranscoderInput(org.apache.batik.transcoder.TranscoderInput) StringReader(java.io.StringReader) PDFTranscoder(org.apache.fop.svg.PDFTranscoder)

Aggregations

TranscoderInput (org.apache.batik.transcoder.TranscoderInput)4 TranscoderOutput (org.apache.batik.transcoder.TranscoderOutput)4 StringReader (java.io.StringReader)2 PNGTranscoder (org.apache.batik.transcoder.image.PNGTranscoder)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 ActivitiException (org.activiti.engine.ActivitiException)1 Model (org.activiti.engine.repository.Model)1 SVGTranscoder (org.apache.batik.transcoder.svg2svg.SVGTranscoder)1 PDFTranscoder (org.apache.fop.svg.PDFTranscoder)1 PreviewController (org.gephi.preview.api.PreviewController)1 PreviewProperties (org.gephi.preview.api.PreviewProperties)1 LongTask (org.gephi.utils.longtask.spi.LongTask)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1