Search in sources :

Example 1 with SVGConverterException

use of org.apache.batik.apps.rasterizer.SVGConverterException in project opencast by opencast.

the class AbstractCoverImageService method rasterizeSvg.

protected static void rasterizeSvg(File svgSource, File pngResult) throws CoverImageException {
    SVGConverter converter = new SVGConverter();
    converter.setDestinationType(DestinationType.PNG);
    converter.setDst(pngResult);
    converter.setSources(new String[] { svgSource.getAbsolutePath() });
    try {
        log.debug("Start converting SVG to PNG");
        converter.execute();
    } catch (SVGConverterException e) {
        log.warn("Error while converting the SVG to a PNG: {}", e.getMessage());
        throw new CoverImageException("Error while converting the SVG to a PNG", e);
    }
}
Also used : CoverImageException(org.opencastproject.coverimage.CoverImageException) SVGConverterException(org.apache.batik.apps.rasterizer.SVGConverterException) SVGConverter(org.apache.batik.apps.rasterizer.SVGConverter)

Example 2 with SVGConverterException

use of org.apache.batik.apps.rasterizer.SVGConverterException in project xwiki-platform by xwiki.

the class ChartingPlugin method generateSvgChart.

private Chart generateSvgChart(JFreeChart jfchart, ChartParams params, XWikiContext context) throws IOException, GenerateException {
    // Get a DOMImplementation
    DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
    // Create an instance of org.w3c.dom.Document
    Document document = domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null);
    // Create an instance of the SVG Generator
    SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
    // Ask the chart to render into the SVG Graphics2D implementation
    Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, params.getInteger(ChartParams.WIDTH).intValue(), params.getInteger(ChartParams.HEIGHT).intValue());
    jfchart.draw(svgGenerator, rect);
    boolean useCSS = false;
    StringWriter swriter = new StringWriter();
    svgGenerator.stream(swriter, useCSS);
    String svgText = swriter.toString();
    String pageURL = null;
    SVGPlugin svgPlugin = (SVGPlugin) context.getWiki().getPlugin("svg", context);
    if (svgPlugin == null) {
        throw new GenerateException("SVGPlugin not loaded");
    }
    String imageURL;
    try {
        imageURL = svgPlugin.getSVGImageURL(svgText, params.getInteger(ChartParams.HEIGHT).intValue(), params.getInteger(ChartParams.WIDTH).intValue(), context);
    } catch (SVGConverterException sce) {
        throw new GenerateException(sce);
    }
    return new ChartImpl(params, imageURL, pageURL);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) DOMImplementation(org.w3c.dom.DOMImplementation) GenericDOMImplementation(org.apache.batik.dom.GenericDOMImplementation) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Document(org.w3c.dom.Document) SVGPlugin(com.xpn.xwiki.plugin.svg.SVGPlugin) GenerateException(com.xpn.xwiki.plugin.charts.exceptions.GenerateException) StringWriter(java.io.StringWriter) SVGConverterException(org.apache.batik.apps.rasterizer.SVGConverterException)

Aggregations

SVGConverterException (org.apache.batik.apps.rasterizer.SVGConverterException)2 GenerateException (com.xpn.xwiki.plugin.charts.exceptions.GenerateException)1 SVGPlugin (com.xpn.xwiki.plugin.svg.SVGPlugin)1 Rectangle2D (java.awt.geom.Rectangle2D)1 StringWriter (java.io.StringWriter)1 SVGConverter (org.apache.batik.apps.rasterizer.SVGConverter)1 GenericDOMImplementation (org.apache.batik.dom.GenericDOMImplementation)1 SVGGraphics2D (org.apache.batik.svggen.SVGGraphics2D)1 CoverImageException (org.opencastproject.coverimage.CoverImageException)1 DOMImplementation (org.w3c.dom.DOMImplementation)1 Document (org.w3c.dom.Document)1