From c1e5695d67b7496ec611c52b345d4022415ae1d4 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Tue, 29 Nov 2005 10:33:01 +0000 Subject: Bugfix for "/ by zero" ArithmeticExceptions when an URL to a non-existing image is used and content-width and/or content-height is used. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@349698 13f79535-47bb-0310-9956-ffa450edef68 --- .../inline/AbstractGraphicsLayoutManager.java | 37 ++++++++++----- .../external-graphic_invalid.xml | 55 ++++++++++++++++++++++ 2 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 test/layoutengine/standard-testcases/external-graphic_invalid.xml 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 @@ + + + + + +

+ 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. +

+
+ + + + + + + + + + Invalid image: + + EOG + + + EOG + + + EOG + + + EOG + + + + + + + + + +
-- cgit v1.2.3