Exceptions reading some SVG files and Batik
See original GitHub issueFirst of all, I’m really happy with this 3.4.1 release, thank you for a great job! All the problems that I’ve encountered had been solved, except with some SVG files.
Now, there is a very high chance that this is not a TwelveMonkey’s problem, I bet it is an issue within Batik (and I do know that Batik does not support everything) or I’m doing something wrong (like missing some jar files), but I felt it was worth mentioning.
The problem happens only with some SVG images, like the one at the wikipedia page “SVG exported from KOMPAS-Graphic”.
When I try to read this file, I get this:
2018-09-17 09:49:50 FINE: null
Enclosed Exception:
The current document is unable to create an element of the requested type (namespace: http://www.w3.org/2000/svg, name: drawing-type). [@meew.FileManager getCurrentImage]
javax.imageio.IIOException: null
Enclosed Exception:
The current document is unable to create an element of the requested type (namespace: http://www.w3.org/2000/svg, name: drawing-type).
at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader.getWidth(SVGImageReader.java:232)
at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader.read(SVGImageReader.java:131)
at javax.imageio.ImageReader.read(ImageReader.java:939)
at meew.FileManager.getCurrentImage(FileManager.java:2046)
...
Caused by: org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
The current document is unable to create an element of the requested type (namespace: http://www.w3.org/2000/svg, name: drawing-type).
at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:134)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader$Rasterizer.init(SVGImageReader.java:549)
at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader$Rasterizer.getDefaultWidth(SVGImageReader.java:562)
at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader.getWidth(SVGImageReader.java:229)
... 40 more
Caused by: org.w3c.dom.DOMException: The current document is unable to create an element of the requested type (namespace: http://www.w3.org/2000/svg, name: drawing-type).
at org.apache.batik.dom.AbstractNode.createDOMException(AbstractNode.java:407)
at org.apache.batik.anim.dom.SVGDOMImplementation.createElementNS(SVGDOMImplementation.java:202)
at org.apache.batik.anim.dom.SVGOMDocument.createElementNS(SVGOMDocument.java:373)
at org.apache.batik.dom.util.SAXDocumentFactory.startElement(SAXDocumentFactory.java:651)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(SAXDocumentFactory.java:453)
at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(SAXDocumentFactory.java:357)
at org.apache.batik.anim.dom.SAXSVGDocumentFactory.createDocument(SAXSVGDocumentFactory.java:225)
at org.apache.batik.anim.dom.SAXSVGDocumentFactory.createDocument(SAXSVGDocumentFactory.java:300)
at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:114)
... 44 more
I can’t find any info about this drawing-type tag. I edited the xml of the file to remove that tag to test it. The image is displayed exactly the same in Firefox, with or without the tag. When I try to load the image removing the <drawing-type>1</drawing-type>
, the exception changes to:
java.lang.NullPointerException
at org.apache.batik.css.engine.CSSEngine.parseStyleSheet(CSSEngine.java:1223)
at org.apache.batik.css.engine.CSSEngine.parseStyleSheet(CSSEngine.java:1204)
at org.apache.batik.anim.dom.SVGOMStyleElement.getCSSStyleSheet(SVGOMStyleElement.java:140)
at org.apache.batik.css.engine.CSSEngine.getStyleSheetNodes(CSSEngine.java:923)
at org.apache.batik.css.engine.CSSEngine.getCascadedStyleMap(CSSEngine.java:785)
at org.apache.batik.css.engine.CSSEngine.getComputedStyle(CSSEngine.java:867)
at org.apache.batik.bridge.CSSUtilities.getComputedStyle(CSSUtilities.java:81)
at org.apache.batik.bridge.CSSUtilities.convertVisibility(CSSUtilities.java:578)
at org.apache.batik.bridge.SVGSVGElementBridge.createGraphicsNode(SVGSVGElementBridge.java:141)
at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:76)
at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader$Rasterizer.transcode(SVGImageReader.java:309)
at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader$Rasterizer.init(SVGImageReader.java:549)
at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader$Rasterizer.getDefaultWidth(SVGImageReader.java:562)
at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader.getWidth(SVGImageReader.java:229)
at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader.read(SVGImageReader.java:131)
at javax.imageio.ImageReader.read(ImageReader.java:939)
at meew.FileManager.getCurrentImage(FileManager.java:2046)
...
Do you know anything about this? This also happened in the previous 3.3.2 version. I’m using Batik version 1.10 now but the problem happened in the 1.9 version as well. By the way, I saw in the TwelveMonkey’s release notes that “Batik dependencies updated to 1.9”, so is it safe if I use 1.10?
Issue Analytics
- State:
- Created 5 years ago
- Comments:23 (12 by maintainers)
Top GitHub Comments
Not yet, but I will!! I promise to come back with the results soon.
I can’t see anything in the spec about them having to be on a specific line… But you need to report that bug to the Batik guys, as I don’t control the parsing.
As I mentioned above, I think a better approach (than re-serializing to a byte array) would be to just pass the pre-parsed document to the reader. Did you try that out yet?
– Harald K