aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java37
-rw-r--r--test/layoutengine/standard-testcases/external-graphic_invalid.xml55
2 files changed, 79 insertions, 13 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java
index 204c69e8f..01fd854d6 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java
@@ -22,7 +22,6 @@ import java.awt.geom.Rectangle2D;
import java.util.LinkedList;
import org.apache.fop.area.Area;
-import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.inline.Viewport;
import org.apache.fop.datatypes.Length;
import org.apache.fop.datatypes.LengthBase;
@@ -71,7 +70,6 @@ public abstract class AbstractGraphicsLayoutManager extends LeafNodeLayoutManage
int bpd = -1;
int ipd = -1;
- boolean bpdauto = false;
if (hasLH) {
bpd = fobj.getLineHeight().getOptimum(this).getLength().getValue(this);
} else {
@@ -130,20 +128,33 @@ public abstract class AbstractGraphicsLayoutManager extends LeafNodeLayoutManage
cwidth = fobj.getIntrinsicWidth();
cheight = fobj.getIntrinsicHeight();
} else if (cwidth == -1) {
- cwidth = (int)(fobj.getIntrinsicWidth() * (double)cheight
- / fobj.getIntrinsicHeight());
+ if (fobj.getIntrinsicHeight() == 0) {
+ cwidth = 0;
+ } else {
+ cwidth = (int)(fobj.getIntrinsicWidth() * (double)cheight
+ / fobj.getIntrinsicHeight());
+ }
} else if (cheight == -1) {
- cheight = (int)(fobj.getIntrinsicHeight() * (double)cwidth
- / fobj.getIntrinsicWidth());
+ if (fobj.getIntrinsicWidth() == 0) {
+ cheight = 0;
+ } else {
+ cheight = (int)(fobj.getIntrinsicHeight() * (double)cwidth
+ / fobj.getIntrinsicWidth());
+ }
} else {
// adjust the larger
- double rat1 = cwidth / fobj.getIntrinsicWidth();
- double rat2 = cheight / fobj.getIntrinsicHeight();
- if (rat1 < rat2) {
- // reduce cheight
- cheight = (int)(rat1 * fobj.getIntrinsicHeight());
- } else if (rat1 > rat2) {
- cwidth = (int)(rat2 * fobj.getIntrinsicWidth());
+ if (fobj.getIntrinsicWidth() == 0 || fobj.getIntrinsicHeight() == 0) {
+ cwidth = 0;
+ cheight = 0;
+ } else {
+ double rat1 = cwidth / fobj.getIntrinsicWidth();
+ double rat2 = cheight / fobj.getIntrinsicHeight();
+ if (rat1 < rat2) {
+ // reduce cheight
+ cheight = (int)(rat1 * fobj.getIntrinsicHeight());
+ } else if (rat1 > rat2) {
+ cwidth = (int)(rat2 * fobj.getIntrinsicWidth());
+ }
}
}
}
diff --git a/test/layoutengine/standard-testcases/external-graphic_invalid.xml b/test/layoutengine/standard-testcases/external-graphic_invalid.xml
new file mode 100644
index 000000000..1cd0e239e
--- /dev/null
+++ b/test/layoutengine/standard-testcases/external-graphic_invalid.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2005 The Apache Software Foundation
+
+ Licensed 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.
+-->
+<!-- $Id$ -->
+<testcase>
+ <info>
+ <p>
+ This test checks external-graphics with an invalid URI to the image. Particular situations
+ with combination of content-width and content-height produced "/ by zero" ArithmeticExceptions.
+ </p>
+ </info>
+ <fo>
+ <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="normal" page-width="5in" page-height="5in">
+ <fo:region-body/>
+ </fo:simple-page-master>
+ </fo:layout-master-set>
+ <fo:page-sequence master-reference="normal" white-space-collapse="true">
+ <fo:flow flow-name="xsl-region-body">
+ <fo:block>Invalid image:</fo:block>
+ <fo:block>
+ <fo:external-graphic src="file://localhost/some-invalid-uri.png"/>EOG
+ </fo:block>
+ <fo:block>
+ <fo:external-graphic src="file://localhost/some-invalid-uri.png" content-width="5pt" content-height="5pt"/>EOG
+ </fo:block>
+ <fo:block>
+ <fo:external-graphic src="file://localhost/some-invalid-uri.png" content-width="5pt"/>EOG
+ </fo:block>
+ <fo:block>
+ <fo:external-graphic src="file://localhost/some-invalid-uri.png" content-height="5pt"/>EOG
+ </fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+ </fo:root>
+ </fo>
+ <checks>
+ <!-- We don't test anything particular. We just don't want any ArithmeticExceptions (div by zero). -->
+ <eval expected="1" xpath="count(//pageViewport)"/>
+ </checks>
+</testcase>