Search in sources :

Example 6 with HSLFSlide

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

the class TestSlideMaster method testMasterAttributes.

/**
     * If a style attribute is not set ensure it is read from the master
     */
@Test
public void testMasterAttributes() throws Exception {
    HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
    List<HSLFSlide> slide = ppt.getSlides();
    assertEquals(3, slide.size());
    for (List<HSLFTextParagraph> tparas : slide.get(0).getTextParagraphs()) {
        HSLFTextParagraph tpara = tparas.get(0);
        if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE) {
            HSLFTextRun rt = tpara.getTextRuns().get(0);
            assertEquals(40, rt.getFontSize(), 0);
            assertEquals(true, rt.isUnderlined());
            assertEquals("Arial", rt.getFontFamily());
        } else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE) {
            HSLFTextRun rt = tpara.getTextRuns().get(0);
            assertEquals(0, tpara.getIndentLevel());
            assertEquals(32, rt.getFontSize(), 0);
            assertEquals("Arial", rt.getFontFamily());
            tpara = tparas.get(1);
            rt = tpara.getTextRuns().get(0);
            assertEquals(1, tpara.getIndentLevel());
            assertEquals(28, rt.getFontSize(), 0);
            assertEquals("Arial", rt.getFontFamily());
        }
    }
    for (List<HSLFTextParagraph> tparas : slide.get(1).getTextParagraphs()) {
        HSLFTextParagraph tpara = tparas.get(0);
        if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE) {
            HSLFTextRun rt = tpara.getTextRuns().get(0);
            assertEquals(48, rt.getFontSize(), 0);
            assertEquals(true, rt.isItalic());
            assertEquals("Georgia", rt.getFontFamily());
        } else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE) {
            HSLFTextRun rt;
            rt = tpara.getTextRuns().get(0);
            assertEquals(0, tpara.getIndentLevel());
            assertEquals(32, rt.getFontSize(), 0);
            assertEquals("Courier New", rt.getFontFamily());
        }
    }
    ppt.close();
}
Also used : HSLFTextRun(org.apache.poi.hslf.usermodel.HSLFTextRun) HSLFTextParagraph(org.apache.poi.hslf.usermodel.HSLFTextParagraph) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 7 with HSLFSlide

use of org.apache.poi.hslf.usermodel.HSLFSlide 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 8 with HSLFSlide

use of org.apache.poi.hslf.usermodel.HSLFSlide 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)

Example 9 with HSLFSlide

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

the class TestBackground method backgroundPicture.

/**
     * Create a ppt with various fill effects
     */
