use of org.apache.batik.dom.util.SAXDocumentFactory in project megameklab by MegaMek.
the class PrintMech method loadPipSVG.
@Nullable
private NodeList loadPipSVG(String filename) {
File f = new File(filename);
if (!f.exists()) {
return null;
}
Document doc;
try (InputStream is = new FileInputStream(f)) {
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
final String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXDocumentFactory df = new SAXDocumentFactory(impl, parser);
doc = df.createDocument(f.toURI().toASCIIString(), is);
} catch (Exception e) {
LogManager.getLogger().error("Failed to open pip SVG file! Path: " + f.getName());
return null;
}
if (doc == null) {
LogManager.getLogger().error("Failed to open pip SVG file! Path: " + f.getName());
return null;
} else {
return doc.getElementsByTagName(SVGConstants.SVG_PATH_TAG);
}
}
use of org.apache.batik.dom.util.SAXDocumentFactory in project megameklab by MegaMek.
the class PrintRecordSheet method loadSVG.
/**
* Creates a {@link Document} from an svg image file
*
* @param filename The name of the SVG file
* @return The document object
*/
@Nullable
static Document loadSVG(String dirName, String filename) {
File f = new File(dirName, filename);
Document svgDocument = null;
try (InputStream is = new FileInputStream(f)) {
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
final String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXDocumentFactory df = new SAXDocumentFactory(impl, parser);
svgDocument = df.createDocument(f.toURI().toASCIIString(), is);
} catch (Exception ex) {
LogManager.getLogger().error("", ex);
}
if (svgDocument == null) {
LogManager.getLogger().error("Failed to open SVG file! Path: data/images/recordsheets/" + filename);
}
return svgDocument;
}
use of org.apache.batik.dom.util.SAXDocumentFactory in project megameklab by MegaMek.
the class PrintRecordSheet method print.
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
final String METHOD_NAME = "print(Graphics,PageFormat,int)";
Graphics2D g2d = (Graphics2D) graphics;
if (null != g2d) {
File f = new File("data/images/recordsheets/" + getSVGFileName());
svgDocument = null;
try {
InputStream is = new FileInputStream(f);
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
final String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXDocumentFactory df = new SAXDocumentFactory(impl, parser);
svgDocument = df.createDocument(f.toURI().toASCIIString(), is);
} catch (Exception e) {
MegaMekLab.getLogger().log(PrintRecordSheet.class, METHOD_NAME, e);
}
if (null == svgDocument) {
MegaMekLab.getLogger().log(PrintRecordSheet.class, METHOD_NAME, LogLevel.ERROR, "Failed to open Mech SVG file! Path: data/images/recordsheets/" + getSVGFileName());
} else {
svgGenerator = new SVGGraphics2D(svgDocument);
printImage(g2d, pageFormat, pageIndex - firstPage);
GraphicsNode node = build();
node.paint(g2d);
}
}
return Printable.PAGE_EXISTS;
}
Aggregations