* @param idx the index of the picture
*/
public Picture(int idx){
- super(null, null);
- _escherContainer = createSpContainer(idx);
+ this(idx, null);
+ }
+
+ /**
+ * Create a new <code>Picture</code>
+ *
+ * @param idx the index of the picture
+ * @param parent the parent shape
+ */
+ public Picture(int idx, Shape parent) {
+ super(null, parent);
+ _escherContainer = createSpContainer(idx, parent instanceof ShapeGroup);
}
/**
* @param idx the index of the picture which referes to <code>EscherBSE</code> container.
* @return the create Picture object
*/
- protected EscherContainerRecord createSpContainer(int idx) {
- EscherContainerRecord spContainer = super.createSpContainer(false);
+ protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {
+ EscherContainerRecord spContainer = super.createSpContainer(isChild);
spContainer.setOptions((short)15);
EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
anchor = new java.awt.Rectangle();
anchor.x = rec.getDx1()*POINT_DPI/MASTER_DPI;
anchor.y = rec.getDy1()*POINT_DPI/MASTER_DPI;
- anchor.width = (rec.getDx2() - anchor.x)*POINT_DPI/MASTER_DPI;
- anchor.height = (rec.getDy2() - anchor.y)*POINT_DPI/MASTER_DPI;
+ anchor.width = rec.getDx2()*POINT_DPI/MASTER_DPI - anchor.x;
+ anchor.height = rec.getDy2()*POINT_DPI/MASTER_DPI - anchor.y;
}
else {
EscherClientAnchorRecord rec = (EscherClientAnchorRecord)getEscherChild(_escherContainer, EscherClientAnchorRecord.RECORD_ID);
import java.awt.Rectangle;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
+import java.io.File;
import java.util.ArrayList;
/**
assertTrue(lst2.containsAll(lst1));
}
}
+
+ /**
+ * Test adding shapes to <code>ShapeGroup</code>
+ */
+ public void testShapeGroup() throws Exception {
+ String cwd = System.getProperty("HSLF.testdata.path");
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+ Dimension pgsize = ppt.getPageSize();
+
+ ShapeGroup group = new ShapeGroup();
+
+ group.setAnchor(new Rectangle(0, 0, (int)pgsize.getWidth(), (int)pgsize.getHeight()));
+ slide.addShape(group);
+
+ File img = new File(cwd, "clock.jpg");
+ int idx = ppt.addPicture(img, Picture.JPEG);
+ Picture pict = new Picture(idx, group);
+ pict.setAnchor(new Rectangle(0, 0, 200, 200));
+ group.addShape(pict);
+
+ Line line = new Line(group);
+ line.setAnchor(new Rectangle(300, 300, 500, 0));
+ group.addShape(line);
+
+ //serialize and read again.
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(out.toByteArray());
+ ppt = new SlideShow(is);
+ is.close();
+
+ slide = ppt.getSlides()[0];
+
+ Shape[] shape = slide.getShapes();
+ assertEquals(1, shape.length);
+ assertTrue(shape[0] instanceof ShapeGroup);
+
+ group = (ShapeGroup)shape[0];
+ Shape[] grshape = group.getShapes();
+ assertEquals(2, grshape.length);
+ assertTrue(grshape[0] instanceof Picture);
+ assertTrue(grshape[1] instanceof Line);
+
+ pict = (Picture)grshape[0];
+ assertEquals(new Rectangle(0, 0, 200, 200), pict.getAnchor());
+
+ line = (Line)grshape[1];
+ assertEquals(new Rectangle(300, 300, 500, 0), line.getAnchor());
+ }
}