use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.
the class TestHeadersFooters method bug58144b.
@Test
public void bug58144b() throws IOException {
assumeFalse(xslfOnly);
SlideShow<?, ?> ppt = openSampleSlideshow("bug58144-headers-footers-2007.ppt");
Slide<?, ?> sl = ppt.getSlides().get(0);
HeadersFooters hfs2 = ((HSLFSlide) sl).getHeadersFooters();
assertNull(hfs2.getHeaderText());
assertEquals("Slide footer", hfs2.getFooterText());
testSlideShow(ppt);
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.
the class TestHeadersFooters method bug58144a.
@Test
public void bug58144a() throws IOException {
assumeFalse(xslfOnly);
SlideShow<?, ?> ppt = openSampleSlideshow("bug58144-headers-footers-2003.ppt");
HSLFSlide sl = (HSLFSlide) ppt.getSlides().get(0);
HeadersFooters hfs = sl.getHeadersFooters();
assertNull(hfs.getHeaderText());
assertEquals("Confidential", hfs.getFooterText());
List<List<HSLFTextParagraph>> llp = sl.getTextParagraphs();
assertEquals("Test", HSLFTextParagraph.getText(llp.get(0)));
assertFalse(llp.get(0).get(0).isHeaderOrFooter());
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.
the class TestShapes method shapeId.
@Test
public void shapeId() throws IOException {
HSLFSlideShow ss = new HSLFSlideShow();
HSLFSlide slide = ss.createSlide();
HSLFShape shape = null;
//EscherDgg is a document-level record which keeps track of the drawing groups
EscherDggRecord dgg = ss.getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
EscherDgRecord dg = slide.getSheetContainer().getPPDrawing().getEscherDgRecord();
//total number of shapes in the ppt
int dggShapesUsed = dgg.getNumShapesSaved();
//max number of shapeId
int dggMaxId = dgg.getShapeIdMax();
//max shapeId in the slide
int dgMaxId = dg.getLastMSOSPID();
// number of shapes in the slide
int dgShapesUsed = dg.getNumShapes();
//insert 3 shapes and make sure the Ids are properly incremented
for (int i = 0; i < 3; i++) {
shape = new HSLFLine();
assertEquals(0, shape.getShapeId());
slide.addShape(shape);
assertTrue(shape.getShapeId() > 0);
//check that EscherDgRecord is updated
assertEquals(shape.getShapeId(), dg.getLastMSOSPID());
assertEquals(dgMaxId + 1, dg.getLastMSOSPID());
assertEquals(dgShapesUsed + 1, dg.getNumShapes());
//check that EscherDggRecord is updated
assertEquals(shape.getShapeId() + 1, dgg.getShapeIdMax());
assertEquals(dggMaxId + 1, dgg.getShapeIdMax());
assertEquals(dggShapesUsed + 1, dgg.getNumShapesSaved());
dggShapesUsed = dgg.getNumShapesSaved();
dggMaxId = dgg.getShapeIdMax();
dgMaxId = dg.getLastMSOSPID();
dgShapesUsed = dg.getNumShapes();
}
//For each drawing group PPT allocates clusters with size=1024
//if the number of shapes is greater that 1024 a new cluster is allocated
//make sure it is so
int numClusters = dgg.getNumIdClusters();
for (int i = 0; i < 1025; i++) {
shape = new HSLFLine();
slide.addShape(shape);
}
assertEquals(numClusters + 1, dgg.getNumIdClusters());
ss.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlide 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.HSLFSlide 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();
}
Aggregations