Search in sources :

Example 1 with SAXSVGDocumentFactory

use of org.apache.batik.anim.dom.SAXSVGDocumentFactory in project pentaho-kettle by pentaho.

the class SvgSupport method getSvgFactory.

private static SAXSVGDocumentFactory getSvgFactory() {
    SAXSVGDocumentFactory factory = SVG_FACTORY_THREAD_LOCAL.get();
    if (factory == null) {
        factory = createFactory();
        SVG_FACTORY_THREAD_LOCAL.set(factory);
    }
    return factory;
}
Also used : SAXSVGDocumentFactory(org.apache.batik.anim.dom.SAXSVGDocumentFactory)

Example 2 with SAXSVGDocumentFactory

use of org.apache.batik.anim.dom.SAXSVGDocumentFactory in project quick-media by liuyueyi.

the class SvgDocumentHelper method getDocument.

private static Document getDocument(String path) throws URISyntaxException, IOException {
    Document cache = cacheDocMap.get(path);
    if (cache == null) {
        String parser = XMLResourceDescriptor.getXMLParserClassName();
        SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
        if (path.startsWith(SVG_CONTENT_TAG)) {
            // 表示直接传递的svg内容
            cache = f.createDocument(null, new ByteArrayInputStream(path.getBytes()));
        } else {
            // 传递的是文件形式
            cache = f.createDocument(UriUtil.getAbsUri(path));
        }
        // 缓存map数量添加限制,防止内存撑爆
        if (cacheDocMap.size() < CACHE_MAX_SIZE) {
            cacheDocMap.put(path, cache);
        }
    }
    return (Document) cache.cloneNode(true);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SAXSVGDocumentFactory(org.apache.batik.anim.dom.SAXSVGDocumentFactory) Document(org.w3c.dom.Document)

Example 3 with SAXSVGDocumentFactory

use of org.apache.batik.anim.dom.SAXSVGDocumentFactory in project pdfbox-graphics2d by rototor.

the class RenderSVGsTest method renderSVG.

private void renderSVG(String name, final double scale) throws IOException {
    String uri = RenderSVGsTest.class.getResource(name).toString();
    // create the document
    String parser = XMLResourceDescriptor.getXMLParserClassName();
    SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
    Document document = f.createDocument(uri, RenderSVGsTest.class.getResourceAsStream(name));
    // create the GVT
    UserAgent userAgent = new UserAgentAdapter();
    DocumentLoader loader = new DocumentLoader(userAgent);
    BridgeContext bctx = new BridgeContext(userAgent, loader);
    bctx.setDynamicState(BridgeContext.STATIC);
    GVTBuilder builder = new GVTBuilder();
    final GraphicsNode gvtRoot = builder.build(bctx, document);
    this.exportGraphic("svg", name.replace(".svg", ""), new GraphicsExporter() {

        @Override
        public void draw(Graphics2D gfx) {
            gfx.scale(scale, scale);
            gvtRoot.paint(gfx);
        }
    });
}
Also used : Document(org.w3c.dom.Document) SAXSVGDocumentFactory(org.apache.batik.anim.dom.SAXSVGDocumentFactory) GraphicsNode(org.apache.batik.gvt.GraphicsNode)

Example 4 with SAXSVGDocumentFactory

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

the class SVGUtils method loadSVG.

public static ImageData loadSVG(IPath fullPath, InputStream is, int width, int height) {
    if (fullPath == null || is == null)
        return null;
    SimpleImageTranscoder transcoder = null;
    String parser = XMLResourceDescriptor.getXMLParserClassName();
    SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
    try {
        Document svgDocument = factory.createDocument(fullPath.toOSString(), is);
        transcoder = new SimpleImageTranscoder(svgDocument);
        transcoder.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        transcoder.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
        transcoder.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        transcoder.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        transcoder.getRenderingHints().put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        transcoder.setCanvasSize(width, height);
        BufferedImage awtImage = transcoder.getBufferedImage();
        if (awtImage != null) {
            return toSWT(Display.getCurrent(), awtImage);
        }
    } catch (Exception e) {
        Activator.getLogger().log(Level.WARNING, "Error loading SVG file" + fullPath, e);
    }
    return null;
}
Also used : SAXSVGDocumentFactory(org.apache.batik.anim.dom.SAXSVGDocumentFactory) Document(org.w3c.dom.Document) BufferedImage(java.awt.image.BufferedImage)

Example 5 with SAXSVGDocumentFactory

use of org.apache.batik.anim.dom.SAXSVGDocumentFactory in project Activiti by Activiti.

the class ProcessDiagramGeneratorTest method parseXml.

private SVGOMDocument parseXml(InputStream resourceStream) throws Exception {
    String parser = XMLResourceDescriptor.getXMLParserClassName();
    SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
    return (SVGOMDocument) factory.createDocument(null, resourceStream);
}
Also used : SVGOMDocument(org.apache.batik.anim.dom.SVGOMDocument) SAXSVGDocumentFactory(org.apache.batik.anim.dom.SAXSVGDocumentFactory)

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