Search in sources :

Example 6 with SVGGeneratorContext

use of org.apache.batik.svggen.SVGGeneratorContext 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

SVGGeneratorContext (org.apache.batik.svggen.SVGGeneratorContext)6 SVGGraphics2D (org.apache.batik.svggen.SVGGraphics2D)4 Document (org.w3c.dom.Document)4 Dimension (java.awt.Dimension)2 Font (java.awt.Font)2 GenericDOMImplementation (org.apache.batik.dom.GenericDOMImplementation)2 DOMImplementation (org.w3c.dom.DOMImplementation)2 IExportDialogAdapter (com.archimatetool.editor.diagram.IImageExportProvider.IExportDialogAdapter)1 GraphicsToGraphics2DAdaptor (com.archimatetool.export.svg.graphiti.GraphicsToGraphics2DAdaptor)1 Rectangle (java.awt.Rectangle)1 RenderingHints (java.awt.RenderingHints)1 Key (java.awt.RenderingHints.Key)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 OutputException (net.parostroj.timetable.output2.OutputException)1 GraphicContextDefaults (org.apache.batik.svggen.SVGGeneratorContext.GraphicContextDefaults)1 Test (org.junit.Test)1 Element (org.w3c.dom.Element)1