You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "simon steiner (JIRA)" <ji...@apache.org> on 2019/07/05 08:19:00 UTC

[jira] [Commented] (FOP-2872) [PATCH] NullPointerException when an SVG root element specifies the size in 'em' (and a fix for this)

    [ https://issues.apache.org/jira/browse/FOP-2872?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16879061#comment-16879061 ] 

simon steiner commented on FOP-2872:
------------------------------------

Can you submit as a patch file with a unit test

> [PATCH] NullPointerException when an SVG root element specifies the size in 'em' (and a fix for this)
> -----------------------------------------------------------------------------------------------------
>
>                 Key: FOP-2872
>                 URL: https://issues.apache.org/jira/browse/FOP-2872
>             Project: FOP
>          Issue Type: Bug
>          Components: foreign/svg
>    Affects Versions: 2.3
>            Reporter: Dan Caprioara
>            Priority: Major
>
> This is the sample FO file, the SVG has its height specified in 'em' dimension:
> {code:xml}
> <?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>
> {code}
> The exception is:
> {code:java}
> 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)
> 	
> {code}
> 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:
> {code:java}
> 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;
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)