You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2005/11/29 11:33:11 UTC

svn commit: r349698 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java test/layoutengine/standard-testcases/external-graphic_invalid.xml

Author: jeremias
Date: Tue Nov 29 02:33:01 2005
New Revision: 349698

URL: http://svn.apache.org/viewcvs?rev=349698&view=rev
Log:
Bugfix for "/ by zero" ArithmeticExceptions when an URL to a non-existing image is used and content-width and/or content-height is used.

Added:
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/external-graphic_invalid.xml   (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java?rev=349698&r1=349697&r2=349698&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java Tue Nov 29 02:33:01 2005
@@ -22,7 +22,6 @@
 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 @@
 
         int bpd = -1;
         int ipd = -1;
-        boolean bpdauto = false;
         if (hasLH) {
             bpd = fobj.getLineHeight().getOptimum(this).getLength().getValue(this);
         } else {
@@ -130,20 +128,33 @@
                 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());
+                    }
                 }
             }
         }

Added: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/external-graphic_invalid.xml
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/external-graphic_invalid.xml?rev=349698&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/external-graphic_invalid.xml (added)
+++ xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/external-graphic_invalid.xml Tue Nov 29 02:33:01 2005
@@ -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>

Propchange: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/external-graphic_invalid.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/external-graphic_invalid.xml
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org