use of org.apache.batik.svggen.SVGGraphics2D 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);
}
use of org.apache.batik.svggen.SVGGraphics2D in project grafikon by jub77.
the class DrawOutput method processSvg.
private void processSvg(Collection<Image> images, OutputStream stream, DrawLayout layout) throws OutputException {
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
SVGGeneratorContext context = SVGGeneratorContext.createDefault(document);
context.setGraphicContextDefaults(new SVGGeneratorContext.GraphicContextDefaults());
// set default font
context.getGraphicContextDefaults().setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
// set antialiasing
Map<Key, Object> map = new HashMap<>();
map.put(RenderingHints.KEY_ANTIALIASING, Boolean.TRUE);
map.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
context.getGraphicContextDefaults().setRenderingHints(new RenderingHints(map));
SVGGraphics2D g2d = new SVGGraphics2D(context, false);
List<Dimension> sizes = this.getSizes(images, g2d);
Dimension size = this.getTotalSize(sizes, layout);
g2d.setSVGCanvasSize(size);
this.drawImages(sizes, images, g2d, layout);
// write to ouput - do not use css style
boolean useCSS = false;
try {
Writer out = new OutputStreamWriter(stream, "UTF-8");
g2d.stream(out, useCSS);
} catch (IOException e) {
throw new OutputException(e.getMessage(), e);
}
}
use of org.apache.batik.svggen.SVGGraphics2D in project hale by halestudio.
the class SVGPainter method createSVGGraphics.
private SVGGraphics2D createSVGGraphics() {
// Get a DOMImplementation.
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator.
return new SVGGraphics2D(document);
}
use of org.apache.batik.svggen.SVGGraphics2D in project archi by archimatetool.
the class AbstractExportProvider method initialiseGraphics.
protected void initialiseGraphics() {
// Ensure user fonts are loaded into AWT for Windows
loadUserFontsIntoAWT();
// Create a DOM Document
Document document = createDocument();
// Create a context for customisation
// Don't embed fonts
SVGGeneratorContext ctx = createContext(document, false);
// Create a Batik SVGGraphics2D instance
// Text is drawn as shapes
svgGraphics2D = new SVGGraphics2D(ctx, true);
// Create a Graphiti wrapper adapter
GraphicsToGraphics2DAdaptor graphicsAdaptor = createGraphicsToGraphics2DAdaptor(svgGraphics2D, viewPortBounds);
// Paint the figure onto the graphics instance
figure.paint(graphicsAdaptor);
// Dispose of this
graphicsAdaptor.dispose();
}
use of org.apache.batik.svggen.SVGGraphics2D in project megameklab by MegaMek.
the class PrintRecordSheet method createDocument.
void createDocument(int pageIndex, PageFormat pageFormat, boolean addMargin) {
svgDocument = loadTemplate(pageIndex, pageFormat);
if (null != svgDocument) {
subFonts((SVGDocument) svgDocument);
subColorElements();
SVGGeneratorContext context = SVGGeneratorContext.createDefault(svgDocument);
svgGenerator = new SVGGraphics2D(context, false);
double ratio = Math.min(pageFormat.getImageableWidth() / (options.getPaperSize().pxWidth - 36), pageFormat.getPaper().getImageableHeight() / (options.getPaperSize().pxHeight - 36));
if ((pageIndex == firstPage) && includeReferenceCharts()) {
ratio *= TABLE_RATIO;
}
Element svgRoot = svgDocument.getDocumentElement();
svgRoot.setAttributeNS(null, SVGConstants.SVG_WIDTH_ATTRIBUTE, String.valueOf(pageFormat.getWidth()));
svgRoot.setAttributeNS(null, SVGConstants.SVG_HEIGHT_ATTRIBUTE, String.valueOf(pageFormat.getHeight()));
Element g = svgDocument.getElementById(RS_TEMPLATE);
if (g != null) {
if (addMargin) {
g.setAttributeNS(null, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, String.format("%s(%f 0 0 %f %f %f)", SVGConstants.SVG_MATRIX_VALUE, ratio, ratio, pageFormat.getImageableX(), pageFormat.getImageableY()));
} else {
g.setAttributeNS(null, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, String.format("%s(%f %f)", SVGConstants.SVG_SCALE_ATTRIBUTE, ratio, ratio));
}
}
processImage(pageIndex - firstPage, pageFormat);
}
}
Aggregations