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;
}
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);
}
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);
}
});
}
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;
}
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);
}
Aggregations