Search in sources :

Example 36 with HSLFSlide

use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.

the class TestSlideMaster method testTitleMaster.

/**
     * Slide 3 has title layout and follows the TitleMaster. Verify that.
     */
@Test
public void testTitleMaster() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
    HSLFSlide slide = ppt.getSlides().get(2);
    HSLFMasterSheet masterSheet = slide.getMasterSheet();
    assertTrue(masterSheet instanceof HSLFTitleMaster);
    for (List<HSLFTextParagraph> txt : slide.getTextParagraphs()) {
        HSLFTextRun rt = txt.get(0).getTextRuns().get(0);
        switch(txt.get(0).getRunType()) {
            case TextHeaderAtom.CENTER_TITLE_TYPE:
                assertEquals("Arial", rt.getFontFamily());
                assertEquals(32, rt.getFontSize(), 0);
                assertEquals(true, rt.isBold());
                assertEquals(true, rt.isUnderlined());
                break;
            case TextHeaderAtom.CENTRE_BODY_TYPE:
                assertEquals("Courier New", rt.getFontFamily());
                assertEquals(20, rt.getFontSize(), 0);
                assertEquals(true, rt.isBold());
                assertEquals(false, rt.isUnderlined());
                break;
        }
    }
    ppt.close();
}
Also used : HSLFTextRun(org.apache.poi.hslf.usermodel.HSLFTextRun) HSLFMasterSheet(org.apache.poi.hslf.usermodel.HSLFMasterSheet) HSLFTextParagraph(org.apache.poi.hslf.usermodel.HSLFTextParagraph) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) HSLFTitleMaster(org.apache.poi.hslf.usermodel.HSLFTitleMaster) Test(org.junit.Test)

Example 37 with HSLFSlide

use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.

the class TestSlideMaster method testChangeSlideMaster.

/**
     * Check we can dynamically assign a slide master to a slide.
     */
@Test
public void testChangeSlideMaster() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
    List<HSLFSlideMaster> master = ppt.getSlideMasters();
    List<HSLFSlide> slide = ppt.getSlides();
    int sheetNo;
    //each slide uses its own master
    assertEquals(slide.get(0).getMasterSheet()._getSheetNumber(), master.get(0)._getSheetNumber());
    assertEquals(slide.get(1).getMasterSheet()._getSheetNumber(), master.get(1)._getSheetNumber());
    //all slides use the first master slide
    sheetNo = master.get(0)._getSheetNumber();
    for (HSLFSlide s : slide) {
        s.setMasterSheet(master.get(0));
    }
    ByteArrayOutputStream out;
    out = new ByteArrayOutputStream();
    ppt.write(out);
    out.close();
    ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
    master = ppt.getSlideMasters();
    slide = ppt.getSlides();
    for (HSLFSlide s : slide) {
        assertEquals(sheetNo, s.getMasterSheet()._getSheetNumber());
    }
    ppt.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HSLFSlideMaster(org.apache.poi.hslf.usermodel.HSLFSlideMaster) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Test(org.junit.Test)

Example 38 with HSLFSlide

use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.

the class TestTable method testIllegalColConstruction.

@Test(expected = IllegalArgumentException.class)
public void testIllegalColConstruction() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow();
    HSLFSlide slide = ppt.createSlide();
    slide.createTable(5, 0);
    fail("Table(rownum, colnum) must throw IllegalArgumentException if any of tghe arguments is less than 1");
    ppt.close();
}
Also used : HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 39 with HSLFSlide

use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.

the class TestTable method testShapeFactory.

/**
     * Test that ShapeFactory works properly and returns <code>Table</code>
     */
@Test
public void testShapeFactory() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow();
    HSLFSlide slide = ppt.createSlide();
    HSLFTable tbl = slide.createTable(2, 5);
    HSLFTableCell cell = tbl.getCell(0, 0);
    //table cells have type=TextHeaderAtom.OTHER_TYPE, see bug #46033
    assertEquals(TextHeaderAtom.OTHER_TYPE, cell.getTextParagraphs().get(0).getRunType());
    HSLFShape tblSh = slide.getShapes().get(0);
    assertTrue(tblSh instanceof HSLFTable);
    HSLFTable tbl2 = (HSLFTable) tblSh;
    assertEquals(tbl.getNumberOfColumns(), tbl2.getNumberOfColumns());
    assertEquals(tbl.getNumberOfRows(), tbl2.getNumberOfRows());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ppt.write(out);
    out.close();
    ppt.close();
    ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
    slide = ppt.getSlides().get(0);
    assertTrue(slide.getShapes().get(0) instanceof HSLFTable);
    HSLFTable tbl3 = (HSLFTable) slide.getShapes().get(0);
    assertEquals(tbl.getNumberOfColumns(), tbl3.getNumberOfColumns());
    assertEquals(tbl.getNumberOfRows(), tbl3.getNumberOfRows());
    ppt.close();
}
Also used : HSLFTable(org.apache.poi.hslf.usermodel.HSLFTable) HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) ByteArrayInputStream(java.io.ByteArrayInputStream) HSLFTableCell(org.apache.poi.hslf.usermodel.HSLFTableCell) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 40 with HSLFSlide

use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.

the class TestTable method testIllegalRowCnstruction.

@Test(expected = IllegalArgumentException.class)
public void testIllegalRowCnstruction() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow();
    HSLFSlide slide = ppt.createSlide();
    slide.createTable(0, 5);
    fail("Table(rownum, colnum) must throw IllegalArgumentException if any of tghe arguments is less than 1");
    ppt.close();
}
Also used : HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Aggregations

HSLFSlide (org.apache.poi.hslf.usermodel.HSLFSlide)43 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)39 Test (org.junit.Test)32 HSLFShape (org.apache.poi.hslf.usermodel.HSLFShape)17 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 HSLFTextRun (org.apache.poi.hslf.usermodel.HSLFTextRun)9 HSLFTextParagraph (org.apache.poi.hslf.usermodel.HSLFTextParagraph)8 Rectangle2D (java.awt.geom.Rectangle2D)7 FileOutputStream (java.io.FileOutputStream)6 HSLFPictureData (org.apache.poi.hslf.usermodel.HSLFPictureData)6 HSLFTextBox (org.apache.poi.hslf.usermodel.HSLFTextBox)6 InputStream (java.io.InputStream)5 FileInputStream (java.io.FileInputStream)4 HeadersFooters (org.apache.poi.hslf.model.HeadersFooters)4 HSLFHyperlink (org.apache.poi.hslf.usermodel.HSLFHyperlink)4 HSLFLine (org.apache.poi.hslf.usermodel.HSLFLine)4 HSLFTable (org.apache.poi.hslf.usermodel.HSLFTable)4 HSLFAutoShape (org.apache.poi.hslf.usermodel.HSLFAutoShape)3 Dimension (java.awt.Dimension)2