Search in sources :

Example 16 with EscherSpRecord

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

Example 17 with EscherSpRecord

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

the class InternalWorkbook method cloneDrawings.

/**
     * Check if the cloned sheet has drawings. If yes, then allocate a new drawing group ID and
     * re-generate shape IDs
     *
     * @param sheet the cloned sheet
     */
public void cloneDrawings(InternalSheet sheet) {
    findDrawingGroup();
    if (drawingManager == null) {
        //this workbook does not have drawings
        return;
    }
    //check if the cloned sheet has drawings
    int aggLoc = sheet.aggregateDrawingRecords(drawingManager, false);
    if (aggLoc == -1) {
        return;
    }
    EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
    EscherContainerRecord escherContainer = agg.getEscherContainer();
    if (escherContainer == null) {
        return;
    }
    EscherDggRecord dgg = drawingManager.getDgg();
    //register a new drawing group for the cloned sheet
    int dgId = drawingManager.findNewDrawingGroupId();
    dgg.addCluster(dgId, 0);
    dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
    EscherDgRecord dg = null;
    for (EscherRecord er : escherContainer) {
        if (er instanceof EscherDgRecord) {
            dg = (EscherDgRecord) er;
            //update id of the drawing in the cloned sheet
            dg.setOptions((short) (dgId << 4));
        } else if (er instanceof EscherContainerRecord) {
            // iterate over shapes and re-generate shapeId
            for (EscherRecord er2 : (EscherContainerRecord) er) {
                for (EscherRecord shapeChildRecord : (EscherContainerRecord) er2) {
                    int recordId = shapeChildRecord.getRecordId();
                    if (recordId == EscherSpRecord.RECORD_ID) {
                        if (dg == null) {
                            throw new RecordFormatException("EscherDgRecord wasn't set/processed before.");
                        }
                        EscherSpRecord sp = (EscherSpRecord) shapeChildRecord;
                        int shapeId = drawingManager.allocateShapeId((short) dgId, dg);
                        //allocateShapeId increments the number of shapes. roll back to the previous value
                        dg.setNumShapes(dg.getNumShapes() - 1);
                        sp.setShapeId(shapeId);
                    } else if (recordId == EscherOptRecord.RECORD_ID) {
                        EscherOptRecord opt = (EscherOptRecord) shapeChildRecord;
                        EscherSimpleProperty prop = (EscherSimpleProperty) opt.lookup(EscherProperties.BLIP__BLIPTODISPLAY);
                        if (prop != null) {
                            int pictureIndex = prop.getPropertyValue();
                            // increment reference count for pictures
                            EscherBSERecord bse = getBSERecord(pictureIndex);
                            bse.setRef(bse.getRef() + 1);
                        }
                    }
                }
            }
        }
    }
}
Also used : EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) RecordFormatException(org.apache.poi.util.RecordFormatException) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 18 with EscherSpRecord

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

the class HSLFGroupShape method getShapeType.

/**
     * Return type of the shape.
     * In most cases shape group type is {@link org.apache.poi.sl.usermodel.ShapeType#NOT_PRIMITIVE}
     *
     * @return type of the shape.
     */
@Override
public ShapeType getShapeType() {
    EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
    int nativeId = spRecord.getOptions() >> 4;
    return ShapeType.forId(nativeId, false);
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord)

Example 19 with EscherSpRecord

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

the class HSLFShape method setAnchor.

/**
     * Sets the anchor (the bounding box rectangle) of this shape.
     * All coordinates should be expressed in points (72 dpi).
     *
     * @param anchor new anchor
     */
public void setAnchor(Rectangle2D anchor) {
    int x = Units.pointsToMaster(anchor.getX());
    int y = Units.pointsToMaster(anchor.getY());
    int w = Units.pointsToMaster(anchor.getWidth() + anchor.getX());
    int h = Units.pointsToMaster(anchor.getHeight() + anchor.getY());
    EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
    int flags = spRecord.getFlags();
    if ((flags & EscherSpRecord.FLAG_CHILD) != 0) {
        EscherChildAnchorRecord rec = (EscherChildAnchorRecord) getEscherChild(EscherChildAnchorRecord.RECORD_ID);
        rec.setDx1(x);
        rec.setDy1(y);
        rec.setDx2(w);
        rec.setDy2(h);
    } else {
        EscherClientAnchorRecord rec = (EscherClientAnchorRecord) getEscherChild(EscherClientAnchorRecord.RECORD_ID);
        rec.setCol1((short) x);
        rec.setFlag((short) y);
        rec.setDx1((short) w);
        rec.setRow1((short) h);
    }
}
Also used : EscherChildAnchorRecord(org.apache.poi.ddf.EscherChildAnchorRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord)

Example 20 with EscherSpRecord

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

the class HSLFShape method setShapeType.

public void setShapeType(ShapeType type) {
    EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
    spRecord.setShapeType((short) type.nativeId);
    spRecord.setVersion((short) 0x2);
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord)

Aggregations

EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)31 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)17 EscherClientAnchorRecord (org.apache.poi.ddf.EscherClientAnchorRecord)5 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)5 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)5 CommonObjectDataSubRecord (org.apache.poi.hssf.record.CommonObjectDataSubRecord)5 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)4 EscherChildAnchorRecord (org.apache.poi.ddf.EscherChildAnchorRecord)4 EscherRecord (org.apache.poi.ddf.EscherRecord)4 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)4 Test (org.junit.Test)4 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)3 EscherSpgrRecord (org.apache.poi.ddf.EscherSpgrRecord)3 HSLFEscherClientDataRecord (org.apache.poi.hslf.record.HSLFEscherClientDataRecord)3 EscherBoolProperty (org.apache.poi.ddf.EscherBoolProperty)2 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)2 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)2 EscherRGBProperty (org.apache.poi.ddf.EscherRGBProperty)2 ExObjRefAtom (org.apache.poi.hslf.record.ExObjRefAtom)2 Record (org.apache.poi.hslf.record.Record)2