use of org.apache.batik.transcoder.TranscoderOutput 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;
}
use of org.apache.batik.transcoder.TranscoderOutput 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);
}
}
use of org.apache.batik.transcoder.TranscoderOutput 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);
}
use of org.apache.batik.transcoder.TranscoderOutput 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);
}
Aggregations