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