use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestReWrite method assertSlideShowWritesOutTheSame.
public void assertSlideShowWritesOutTheSame(HSLFSlideShowImpl hss, POIFSFileSystem pfs) throws IOException {
// Create a slideshow covering it
@SuppressWarnings("resource") HSLFSlideShow ss = new HSLFSlideShow(hss);
ss.getSlides();
ss.getNotes();
// Now write out to a byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hss.write(baos);
// Build an input stream of it
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
// Use POIFS to query that lot
POIFSFileSystem npfs = new POIFSFileSystem(bais);
// Check that the "PowerPoint Document" sections have the same size
DocumentEntry oProps = (DocumentEntry) pfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
DocumentEntry nProps = (DocumentEntry) npfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
assertEquals(oProps.getSize(), nProps.getSize());
// Check that they contain the same data
byte[] _oData = new byte[oProps.getSize()];
byte[] _nData = new byte[nProps.getSize()];
pfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_oData);
npfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_nData);
for (int i = 0; i < _oData.length; i++) {
if (_oData[i] != _nData[i])
System.out.println(i + "\t" + Integer.toHexString(i));
assertEquals(_oData[i], _nData[i]);
}
npfs.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestReWrite method test48593.
@Test
public void test48593() throws IOException {
HSLFSlideShow ppt1 = new HSLFSlideShow();
ppt1.createSlide();
HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
ppt2.createSlide();
HSLFSlideShow ppt3 = HSLFTestDataSamples.writeOutAndReadBack(ppt2);
ppt3.createSlide();
HSLFSlideShow ppt4 = HSLFTestDataSamples.writeOutAndReadBack(ppt3);
ppt4.createSlide();
HSLFTestDataSamples.writeOutAndReadBack(ppt4).close();
ppt4.close();
ppt3.close();
ppt2.close();
ppt1.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestTable method test45889.
/**
* Error constructing Table when rownum=1
*/
@Test
public void test45889() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
List<HSLFShape> shapes;
HSLFTable tbl1 = slide.createTable(1, 5);
assertEquals(5, tbl1.getNumberOfColumns());
assertEquals(1, tbl1.getNumberOfRows());
shapes = slide.getShapes();
assertEquals(1, shapes.size());
HSLFTable tbl2 = (HSLFTable) shapes.get(0);
assertSame(tbl1.getSpContainer(), tbl2.getSpContainer());
assertEquals(tbl1.getNumberOfColumns(), tbl2.getNumberOfColumns());
assertEquals(tbl1.getNumberOfRows(), tbl2.getNumberOfRows());
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestPPFont method testCreate.
@Test
public void testCreate() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
assertEquals(1, ppt.getNumberOfFonts());
assertEquals("Arial", ppt.getFont(0).getFontName());
//adding the same font twice
assertEquals(0, ppt.addFont(PPFont.ARIAL));
assertEquals(1, ppt.getNumberOfFonts());
assertEquals(1, ppt.addFont(PPFont.TIMES_NEW_ROMAN));
assertEquals(2, ppt.addFont(PPFont.COURIER_NEW));
assertEquals(3, ppt.addFont(PPFont.WINGDINGS));
assertEquals(4, ppt.getNumberOfFonts());
assertEquals(PPFont.TIMES_NEW_ROMAN.getFontName(), ppt.getFont(1).getFontName());
assertEquals(PPFont.COURIER_NEW.getFontName(), ppt.getFont(2).getFontName());
PPFont font3 = ppt.getFont(3);
assertEquals(PPFont.WINGDINGS.getFontName(), font3.getFontName());
assertEquals(PPFont.SYMBOL_CHARSET, font3.getCharSet());
assertEquals(PPFont.VARIABLE_PITCH, font3.getPitchAndFamily());
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestShapes method removeShapes.
/**
* Test functionality of Sheet.removeShape(Shape shape)
*/
@Test
public void removeShapes() throws IOException {
String file = "with_textbox.ppt";
HSLFSlideShow ss = new HSLFSlideShow(_slTests.openResourceAsStream(file));
HSLFSlide sl = ss.getSlides().get(0);
List<HSLFShape> sh = sl.getShapes();
assertEquals("expected four shaped in " + file, 4, sh.size());
//remove all
for (int i = 0; i < sh.size(); i++) {
boolean ok = sl.removeShape(sh.get(i));
assertTrue("Failed to delete shape #" + i, ok);
}
//now Slide.getShapes() should return an empty array
assertEquals("expected 0 shaped in " + file, 0, sl.getShapes().size());
//serialize and read again. The file should be readable and contain no shapes
ByteArrayOutputStream out = new ByteArrayOutputStream();
ss.write(out);
out.close();
ss.close();
ss = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
sl = ss.getSlides().get(0);
assertEquals("expected 0 shaped in " + file, 0, sl.getShapes().size());
ss.close();
}
Aggregations