Search in sources :

Example 6 with EscherDgRecord

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

the class TestPatriarch method testGetPatriarch.

public void testGetPatriarch() {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sh = wb.createSheet();
    assertNull(sh.getDrawingPatriarch());
    HSSFPatriarch patriarch = sh.createDrawingPatriarch();
    assertNotNull(patriarch);
    patriarch.createSimpleShape(new HSSFClientAnchor());
    patriarch.createSimpleShape(new HSSFClientAnchor());
    assertSame(patriarch, sh.getDrawingPatriarch());
    EscherAggregate agg = patriarch.getBoundAggregate();
    EscherDgRecord dg = agg.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
    int lastId = dg.getLastMSOSPID();
    assertSame(patriarch, sh.createDrawingPatriarch());
    wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
    sh = wb.getSheetAt(0);
    patriarch = sh.createDrawingPatriarch();
    dg = patriarch.getBoundAggregate().getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
    assertEquals(lastId, dg.getLastMSOSPID());
}
Also used : EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord)

Example 7 with EscherDgRecord

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

the class HSLFSheet method allocateShapeId.

/**
     * Allocates new shape id for the new drawing group id.
     *
     * @return a new shape id.
     */
public int allocateShapeId() {
    EscherDggRecord dgg = _slideShow.getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
    EscherDgRecord dg = _container.getPPDrawing().getEscherDgRecord();
    dgg.setNumShapesSaved(dgg.getNumShapesSaved() + 1);
    // Add to existing cluster if space available
    for (int i = 0; i < dgg.getFileIdClusters().length; i++) {
        EscherDggRecord.FileIdCluster c = dgg.getFileIdClusters()[i];
        if (c.getDrawingGroupId() == dg.getDrawingGroupId() && c.getNumShapeIdsUsed() != 1024) {
            int result = c.getNumShapeIdsUsed() + (1024 * (i + 1));
            c.incrementShapeId();
            dg.setNumShapes(dg.getNumShapes() + 1);
            dg.setLastMSOSPID(result);
            if (result >= dgg.getShapeIdMax()) {
                dgg.setShapeIdMax(result + 1);
            }
            return result;
        }
    }
    // Create new cluster
    dgg.addCluster(dg.getDrawingGroupId(), 0, false);
    dgg.getFileIdClusters()[dgg.getFileIdClusters().length - 1].incrementShapeId();
    dg.setNumShapes(dg.getNumShapes() + 1);
    int result = (1024 * dgg.getFileIdClusters().length);
    dg.setLastMSOSPID(result);
    if (result >= dgg.getShapeIdMax()) {
        dgg.setShapeIdMax(result + 1);
    }
    return result;
}
Also used : EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord)

Example 8 with EscherDgRecord

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

the class TestDrawingManager2 method testAllocateShapeId.

public void testAllocateShapeId() {
    EscherDgRecord dgRecord1 = drawingManager2.createDgRecord();
    EscherDgRecord dgRecord2 = drawingManager2.createDgRecord();
    assertEquals(1024, drawingManager2.allocateShapeId((short) 1));
    assertEquals(1024, dgRecord1.getLastMSOSPID());
    assertEquals(1025, dgg.getShapeIdMax());
    assertEquals(1025, drawingManager2.allocateShapeId((short) 1));
    assertEquals(1025, dgRecord1.getLastMSOSPID());
    assertEquals(1026, dgg.getShapeIdMax());
    assertEquals(1026, drawingManager2.allocateShapeId((short) 1));
    assertEquals(1026, dgRecord1.getLastMSOSPID());
    assertEquals(1027, dgg.getShapeIdMax());
    assertEquals(2048, drawingManager2.allocateShapeId((short) 2));
    assertEquals(2048, dgRecord2.getLastMSOSPID());
    assertEquals(2049, dgg.getShapeIdMax());
    for (int i = 0; i < 1021; i++) {
        drawingManager2.allocateShapeId((short) 1);
        assertEquals(2049, dgg.getShapeIdMax());
    }
    assertEquals(3072, drawingManager2.allocateShapeId((short) 1));
    assertEquals(3073, dgg.getShapeIdMax());
    assertEquals(2, dgg.getDrawingsSaved());
    assertEquals(4, dgg.getNumIdClusters());
    assertEquals(1026, dgg.getNumShapesSaved());
}
Also used : EscherDgRecord(org.apache.poi.ddf.EscherDgRecord)

