]> source.dussan.org Git - poi.git/commitdiff
fixed bug 42484: NullPointerException from ShapeGroup.getAnchor()
authorYegor Kozlov <yegor@apache.org>
Thu, 24 May 2007 12:09:34 +0000 (12:09 +0000)
committerYegor Kozlov <yegor@apache.org>
Thu, 24 May 2007 12:09:34 +0000 (12:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@541281 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java

index 8519e88af3a65979799557ad605a21e0100b3bd3..caea86ae6e17a4d9441266b41a2889ae7df5963b 100644 (file)
@@ -179,4 +179,22 @@ public class ShapeGroup extends Shape{
         }
     }
 
+    /**
+     * 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;
+    }
 }
index 89f97959d772390fd7f0989f293f6ecbd4ceab4f..21540fb5e159e2ec881db501ff8f0c8f763007dd 100644 (file)
@@ -140,4 +140,27 @@ public class TestBugs extends TestCase {
         }\r
     }\r
 \r
+    /**\r
+     * Bug 42484: NullPointerException from ShapeGroup.getAnchor()\r
+     */\r
+    public void test42484 () throws Exception {\r
+        FileInputStream is = new FileInputStream(new File(cwd, "42485.ppt")); //test file is the same as for bug 42485\r
+        HSLFSlideShow hslf = new HSLFSlideShow(is);\r
+        is.close();\r
+\r
+        SlideShow ppt = new SlideShow(hslf);\r
+        Shape[] shape = ppt.getSlides()[0].getShapes();\r
+        for (int i = 0; i < shape.length; i++) {\r
+            if(shape[i] instanceof ShapeGroup){\r
+                ShapeGroup  group = (ShapeGroup)shape[i];\r
+                assertNotNull(group.getAnchor());\r
+                Shape[] sh = group.getShapes();\r
+                for (int j = 0; j < sh.length; j++) {\r
+                    assertNotNull(sh[j].getAnchor());\r
+                }\r
+            }\r
+        }\r
+        assertTrue("No Exceptions while reading file", true);\r
+    }\r
+\r
 }\r