From f89c2115397625fc9194f676eb7e0feb9a03ee95 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Thu, 24 May 2007 12:09:34 +0000 Subject: [PATCH] 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 --- .../org/apache/poi/hslf/model/ShapeGroup.java | 18 +++++++++++++++ .../apache/poi/hslf/usermodel/TestBugs.java | 23 +++++++++++++++++++ 2 files changed, 41 insertions(+) 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); + } + } -- 2.39.5