You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by jg...@apache.org on 2026/03/10 15:19:17 UTC
(xmlgraphics-fop) branch main updated: FOP-2872 Fix NPE when using em units on SVG
This is an automated email from the ASF dual-hosted git repository.
jgoncalves pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/xmlgraphics-fop.git
The following commit(s) were added to refs/heads/main by this push:
new 89a2564fe FOP-2872 Fix NPE when using em units on SVG
89a2564fe is described below
commit 89a2564fecbc1a4877d84787125becb5bbc1a90d
Author: Joao Goncalves <an...@gmail.com>
AuthorDate: Thu Mar 5 16:23:37 2026 -0600
FOP-2872 Fix NPE when using em units on SVG
---
.../fop/image/loader/batik/PreloaderSVG.java | 11 +++++
fop/test/intermediate/svg_em_unit.xml | 49 ++++++++++++++++++++++
2 files changed, 60 insertions(+)
diff --git a/fop-core/src/main/java/org/apache/fop/image/loader/batik/PreloaderSVG.java b/fop-core/src/main/java/org/apache/fop/image/loader/batik/PreloaderSVG.java
index 4d8f6d123..81b7588b3 100644
--- a/fop-core/src/main/java/org/apache/fop/image/loader/batik/PreloaderSVG.java
+++ b/fop-core/src/main/java/org/apache/fop/image/loader/batik/PreloaderSVG.java
@@ -34,11 +34,13 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.batik.anim.dom.SAXSVGDocumentFactory;
+import org.apache.batik.anim.dom.SVGDOMImplementation;
import org.apache.batik.anim.dom.SVGOMDocument;
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.DefaultFontFamilyResolver;
import org.apache.batik.bridge.UnitProcessor;
import org.apache.batik.bridge.UserAgent;
+import org.apache.batik.css.engine.CSSEngine;
import org.apache.xmlgraphics.image.loader.ImageContext;
import org.apache.xmlgraphics.image.loader.ImageInfo;
@@ -172,6 +174,15 @@ public class PreloaderSVG extends AbstractImagePreloader {
};
BridgeContext ctx = new BridgeContext(userAg);
+ if (doc instanceof SVGOMDocument) {
+ SVGOMDocument document = (SVGOMDocument) doc;
+ CSSEngine eng = document.getCSSEngine();
+ if (eng == null) {
+ SVGDOMImplementation impl = (SVGDOMImplementation) document.getImplementation();
+ impl.createCSSEngine(document, ctx);
+ }
+ }
+
UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e);
String s;
diff --git a/fop/test/intermediate/svg_em_unit.xml b/fop/test/intermediate/svg_em_unit.xml
new file mode 100644
index 000000000..62c5a1c65
--- /dev/null
+++ b/fop/test/intermediate/svg_em_unit.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" standalone="no"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<testcase>
+ <info>
+ <p>
+ This test checks that IDs coming from images properly appear in the IF output.
+ </p>
+ </info>
+ <fo>
+ <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
+ <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>
+ </fo>
+ <if-checks xmlns:if="http://xmlgraphics.apache.org/fop/intermediate">
+ <eval expected="5em" xpath="//if:page-sequence/descendant::*[local-name() = 'svg'][1]/@height"/>
+ </if-checks>
+</testcase>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org