support for adding Picture to ShapeGroup in HSLF. See Bug 43323 for details.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@573955 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2007-09-09 07:38:35 +00:00
parent 177caeec53
commit 7356dd361c
3 changed files with 70 additions and 6 deletions

View File

@ -75,8 +75,18 @@ public class Picture extends SimpleShape {
* @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);
}
/**
@ -109,8 +119,8 @@ public class Picture extends SimpleShape {
* @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);

View File

@ -151,8 +151,8 @@ public abstract class Shape {
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);

View File

@ -25,6 +25,7 @@ import java.awt.*;
import java.awt.Rectangle;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.ArrayList;
/**
@ -225,4 +226,57 @@ public class TestShapes extends TestCase {
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());
}
}