Search in sources :

Example 11 with HSLFShape

use of org.apache.poi.hslf.usermodel.HSLFShape 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();
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Dimension(java.awt.Dimension) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFGroupShape(org.apache.poi.hslf.usermodel.HSLFGroupShape) HSLFLine(org.apache.poi.hslf.usermodel.HSLFLine) HSLFPictureShape(org.apache.poi.hslf.usermodel.HSLFPictureShape) HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) ByteArrayInputStream(java.io.ByteArrayInputStream) HSLFPictureData(org.apache.poi.hslf.usermodel.HSLFPictureData) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 12 with HSLFShape

use of org.apache.poi.hslf.usermodel.HSLFShape 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();
}
Also used : HSLFTextRun(org.apache.poi.hslf.usermodel.HSLFTextRun) HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSLFTextParagraph(org.apache.poi.hslf.usermodel.HSLFTextParagraph) ArrayList(java.util.ArrayList) HSLFTextShape(org.apache.poi.hslf.usermodel.HSLFTextShape) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide)

Example 13 with HSLFShape

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

the class TestShapes method textBoxRead.

/**
     * Verify that we can read TextBox shapes
     * @throws Exception
     */
@Test
public void textBoxRead() throws IOException {
    ppt = new HSLFSlideShow(_slTests.openResourceAsStream("with_textbox.ppt"));
    HSLFSlide sl = ppt.getSlides().get(0);
    for (HSLFShape sh : sl.getShapes()) {
        assertTrue(sh instanceof HSLFTextBox);
        HSLFTextBox txtbox = (HSLFTextBox) sh;
        String text = txtbox.getText();
        assertNotNull(text);
        assertEquals(txtbox.getTextParagraphs().get(0).getTextRuns().size(), 1);
        HSLFTextRun rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
        if (text.equals("Hello, World!!!")) {
            assertEquals(32, rt.getFontSize(), 0);
            assertTrue(rt.isBold());
            assertTrue(rt.isItalic());
        } else if (text.equals("I am just a poor boy")) {
            assertEquals(44, rt.getFontSize(), 0);
            assertTrue(rt.isBold());
        } else if (text.equals("This is Times New Roman")) {
            assertEquals(16, rt.getFontSize(), 0);
            assertTrue(rt.isBold());
            assertTrue(rt.isItalic());
            assertTrue(rt.isUnderlined());
        } else if (text.equals("Plain Text")) {
            assertEquals(18, rt.getFontSize(), 0);
        }
    }
}
Also used : HSLFTextRun(org.apache.poi.hslf.usermodel.HSLFTextRun) HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSLFTextBox(org.apache.poi.hslf.usermodel.HSLFTextBox) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 14 with HSLFShape

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

the class TestShapes method graphics.

@Test
public void graphics() throws IOException {
    HSLFSlide slide = ppt.createSlide();
    HSLFLine line = new HSLFLine();
    java.awt.Rectangle lineAnchor = new java.awt.Rectangle(100, 200, 50, 60);
    line.setAnchor(lineAnchor);
    line.setLineWidth(3);
    line.setLineDash(LineDash.DASH);
    line.setLineColor(Color.red);
    slide.addShape(line);
    HSLFAutoShape ellipse = new HSLFAutoShape(ShapeType.ELLIPSE);
    Rectangle2D ellipseAnchor = new Rectangle2D.Double(320, 154, 55, 111);
    ellipse.setAnchor(ellipseAnchor);
    ellipse.setLineWidth(2);
    ellipse.setLineDash(LineDash.SOLID);
    ellipse.setLineColor(Color.green);
    ellipse.setFillColor(Color.lightGray);
    slide.addShape(ellipse);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ppt.write(out);
    out.close();
    //read ppt from byte array
    HSLFSlideShow ppt2 = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
    assertEquals(1, ppt2.getSlides().size());
    slide = ppt2.getSlides().get(0);
    List<HSLFShape> shape = slide.getShapes();
    assertEquals(2, shape.size());
    //group shape
    assertTrue(shape.get(0) instanceof HSLFLine);
    //group shape
    assertEquals(lineAnchor, shape.get(0).getAnchor());
    //group shape
    assertTrue(shape.get(1) instanceof HSLFAutoShape);
    //group shape
    assertEquals(ellipseAnchor, shape.get(1).getAnchor());
    ppt2.close();
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFLine(org.apache.poi.hslf.usermodel.HSLFLine) HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) ByteArrayInputStream(java.io.ByteArrayInputStream) HSLFAutoShape(org.apache.poi.hslf.usermodel.HSLFAutoShape) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 15 with HSLFShape

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

the class TestBackground method defaults.

/**
     * Default background for slide, shape and slide master.
     */
@Test
public void defaults() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow();
    assertEquals(HSLFFill.FILL_SOLID, ppt.getSlideMasters().get(0).getBackground().getFill().getFillType());
    HSLFSlide slide = ppt.createSlide();
    assertTrue(slide.getFollowMasterBackground());
    assertEquals(HSLFFill.FILL_SOLID, slide.getBackground().getFill().getFillType());
    HSLFShape shape = new HSLFAutoShape(ShapeType.RECT);
    assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
    ppt.close();
}
Also used : HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSLFAutoShape(org.apache.poi.hslf.usermodel.HSLFAutoShape) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Aggregations

HSLFShape (org.apache.poi.hslf.usermodel.HSLFShape)20 HSLFSlide (org.apache.poi.hslf.usermodel.HSLFSlide)17 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)17 Test (org.junit.Test)12 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 HSLFTable (org.apache.poi.hslf.usermodel.HSLFTable)4 HSLFTextShape (org.apache.poi.hslf.usermodel.HSLFTextShape)4 FileInputStream (java.io.FileInputStream)3 HSLFAutoShape (org.apache.poi.hslf.usermodel.HSLFAutoShape)3 HSLFLine (org.apache.poi.hslf.usermodel.HSLFLine)3 HSLFObjectData (org.apache.poi.hslf.usermodel.HSLFObjectData)3 HSLFPictureData (org.apache.poi.hslf.usermodel.HSLFPictureData)3 HSLFTextRun (org.apache.poi.hslf.usermodel.HSLFTextRun)3 Rectangle2D (java.awt.geom.Rectangle2D)2 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 Comment (org.apache.poi.hslf.model.Comment)2 HeadersFooters (org.apache.poi.hslf.model.HeadersFooters)2 OLEShape (org.apache.poi.hslf.model.OLEShape)2