Search in sources :

Example 16 with EscherDggRecord

use of org.apache.poi.ddf.EscherDggRecord 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)

Aggregations

EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)16 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)7 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)7 EscherRecord (org.apache.poi.ddf.EscherRecord)6 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)3 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)3 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)3 EOFRecord (org.apache.poi.hssf.record.EOFRecord)3 EscherAggregate (org.apache.poi.hssf.record.EscherAggregate)3 Record (org.apache.poi.hssf.record.Record)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 EscherSplitMenuColorsRecord (org.apache.poi.ddf.EscherSplitMenuColorsRecord)2 ContinueRecord (org.apache.poi.hssf.record.ContinueRecord)2 DrawingGroupRecord (org.apache.poi.hssf.record.DrawingGroupRecord)2 DrawingRecord (org.apache.poi.hssf.record.DrawingRecord)2 RecordBase (org.apache.poi.hssf.record.RecordBase)2 EscherBoolProperty (org.apache.poi.ddf.EscherBoolProperty)1 EscherRGBProperty (org.apache.poi.ddf.EscherRGBProperty)1 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)1