From: Yegor Kozlov Date: Thu, 24 May 2007 12:09:34 +0000 (+0000) Subject: fixed bug 42484: NullPointerException from ShapeGroup.getAnchor() X-Git-Tag: REL_3_0_1_RC1~18 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f89c2115397625fc9194f676eb7e0feb9a03ee95;p=poi.git fixed bug 42484: NullPointerException from ShapeGroup.getAnchor() git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@541281 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java b/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java index 8519e88af3..caea86ae6e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java @@ -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; + } } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java index 89f97959d7..21540fb5e1 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java @@ -140,4 +140,27 @@ public class TestBugs extends TestCase { } } + /** + * 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); + } + }