Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.3
-
None
-
None
-
Patch, Important
Description
This is the sample FO file, the SVG has its height specified in 'em' dimension:
<?xml version="1.0" encoding="UTF-8"?> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"> <fo:layout-master-set> <fo:simple-page-master master-name="sample"> <fo:region-body/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="sample"> <fo:flow flow-name="xsl-region-body"> <fo:block font-size="large" font-style="italic">Testing SVG images, there should be no NPE</fo:block> <fo:block> <fo:block> This is a SVG with its size in em: <fo:instream-foreign-object><svg class="hazardsymbol" height="5em" version="1.1" viewBox="0 0 600 600" xmlns="http://www.w3.org/2000/svg"><rect fill="red" height="600" rx="10" ry="10" stroke="black" stroke-width="5" width="600" x="0" y="0"/></svg></fo:instream-foreign-object> </fo:block> </fo:block> </fo:flow> </fo:page-sequence> </fo:root>
The exception is:
ava.lang.NullPointerException at org.apache.batik.bridge.UnitProcessor$DefaultContext.getFontSize(UnitProcessor.java:384) at org.apache.batik.parser.UnitProcessor.emsToPixels(UnitProcessor.java:286) at org.apache.batik.parser.UnitProcessor.svgToUserSpace(UnitProcessor.java:171) at org.apache.batik.parser.UnitProcessor.svgToUserSpace(UnitProcessor.java:140) at org.apache.batik.bridge.UnitProcessor.svgToUserSpace(UnitProcessor.java:310) at org.apache.batik.bridge.UnitProcessor.svgLengthToUserSpace(UnitProcessor.java:286) at org.apache.batik.bridge.UnitProcessor.svgVerticalLengthToUserSpace(UnitProcessor.java:217) at org.apache.fop.image.loader.batik.PreloaderSVG$Loader.createImageInfo(PreloaderSVG.java:191) at org.apache.fop.image.loader.batik.PreloaderSVG$Loader.getImage(PreloaderSVG.java:131) at org.apache.fop.image.loader.batik.PreloaderSVG$Loader.access$200(PreloaderSVG.java:108) at org.apache.fop.image.loader.batik.PreloaderSVG.preloadImage(PreloaderSVG.java:76) at org.apache.xmlgraphics.image.loader.ImageManager.preloadImage(ImageManager.java:176)
The cause is the document misses a CSSEngine, the SVG preloader does not provide one.
The solution is to have the preloader initialize the document using the bridge context:
Index: src/main/java/org/apache/batik/bridge/BridgeContext.java =================================================================== --- src/main/java/org/apache/batik/bridge/BridgeContext.java (revision 189449) +++ src/main/java/org/apache/batik/bridge/BridgeContext.java (working copy) @@ -372,7 +372,7 @@ /** * Initializes the given document. */ - protected void initializeDocument(Document document) { + public void initializeDocument(Document document) { SVGOMDocument doc = (SVGOMDocument)document; CSSEngine eng = doc.getCSSEngine(); if (eng == null) { Index: src/main/java/org/apache/fop/image/loader/batik/PreloaderSVG.java =================================================================== --- src/main/java/org/apache/fop/image/loader/batik/PreloaderSVG.java (revision 189449) +++ src/main/java/org/apache/fop/image/loader/batik/PreloaderSVG.java (working copy) @@ -172,6 +172,7 @@ }; BridgeContext ctx = new BridgeContext(userAg); + ctx.initializeDocument(doc); UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e); String s;