Search in sources :

Example 16 with EscherDgRecord

use of org.apache.poi.ddf.EscherDgRecord in project poi by apache.

the class TestDrawingManager2 method testCreateDgRecord.

public void testCreateDgRecord() {
    EscherDgRecord dgRecord1 = drawingManager2.createDgRecord();
    assertEquals(1, dgRecord1.getDrawingGroupId());
    assertEquals(-1, dgRecord1.getLastMSOSPID());
    EscherDgRecord dgRecord2 = drawingManager2.createDgRecord();
    assertEquals(2, dgRecord2.getDrawingGroupId());
    assertEquals(-1, dgRecord2.getLastMSOSPID());
    assertEquals(2, dgg.getDrawingsSaved());
    assertEquals(2, dgg.getFileIdClusters().length);
    assertEquals(3, dgg.getNumIdClusters());
    assertEquals(0, dgg.getNumShapesSaved());
}
Also used : EscherDgRecord(org.apache.poi.ddf.EscherDgRecord)

Example 17 with EscherDgRecord

use of org.apache.poi.ddf.EscherDgRecord in project poi by apache.

the class TestCloneSheet method testCloneSheetWithEmptyDrawingAggregate.

@Test
public void testCloneSheetWithEmptyDrawingAggregate() {
    HSSFWorkbook b = new HSSFWorkbook();
    HSSFSheet s = b.createSheet("Test");
    HSSFPatriarch patriarch = s.createDrawingPatriarch();
    EscherAggregate agg1 = patriarch.getBoundAggregate();
    HSSFSheet s2 = s.cloneSheet(b);
    patriarch = s2.getDrawingPatriarch();
    EscherAggregate agg2 = patriarch.getBoundAggregate();
    EscherSpRecord sp1 = (EscherSpRecord) agg1.getEscherContainer().getChild(1).getChild(0).getChild(1);
    EscherSpRecord sp2 = (EscherSpRecord) agg2.getEscherContainer().getChild(1).getChild(0).getChild(1);
    assertEquals(sp1.getShapeId(), 1024);
    assertEquals(sp2.getShapeId(), 2048);
    EscherDgRecord dg = (EscherDgRecord) agg2.getEscherContainer().getChild(0);
    assertEquals(dg.getLastMSOSPID(), 2048);
    assertEquals(dg.getInstance(), 0x2);
    //everything except id and DgRecord.lastMSOSPID and DgRecord.Instance must be the same
    sp2.setShapeId(1024);
    dg.setLastMSOSPID(1024);
    dg.setInstance((short) 0x1);
    assertEquals(agg1.serialize().length, agg2.serialize().length);
    assertEquals(agg1.toXml(""), agg2.toXml(""));
    assertArrayEquals(agg1.serialize(), agg2.serialize());
}
Also used : EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) Test(org.junit.Test)

Example 18 with EscherDgRecord

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

EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)18 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)7 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)5 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)5 EscherAggregate (org.apache.poi.hssf.record.EscherAggregate)3 Test (org.junit.Test)3 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)2 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)2 EscherSpgrRecord (org.apache.poi.ddf.EscherSpgrRecord)2 DrawingManager2 (org.apache.poi.hssf.model.DrawingManager2)2 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)1 EscherBoolProperty (org.apache.poi.ddf.EscherBoolProperty)1 EscherRGBProperty (org.apache.poi.ddf.EscherRGBProperty)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1 HSLFLine (org.apache.poi.hslf.usermodel.HSLFLine)1 HSLFShape (org.apache.poi.hslf.usermodel.HSLFShape)1 HSLFSlide (org.apache.poi.hslf.usermodel.HSLFSlide)1 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)1 RecordFormatException (org.apache.poi.util.RecordFormatException)1