Search in sources :

Example 11 with SVGGraphics2D

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

Example 12 with SVGGraphics2D

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);
    }
}
Also used : HashMap(java.util.HashMap) DOMImplementation(org.w3c.dom.DOMImplementation) GenericDOMImplementation(org.apache.batik.dom.GenericDOMImplementation) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Dimension(java.awt.Dimension) IOException(java.io.IOException) Document(org.w3c.dom.Document) SVGGeneratorContext(org.apache.batik.svggen.SVGGeneratorContext) Font(java.awt.Font) RenderingHints(java.awt.RenderingHints) OutputException(net.parostroj.timetable.output2.OutputException) OutputStreamWriter(java.io.OutputStreamWriter) Key(java.awt.RenderingHints.Key) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 13 with SVGGraphics2D

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);
}
Also used : GenericDOMImplementation(org.apache.batik.dom.GenericDOMImplementation) DOMImplementation(org.w3c.dom.DOMImplementation) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) LineString(org.locationtech.jts.geom.LineString) Document(org.w3c.dom.Document)

Example 14 with SVGGraphics2D

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();
}
Also used : GraphicsToGraphics2DAdaptor(com.archimatetool.export.svg.graphiti.GraphicsToGraphics2DAdaptor) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Document(org.w3c.dom.Document) SVGGeneratorContext(org.apache.batik.svggen.SVGGeneratorContext)

Example 15 with SVGGraphics2D

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);
    }
}
Also used : SVGRectElement(org.w3c.dom.svg.SVGRectElement) Element(org.w3c.dom.Element) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) SVGGeneratorContext(org.apache.batik.svggen.SVGGeneratorContext)

Aggregations

SVGGraphics2D (org.apache.batik.svggen.SVGGraphics2D)21 Document (org.w3c.dom.Document)14 DOMImplementation (org.w3c.dom.DOMImplementation)12 OutputStreamWriter (java.io.OutputStreamWriter)8 GenericDOMImplementation (org.apache.batik.dom.GenericDOMImplementation)8 Dimension (java.awt.Dimension)7 FileOutputStream (java.io.FileOutputStream)7 Writer (java.io.Writer)6 IOException (java.io.IOException)5 File (java.io.File)4 SVGGeneratorContext (org.apache.batik.svggen.SVGGeneratorContext)4 Rectangle (java.awt.Rectangle)3 Rectangle2D (java.awt.geom.Rectangle2D)3 FileNotFoundException (java.io.FileNotFoundException)3 SVGDOMImplementation (org.apache.batik.anim.dom.SVGDOMImplementation)3 Element (org.w3c.dom.Element)3 PdfWriter (com.itextpdf.text.pdf.PdfWriter)2 Font (java.awt.Font)2 BufferedOutputStream (java.io.BufferedOutputStream)2 PrintWriter (java.io.PrintWriter)2