Search in sources :

Example 1 with HSLFLine

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

the class TestShapes method shapeId.

@Test
public void shapeId() throws IOException {
    HSLFSlideShow ss = new HSLFSlideShow();
    HSLFSlide slide = ss.createSlide();
    HSLFShape shape = null;
    //EscherDgg is a document-level record which keeps track of the drawing groups
    EscherDggRecord dgg = ss.getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
    EscherDgRecord dg = slide.getSheetContainer().getPPDrawing().getEscherDgRecord();
    //total number of shapes in the ppt
    int dggShapesUsed = dgg.getNumShapesSaved();
    //max number of shapeId
    int dggMaxId = dgg.getShapeIdMax();
    //max shapeId in the slide
    int dgMaxId = dg.getLastMSOSPID();
    // number of shapes in the slide
    int dgShapesUsed = dg.getNumShapes();
    //insert 3 shapes and make sure the Ids are properly incremented
    for (int i = 0; i < 3; i++) {
        shape = new HSLFLine();
        assertEquals(0, shape.getShapeId());
        slide.addShape(shape);
        assertTrue(shape.getShapeId() > 0);
        //check that EscherDgRecord is updated
        assertEquals(shape.getShapeId(), dg.getLastMSOSPID());
        assertEquals(dgMaxId + 1, dg.getLastMSOSPID());
        assertEquals(dgShapesUsed + 1, dg.getNumShapes());
        //check that EscherDggRecord is updated
        assertEquals(shape.getShapeId() + 1, dgg.getShapeIdMax());
        assertEquals(dggMaxId + 1, dgg.getShapeIdMax());
        assertEquals(dggShapesUsed + 1, dgg.getNumShapesSaved());
        dggShapesUsed = dgg.getNumShapesSaved();
        dggMaxId = dgg.getShapeIdMax();
        dgMaxId = dg.getLastMSOSPID();
        dgShapesUsed = dg.getNumShapes();
    }
    //For each drawing group PPT allocates clusters with size=1024
    //if the number of shapes is greater that 1024 a new cluster is allocated
    //make sure it is so
    int numClusters = dgg.getNumIdClusters();
    for (int i = 0; i < 1025; i++) {
        shape = new HSLFLine();
        slide.addShape(shape);
    }
    assertEquals(numClusters + 1, dgg.getNumIdClusters());
    ss.close();
}
Also used : HSLFLine(org.apache.poi.hslf.usermodel.HSLFLine) HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 2 with HSLFLine

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

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

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

the class TestLine method testCreateLines.

@Test
public void testCreateLines() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow();
    HSLFSlide slide = ppt.createSlide();
    slide.addTitle().setText("Lines tester");
    HSLFLine line;
    /**
         * line styles
         */
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 200, 300, 0));
    line.setLineCompound(LineCompound.SINGLE);
    line.setLineColor(Color.blue);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 230, 300, 0));
    line.setLineCompound(LineCompound.DOUBLE);
    line.setLineWidth(3.5);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 260, 300, 0));
    line.setLineCompound(LineCompound.TRIPLE);
    line.setLineWidth(6);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 290, 300, 0));
    line.setLineCompound(LineCompound.THICK_THIN);
    line.setLineWidth(4.5);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 320, 300, 0));
    line.setLineCompound(LineCompound.THIN_THICK);
    line.setLineWidth(5.5);
    slide.addShape(line);
    /**
         * line dashing
         */
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(450, 200, 300, 0));
    line.setLineDash(LineDash.SOLID);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(450, 230, 300, 0));
    line.setLineDash(LineDash.DASH);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(450, 260, 300, 0));
    line.setLineDash(LineDash.DOT);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(450, 290, 300, 0));
    line.setLineDash(LineDash.DASH_DOT);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(450, 320, 300, 0));
    line.setLineDash(LineDash.LG_DASH_DOT_DOT);
    slide.addShape(line);
    /**
         * Combinations
         */
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 400, 300, 0));
    line.setLineDash(LineDash.DASH_DOT);
    line.setLineCompound(LineCompound.TRIPLE);
    line.setLineWidth(5.0);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 430, 300, 0));
    line.setLineDash(LineDash.DASH);
    line.setLineCompound(LineCompound.THICK_THIN);
    line.setLineWidth(4.0);
    slide.addShape(line);
    line = new HSLFLine();
    line.setAnchor(new java.awt.Rectangle(75, 460, 300, 0));
    line.setLineDash(LineDash.DOT);
    line.setLineCompound(LineCompound.DOUBLE);
    line.setLineWidth(8.0);
    slide.addShape(line);
    ppt.close();
}
Also used : HSLFLine(org.apache.poi.hslf.usermodel.HSLFLine) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Aggregations

HSLFLine (org.apache.poi.hslf.usermodel.HSLFLine)4 HSLFSlide (org.apache.poi.hslf.usermodel.HSLFSlide)4 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)4 Test (org.junit.Test)4 HSLFShape (org.apache.poi.hslf.usermodel.HSLFShape)3 Rectangle2D (java.awt.geom.Rectangle2D)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Dimension (java.awt.Dimension)1 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)1 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)1 HSLFAutoShape (org.apache.poi.hslf.usermodel.HSLFAutoShape)1 HSLFGroupShape (org.apache.poi.hslf.usermodel.HSLFGroupShape)1 HSLFPictureData (org.apache.poi.hslf.usermodel.HSLFPictureData)1 HSLFPictureShape (org.apache.poi.hslf.usermodel.HSLFPictureShape)1