Author: yegor
Date: Thu May 24 05:09:34 2007
New Revision: 541281

URL: http://svn.apache.org/viewvc?view=rev&rev=541281
Log:
fixed bug 42484: NullPointerException from ShapeGroup.getAnchor()

Modified:
    
jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java
    
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java

Modified: 
jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java
URL: 
http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java?view=diff&rev=541281&r1=541280&r2=541281
==============================================================================
--- 
jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java 
(original)
+++ 
jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java 
Thu May 24 05:09:34 2007
@@ -179,4 +179,22 @@
         }
     }
 
+    /**
+     * Returns the anchor (the bounding box rectangle) of this shape group.
+     * All coordinates are expressed in points (72 dpi).
+     *
+     * @return the anchor of this shape group
+     */
+    public java.awt.Rectangle getAnchor(){
+        EscherContainerRecord groupInfoContainer = 
(EscherContainerRecord)_escherContainer.getChild(0);
+        EscherSpgrRecord spgr = 
(EscherSpgrRecord)getEscherChild(groupInfoContainer, 
EscherSpgrRecord.RECORD_ID);
+        java.awt.Rectangle anchor=null;
+
+        anchor = new java.awt.Rectangle();
+        anchor.x = spgr.getRectX1()*POINT_DPI/MASTER_DPI;
+        anchor.y = spgr.getRectY1()*POINT_DPI/MASTER_DPI;
+        anchor.width = (spgr.getRectX2() - 
spgr.getRectX1())*POINT_DPI/MASTER_DPI;
+        anchor.height = (spgr.getRectY2() - 
spgr.getRectY1())*POINT_DPI/MASTER_DPI;
+        return anchor;
+    }
 }

Modified: 
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
URL: 
http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java?view=diff&rev=541281&r1=541280&r2=541281
==============================================================================
--- 
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
 (original)
+++ 
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
 Thu May 24 05:09:34 2007
@@ -140,4 +140,27 @@
         }
     }
 
+    /**
+     * Bug 42484: NullPointerException from ShapeGroup.getAnchor()
+     */
+    public void test42484 () throws Exception {
+        FileInputStream is = new FileInputStream(new File(cwd, "42485.ppt")); 
//test file is the same as for bug 42485
+        HSLFSlideShow hslf = new HSLFSlideShow(is);
+        is.close();
+
+        SlideShow ppt = new SlideShow(hslf);
+        Shape[] shape = ppt.getSlides()[0].getShapes();
+        for (int i = 0; i < shape.length; i++) {
+            if(shape[i] instanceof ShapeGroup){
+                ShapeGroup  group = (ShapeGroup)shape[i];
+                assertNotNull(group.getAnchor());
+                Shape[] sh = group.getShapes();
+                for (int j = 0; j < sh.length; j++) {
+                    assertNotNull(sh[j].getAnchor());
+                }
+            }
+        }
+        assertTrue("No Exceptions while reading file", true);
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/

Reply via email to