Example 9 with EscherDgRecord

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

the class TestHSSFSheet method cloneSheetWithDrawings.

/**
     * If we clone a sheet containing drawings,
     * we must allocate a new ID of the drawing group and re-create shape IDs
     *
     * See bug #45720.
     */
@Test
public void cloneSheetWithDrawings() throws IOException {
    HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("45720.xls");
    HSSFSheet sheet1 = wb1.getSheetAt(0);
    wb1.getWorkbook().findDrawingGroup();
    DrawingManager2 dm1 = wb1.getWorkbook().getDrawingManager();
    wb1.cloneSheet(0);
    HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    wb2.getWorkbook().findDrawingGroup();
    DrawingManager2 dm2 = wb2.getWorkbook().getDrawingManager();
    //check EscherDggRecord - a workbook-level registry of drawing objects
    assertEquals(dm1.getDgg().getMaxDrawingGroupId() + 1, dm2.getDgg().getMaxDrawingGroupId());
    HSSFSheet sheet2 = wb2.getSheetAt(1);
    //check that id of the drawing group was updated
    EscherDgRecord dg1 = (EscherDgRecord) sheet1.getDrawingPatriarch().getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
    EscherDgRecord dg2 = (EscherDgRecord) sheet2.getDrawingPatriarch().getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
    int dg_id_1 = dg1.getOptions() >> 4;
    int dg_id_2 = dg2.getOptions() >> 4;
    assertEquals(dg_id_1 + 1, dg_id_2);
    //TODO: check shapeId in the cloned sheet
    wb2.close();
}
Also used : EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) DrawingManager2(org.apache.poi.hssf.model.DrawingManager2) Test(org.junit.Test)

Example 10 with EscherDgRecord

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

the class EscherAggregate method buildBaseTree.

/**
     * create base tree with such structure:
     * EscherDgContainer
     * -EscherSpgrContainer
     * --EscherSpContainer
     * ---EscherSpRecord
     * ---EscherSpgrRecord
     * ---EscherSpRecord
     * -EscherDgRecord
     *
     * id of DgRecord and SpRecord are empty and must be set later by HSSFPatriarch
     */
private void buildBaseTree() {
    EscherContainerRecord dgContainer = new EscherContainerRecord();
    EscherContainerRecord spgrContainer = new EscherContainerRecord();
    EscherContainerRecord spContainer1 = new EscherContainerRecord();
    EscherSpgrRecord spgr = new EscherSpgrRecord();
    EscherSpRecord sp1 = new EscherSpRecord();
    dgContainer.setRecordId(EscherContainerRecord.DG_CONTAINER);
    dgContainer.setOptions((short) 0x000F);
    EscherDgRecord dg = new EscherDgRecord();
    dg.setRecordId(EscherDgRecord.RECORD_ID);
    short dgId = 1;
    dg.setOptions((short) (dgId << 4));
    dg.setNumShapes(0);
    dg.setLastMSOSPID(1024);
    spgrContainer.setRecordId(EscherContainerRecord.SPGR_CONTAINER);
    spgrContainer.setOptions((short) 0x000F);
    spContainer1.setRecordId(EscherContainerRecord.SP_CONTAINER);
    spContainer1.setOptions((short) 0x000F);
    spgr.setRecordId(EscherSpgrRecord.RECORD_ID);
    // version
    spgr.setOptions((short) 0x0001);
    spgr.setRectX1(0);
    spgr.setRectY1(0);
    spgr.setRectX2(1023);
    spgr.setRectY2(255);
    sp1.setRecordId(EscherSpRecord.RECORD_ID);
    sp1.setOptions((short) 0x0002);
    sp1.setVersion((short) 0x2);
    sp1.setShapeId(-1);
    sp1.setFlags(EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_PATRIARCH);
    dgContainer.addChildRecord(dg);
    dgContainer.addChildRecord(spgrContainer);
    spgrContainer.addChildRecord(spContainer1);
    spContainer1.addChildRecord(spgr);
    spContainer1.addChildRecord(sp1);
    addEscherRecord(dgContainer);
}
Also used : EscherSpgrRecord(org.apache.poi.ddf.EscherSpgrRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord)

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