use of org.apache.poi.hslf.usermodel.HSLFShape in project poi by apache.
the class TestShapes method shapeGroup.
/**
* Test adding shapes to <code>ShapeGroup</code>
*/
@Test
public void shapeGroup() throws IOException {
HSLFSlideShow ss = new HSLFSlideShow();
HSLFSlide slide = ss.createSlide();
Dimension pgsize = ss.getPageSize();
HSLFGroupShape group = new HSLFGroupShape();
group.setAnchor(new Rectangle2D.Double(0, 0, pgsize.getWidth(), pgsize.getHeight()));
slide.addShape(group);
HSLFPictureData data = ss.addPicture(_slTests.readFile("clock.jpg"), PictureType.JPEG);
HSLFPictureShape pict = new HSLFPictureShape(data, group);
pict.setAnchor(new Rectangle2D.Double(0, 0, 200, 200));
group.addShape(pict);
HSLFLine line = new HSLFLine(group);
line.setAnchor(new Rectangle2D.Double(300, 300, 500, 0));
group.addShape(line);
//serialize and read again.
ByteArrayOutputStream out = new ByteArrayOutputStream();
ss.write(out);
out.close();
ss.close();
ByteArrayInputStream is = new ByteArrayInputStream(out.toByteArray());
ss = new HSLFSlideShow(is);
is.close();
slide = ss.getSlides().get(0);
List<HSLFShape> shape = slide.getShapes();
assertEquals(1, shape.size());
assertTrue(shape.get(0) instanceof HSLFGroupShape);
group = (HSLFGroupShape) shape.get(0);
List<HSLFShape> grshape = group.getShapes();
assertEquals(2, grshape.size());
assertTrue(grshape.get(0) instanceof HSLFPictureShape);
assertTrue(grshape.get(1) instanceof HSLFLine);
pict = (HSLFPictureShape) grshape.get(0);
assertEquals(new Rectangle2D.Double(0, 0, 200, 200), pict.getAnchor());
line = (HSLFLine) grshape.get(1);
assertEquals(new Rectangle2D.Double(300, 300, 500, 0), line.getAnchor());
ss.close();
}
use of org.apache.poi.hslf.usermodel.HSLFShape in project poi by apache.
the class TestShapes method textBoxSet.
private void textBoxSet(String filename) throws IOException {
HSLFSlideShow ss = new HSLFSlideShow(_slTests.openResourceAsStream(filename));
for (HSLFSlide sld : ss.getSlides()) {
ArrayList<String> lst1 = new ArrayList<String>();
for (List<HSLFTextParagraph> txt : sld.getTextParagraphs()) {
for (HSLFTextParagraph p : txt) {
for (HSLFTextRun r : p) {
lst1.add(r.getRawText());
}
}
}
ArrayList<String> lst2 = new ArrayList<String>();
for (HSLFShape sh : sld.getShapes()) {
if (sh instanceof HSLFTextShape) {
HSLFTextShape tbox = (HSLFTextShape) sh;
for (HSLFTextParagraph p : tbox.getTextParagraphs()) {
for (HSLFTextRun r : p) {
lst2.add(r.getRawText());
}
}
}
}
assertTrue(lst1.containsAll(lst2));
assertTrue(lst2.containsAll(lst1));
}
ss.close();
}
use of org.apache.poi.hslf.usermodel.HSLFShape in project poi by apache.
the class TestShapes method textBoxRead.
/**
* Verify that we can read TextBox shapes
* @throws Exception
*/
@Test
public void textBoxRead() throws IOException {
ppt = new HSLFSlideShow(_slTests.openResourceAsStream("with_textbox.ppt"));
HSLFSlide sl = ppt.getSlides().get(0);
for (HSLFShape sh : sl.getShapes()) {
assertTrue(sh instanceof HSLFTextBox);
HSLFTextBox txtbox = (HSLFTextBox) sh;
String text = txtbox.getText();
assertNotNull(text);
assertEquals(txtbox.getTextParagraphs().get(0).getTextRuns().size(), 1);
HSLFTextRun rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
if (text.equals("Hello, World!!!")) {
assertEquals(32, rt.getFontSize(), 0);
assertTrue(rt.isBold());
assertTrue(rt.isItalic());
} else if (text.equals("I am just a poor boy")) {
assertEquals(44, rt.getFontSize(), 0);
assertTrue(rt.isBold());
} else if (text.equals("This is Times New Roman")) {
assertEquals(16, rt.getFontSize(), 0);
assertTrue(rt.isBold());
assertTrue(rt.isItalic());
assertTrue(rt.isUnderlined());
} else if (text.equals("Plain Text")) {
assertEquals(18, rt.getFontSize(), 0);
}
}
}
use of org.apache.poi.hslf.usermodel.HSLFShape in project poi by apache.
the class TestShapes method graphics.
@Test
public void graphics() throws IOException {
HSLFSlide slide = ppt.createSlide();
HSLFLine line = new HSLFLine();
java.awt.Rectangle lineAnchor = new java.awt.Rectangle(100, 200, 50, 60);
line.setAnchor(lineAnchor);
line.setLineWidth(3);
line.setLineDash(LineDash.DASH);
line.setLineColor(Color.red);
slide.addShape(line);
HSLFAutoShape ellipse = new HSLFAutoShape(ShapeType.ELLIPSE);
Rectangle2D ellipseAnchor = new Rectangle2D.Double(320, 154, 55, 111);
ellipse.setAnchor(ellipseAnchor);
ellipse.setLineWidth(2);
ellipse.setLineDash(LineDash.SOLID);
ellipse.setLineColor(Color.green);
ellipse.setFillColor(Color.lightGray);
slide.addShape(ellipse);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ppt.write(out);
out.close();
//read ppt from byte array
HSLFSlideShow ppt2 = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
assertEquals(1, ppt2.getSlides().size());
slide = ppt2.getSlides().get(0);
List<HSLFShape> shape = slide.getShapes();
assertEquals(2, shape.size());
//group shape
assertTrue(shape.get(0) instanceof HSLFLine);
//group shape
assertEquals(lineAnchor, shape.get(0).getAnchor());
//group shape
assertTrue(shape.get(1) instanceof HSLFAutoShape);
//group shape
assertEquals(ellipseAnchor, shape.get(1).getAnchor());
ppt2.close();
}
use of org.apache.poi.hslf.usermodel.HSLFShape in project poi by apache.
the class TestBackground method defaults.
/**
* Default background for slide, shape and slide master.
*/
@Test
public void defaults() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
assertEquals(HSLFFill.FILL_SOLID, ppt.getSlideMasters().get(0).getBackground().getFill().getFillType());
HSLFSlide slide = ppt.createSlide();
assertTrue(slide.getFollowMasterBackground());
assertEquals(HSLFFill.FILL_SOLID, slide.getBackground().getFill().getFillType());
HSLFShape shape = new HSLFAutoShape(ShapeType.RECT);
assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
ppt.close();
}
Aggregations