Search in sources :

Example 11 with HSLFSlideShow

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();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) DocumentEntry(org.apache.poi.poifs.filesystem.DocumentEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow)

Example 12 with HSLFSlideShow

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();
}
Also used : HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) Test(org.junit.Test)

Example 13 with HSLFSlideShow

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();
}
Also used : HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSLFTable(org.apache.poi.hslf.usermodel.HSLFTable) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 14 with HSLFSlideShow

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();
}
Also used : HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) Test(org.junit.Test)

Example 15 with HSLFSlideShow

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();
}
Also used : HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Aggregations

HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)69 Test (org.junit.Test)42 HSLFSlide (org.apache.poi.hslf.usermodel.HSLFSlide)39 HSLFShape (org.apache.poi.hslf.usermodel.HSLFShape)17 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 InputStream (java.io.InputStream)10 FileOutputStream (java.io.FileOutputStream)9 HSLFTextRun (org.apache.poi.hslf.usermodel.HSLFTextRun)9 HSLFTextParagraph (org.apache.poi.hslf.usermodel.HSLFTextParagraph)8 Rectangle2D (java.awt.geom.Rectangle2D)7 FileInputStream (java.io.FileInputStream)7 HSLFPictureData (org.apache.poi.hslf.usermodel.HSLFPictureData)7 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)7 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)7 HSLFSlideShowImpl (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)6 HSLFTextBox (org.apache.poi.hslf.usermodel.HSLFTextBox)5 POIDataSamples (org.apache.poi.POIDataSamples)4 Record (org.apache.poi.hslf.record.Record)4 HSLFHyperlink (org.apache.poi.hslf.usermodel.HSLFHyperlink)4