Search in sources :

Example 6 with SAXSVGDocumentFactory

use of org.apache.batik.anim.dom.SAXSVGDocumentFactory in project yamcs-studio by yamcs.

the class SVGSymbolImage method loadDocument.

private void loadDocument(InputStream inputStream) {
    svgHandler = null;
    failedToLoadDocument = true;
    if (imagePath == null || imagePath.isEmpty()) {
        return;
    }
    var parser = XMLResourceDescriptor.getXMLParserClassName();
    var factory = new SAXSVGDocumentFactory(parser);
    try {
        var workSpacePath = ResourceUtil.workspacePathToSysPath(new Path("/"));
        var uri = "file://" + (workSpacePath == null ? "" : workSpacePath.toOSString()) + imagePath.toString();
        svgDocument = factory.createDocument(uri, inputStream);
        svgHandler = new SVGHandler((SVGDocument) svgDocument, Display.getCurrent());
        svgHandler.setAlignedToNearestSecond(alignedToNearestSecond);
        initRenderingHints();
        var awtImage = svgHandler.getOffScreen();
        if (awtImage != null) {
            originalImageData = SVGUtils.toSWT(Display.getCurrent(), awtImage);
            resetData();
        }
        svgHandler.setRenderListener(image -> {
            if (disposed) {
                return;
            }
            animatedImage = image;
            repaintAnimated = true;
            repaint();
        });
        needRender = true;
        failedToLoadDocument = false;
    } catch (Exception e) {
        log.log(Level.WARNING, "Error loading SVG image " + imagePath, e);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) SVGHandler(org.csstudio.utility.batik.SVGHandler) SAXSVGDocumentFactory(org.apache.batik.anim.dom.SAXSVGDocumentFactory) SVGDocument(org.w3c.dom.svg.SVGDocument) IOException(java.io.IOException)

Aggregations

SAXSVGDocumentFactory (org.apache.batik.anim.dom.SAXSVGDocumentFactory)6 Document (org.w3c.dom.Document)3 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 SVGOMDocument (org.apache.batik.anim.dom.SVGOMDocument)1 GraphicsNode (org.apache.batik.gvt.GraphicsNode)1 SVGHandler (org.csstudio.utility.batik.SVGHandler)1 Path (org.eclipse.core.runtime.Path)1 SVGDocument (org.w3c.dom.svg.SVGDocument)1