@Test
public void backgroundPicture() throws IOException {
    HSLFSlideShow ppt1 = new HSLFSlideShow();
    HSLFSlide slide;
    HSLFFill fill;
    HSLFShape shape;
    HSLFPictureData data;
    //slide 1
    slide = ppt1.createSlide();
    slide.setFollowMasterBackground(false);
    fill = slide.getBackground().getFill();
    data = ppt1.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG);
    fill.setFillType(HSLFFill.FILL_PICTURE);
    fill.setPictureData(data);
    shape = new HSLFAutoShape(ShapeType.RECT);
    shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
    fill = shape.getFill();
    fill.setFillType(HSLFFill.FILL_SOLID);
    slide.addShape(shape);
    //slide 2
    slide = ppt1.createSlide();
    slide.setFollowMasterBackground(false);
    fill = slide.getBackground().getFill();
    data = ppt1.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG);
    fill.setFillType(HSLFFill.FILL_PATTERN);
    fill.setPictureData(data);
    fill.setBackgroundColor(Color.green);
    fill.setForegroundColor(Color.red);
    shape = new HSLFAutoShape(ShapeType.RECT);
    shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
    fill = shape.getFill();
    fill.setFillType(HSLFFill.FILL_BACKGROUND);
    slide.addShape(shape);
    //slide 3
    slide = ppt1.createSlide();
    slide.setFollowMasterBackground(false);
    fill = slide.getBackground().getFill();
    data = ppt1.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG);
    fill.setFillType(HSLFFill.FILL_TEXTURE);
    fill.setPictureData(data);
    shape = new HSLFAutoShape(ShapeType.RECT);
    shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
    fill = shape.getFill();
    fill.setFillType(HSLFFill.FILL_PICTURE);
    data = ppt1.addPicture(_slTests.readFile("clock.jpg"), PictureType.JPEG);
    fill.setPictureData(data);
    slide.addShape(shape);
    // slide 4
    slide = ppt1.createSlide();
    slide.setFollowMasterBackground(false);
    fill = slide.getBackground().getFill();
    fill.setFillType(HSLFFill.FILL_SHADE_CENTER);
    fill.setBackgroundColor(Color.white);
    fill.setForegroundColor(Color.darkGray);
    shape = new HSLFAutoShape(ShapeType.RECT);
    shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
    fill = shape.getFill();
    fill.setFillType(HSLFFill.FILL_SHADE);
    fill.setBackgroundColor(Color.red);
    fill.setForegroundColor(Color.green);
    slide.addShape(shape);
    //serialize and read again
    HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
    List<HSLFSlide> slides = ppt2.getSlides();
    fill = slides.get(0).getBackground().getFill();
    assertEquals(HSLFFill.FILL_PICTURE, fill.getFillType());
    assertEquals(3, getFillPictureRefCount(slides.get(0).getBackground(), fill));
    shape = slides.get(0).getShapes().get(0);
    assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
    fill = slides.get(1).getBackground().getFill();
    assertEquals(HSLFFill.FILL_PATTERN, fill.getFillType());
    shape = slides.get(1).getShapes().get(0);
    assertEquals(HSLFFill.FILL_BACKGROUND, shape.getFill().getFillType());
    fill = slides.get(2).getBackground().getFill();
    assertEquals(HSLFFill.FILL_TEXTURE, fill.getFillType());
    assertEquals(3, getFillPictureRefCount(slides.get(2).getBackground(), fill));
    shape = slides.get(2).getShapes().get(0);
    assertEquals(HSLFFill.FILL_PICTURE, shape.getFill().getFillType());
    assertEquals(1, getFillPictureRefCount(shape, fill));
    fill = slides.get(3).getBackground().getFill();
    assertEquals(HSLFFill.FILL_SHADE_CENTER, fill.getFillType());
    shape = slides.get(3).getShapes().get(0);
    assertEquals(HSLFFill.FILL_SHADE, shape.getFill().getFillType());
    ppt2.close();
    ppt1.close();
}
Also used : HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSLFAutoShape(org.apache.poi.hslf.usermodel.HSLFAutoShape) HSLFPictureData(org.apache.poi.hslf.usermodel.HSLFPictureData) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) HSLFFill(org.apache.poi.hslf.usermodel.HSLFFill) Test(org.junit.Test)

Example 10 with HSLFSlide

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

the class TestBackground method readBackground.

/**
     * Read fill information from an reference ppt file
     */
@Test
public void readBackground() throws IOException {
    HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("backgrounds.ppt");
    HSLFFill fill;
    HSLFShape shape;
    List<HSLFSlide> slide = ppt.getSlides();
    fill = slide.get(0).getBackground().getFill();
    assertEquals(HSLFFill.FILL_PICTURE, fill.getFillType());
    shape = slide.get(0).getShapes().get(0);
    assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
    fill = slide.get(1).getBackground().getFill();
    assertEquals(HSLFFill.FILL_PATTERN, fill.getFillType());
    shape = slide.get(1).getShapes().get(0);
    assertEquals(HSLFFill.FILL_BACKGROUND, shape.getFill().getFillType());
    fill = slide.get(2).getBackground().getFill();
    assertEquals(HSLFFill.FILL_TEXTURE, fill.getFillType());
    shape = slide.get(2).getShapes().get(0);
    assertEquals(HSLFFill.FILL_PICTURE, shape.getFill().getFillType());
    fill = slide.get(3).getBackground().getFill();
    assertEquals(HSLFFill.FILL_SHADE_CENTER, fill.getFillType());
    shape = slide.get(3).getShapes().get(0);
    assertEquals(HSLFFill.FILL_SHADE, shape.getFill().getFillType());
    ppt.close();
}
Also used : HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFFill(org.apache.poi.hslf.usermodel.HSLFFill) 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