Search in sources :

Example 46 with EscherContainerRecord

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

the class TestEscherAggregate method testSerialize.

public void testSerialize() {
    EscherContainerRecord container1 = new EscherContainerRecord();
    EscherContainerRecord spContainer1 = new EscherContainerRecord();
    EscherContainerRecord spContainer2 = new EscherContainerRecord();
    EscherContainerRecord spContainer3 = new EscherContainerRecord();
    EscherSpRecord sp1 = new EscherSpRecord();
    EscherSpRecord sp2 = new EscherSpRecord();
    EscherSpRecord sp3 = new EscherSpRecord();
    EscherClientDataRecord d2 = new EscherClientDataRecord();
    EscherClientDataRecord d3 = new EscherClientDataRecord();
    container1.setOptions((short) 0x000F);
    spContainer1.setOptions((short) 0x000F);
    spContainer1.setRecordId(EscherContainerRecord.SP_CONTAINER);
    spContainer2.setOptions((short) 0x000F);
    spContainer2.setRecordId(EscherContainerRecord.SP_CONTAINER);
    spContainer3.setOptions((short) 0x000F);
    spContainer3.setRecordId(EscherContainerRecord.SP_CONTAINER);
    d2.setRecordId(EscherClientDataRecord.RECORD_ID);
    d2.setRemainingData(new byte[0]);
    d3.setRecordId(EscherClientDataRecord.RECORD_ID);
    d3.setRemainingData(new byte[0]);
    container1.addChildRecord(spContainer1);
    container1.addChildRecord(spContainer2);
    container1.addChildRecord(spContainer3);
    spContainer1.addChildRecord(sp1);
    spContainer2.addChildRecord(sp2);
    spContainer3.addChildRecord(sp3);
    spContainer2.addChildRecord(d2);
    spContainer3.addChildRecord(d3);
    EscherAggregate aggregate = new EscherAggregate(false);
    aggregate.addEscherRecord(container1);
    aggregate.associateShapeToObjRecord(d2, new ObjRecord());
    aggregate.associateShapeToObjRecord(d3, new ObjRecord());
    byte[] data = new byte[112];
    int bytesWritten = aggregate.serialize(0, data);
    assertEquals(112, bytesWritten);
    assertEquals("[EC, 00, 40, 00, 0F, 00, 00, 00, 58, 00, 00, 00, 0F, 00, 04, F0, 10, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00, EC, 00, 20, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00]", HexDump.toHex(data));
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherClientDataRecord(org.apache.poi.ddf.EscherClientDataRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord)

Example 47 with EscherContainerRecord

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

the class HSSFPatriarch method buildShapeTree.

/**
     * create shape tree from existing escher records tree
     */
void buildShapeTree() {
    EscherContainerRecord dgContainer = _boundAggregate.getEscherContainer();
    if (dgContainer == null) {
        return;
    }
    EscherContainerRecord spgrConrainer = dgContainer.getChildContainers().get(0);
    List<EscherContainerRecord> spgrChildren = spgrConrainer.getChildContainers();
    for (int i = 0; i < spgrChildren.size(); i++) {
        EscherContainerRecord spContainer = spgrChildren.get(i);
        if (i != 0) {
            HSSFShapeFactory.createShapeTree(spContainer, _boundAggregate, this, _sheet.getWorkbook().getDirectory());
        }
    }
}
Also used : EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord)

Example 48 with EscherContainerRecord

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

the class HSSFPatriarch method createObjectData.

@Override
public HSSFObjectData createObjectData(ClientAnchor anchor, int storageId, int pictureIndex) {
    ObjRecord obj = new ObjRecord();
    CommonObjectDataSubRecord ftCmo = new CommonObjectDataSubRecord();
    ftCmo.setObjectType(CommonObjectDataSubRecord.OBJECT_TYPE_PICTURE);
    // ftCmo.setObjectId(oleShape.getShapeId()); ... will be set by onCreate(...)
    ftCmo.setLocked(true);
    ftCmo.setPrintable(true);
    ftCmo.setAutofill(true);
    ftCmo.setAutoline(true);
    ftCmo.setReserved1(0);
    ftCmo.setReserved2(0);
    ftCmo.setReserved3(0);
    obj.addSubRecord(ftCmo);
    // FtCf (pictFormat) 
    FtCfSubRecord ftCf = new FtCfSubRecord();
    HSSFPictureData pictData = getSheet().getWorkbook().getAllPictures().get(pictureIndex - 1);
    switch(pictData.getFormat()) {
        case Workbook.PICTURE_TYPE_WMF:
        case Workbook.PICTURE_TYPE_EMF:
            // this needs patch #49658 to be applied to actually work 
            ftCf.setFlags(FtCfSubRecord.METAFILE_BIT);
            break;
        case Workbook.PICTURE_TYPE_DIB:
        case Workbook.PICTURE_TYPE_PNG:
        case Workbook.PICTURE_TYPE_JPEG:
        case Workbook.PICTURE_TYPE_PICT:
            ftCf.setFlags(FtCfSubRecord.BITMAP_BIT);
            break;
        default:
            throw new IllegalStateException("Invalid picture type: " + pictData.getFormat());
    }
    obj.addSubRecord(ftCf);
    // FtPioGrbit (pictFlags)
    FtPioGrbitSubRecord ftPioGrbit = new FtPioGrbitSubRecord();
    ftPioGrbit.setFlagByBit(FtPioGrbitSubRecord.AUTO_PICT_BIT, true);
    obj.addSubRecord(ftPioGrbit);
    EmbeddedObjectRefSubRecord ftPictFmla = new EmbeddedObjectRefSubRecord();
    ftPictFmla.setUnknownFormulaData(new byte[] { 2, 0, 0, 0, 0 });
    ftPictFmla.setOleClassname("Paket");
    ftPictFmla.setStorageId(storageId);
    obj.addSubRecord(ftPictFmla);
    obj.addSubRecord(new EndSubRecord());
    String entryName = "MBD" + HexDump.toHex(storageId);
    DirectoryEntry oleRoot;
    try {
        DirectoryNode dn = _sheet.getWorkbook().getDirectory();
        if (dn == null) {
            throw new FileNotFoundException();
        }
        oleRoot = (DirectoryEntry) dn.getEntry(entryName);
    } catch (FileNotFoundException e) {
        throw new IllegalStateException("trying to add ole shape without actually adding data first - use HSSFWorkbook.addOlePackage first", e);
    }
    // create picture shape, which need to be minimal modified for oleshapes
    HSSFPicture shape = new HSSFPicture(null, (HSSFClientAnchor) anchor);
    shape.setPictureIndex(pictureIndex);
    EscherContainerRecord spContainer = shape.getEscherContainer();
    EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
    spRecord.setFlags(spRecord.getFlags() | EscherSpRecord.FLAG_OLESHAPE);
    HSSFObjectData oleShape = new HSSFObjectData(spContainer, obj, oleRoot);
    addShape(oleShape);
    onCreate(oleShape);
    return oleShape;
}
Also used : FtPioGrbitSubRecord(org.apache.poi.hssf.record.FtPioGrbitSubRecord) EmbeddedObjectRefSubRecord(org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord) CommonObjectDataSubRecord(org.apache.poi.hssf.record.CommonObjectDataSubRecord) EndSubRecord(org.apache.poi.hssf.record.EndSubRecord) FileNotFoundException(java.io.FileNotFoundException) DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode) DirectoryEntry(org.apache.poi.poifs.filesystem.DirectoryEntry) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) FtCfSubRecord(org.apache.poi.hssf.record.FtCfSubRecord) ObjRecord(org.apache.poi.hssf.record.ObjRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord)

Example 49 with EscherContainerRecord

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

the class HSSFComment method createSpContainer.

@Override
protected EscherContainerRecord createSpContainer() {
    EscherContainerRecord spContainer = super.createSpContainer();
    EscherOptRecord opt = spContainer.getChildById(EscherOptRecord.RECORD_ID);
    opt.removeEscherProperty(EscherProperties.TEXT__TEXTLEFT);
    opt.removeEscherProperty(EscherProperties.TEXT__TEXTRIGHT);
    opt.removeEscherProperty(EscherProperties.TEXT__TEXTTOP);
    opt.removeEscherProperty(EscherProperties.TEXT__TEXTBOTTOM);
    opt.setEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, false, false, GROUP_SHAPE_PROPERTY_DEFAULT_VALUE));
    return spContainer;
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord)

Example 50 with EscherContainerRecord

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

the class HSSFSimpleShape method cloneShape.

@Override
protected HSSFShape cloneShape() {
    TextObjectRecord txo = null;
    EscherContainerRecord spContainer = new EscherContainerRecord();
    byte[] inSp = getEscherContainer().serialize();
    spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());
    ObjRecord obj = (ObjRecord) getObjRecord().cloneViaReserialise();
    if (getTextObjectRecord() != null && getString() != null && null != getString().getString()) {
        txo = (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
    }
    return new HSSFSimpleShape(spContainer, obj, txo);
}
Also used : TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) ObjRecord(org.apache.poi.hssf.record.ObjRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory)

Aggregations

EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)53 EscherRecord (org.apache.poi.ddf.EscherRecord)17 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)17 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)11 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)8 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)8 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)6 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)6 DefaultEscherRecordFactory (org.apache.poi.ddf.DefaultEscherRecordFactory)5 ObjRecord (org.apache.poi.hssf.record.ObjRecord)5 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)4 EscherSpgrRecord (org.apache.poi.ddf.EscherSpgrRecord)4 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)4 Document (org.apache.poi.hslf.record.Document)4 PPDrawing (org.apache.poi.hslf.record.PPDrawing)4 LinkedList (java.util.LinkedList)3 EscherBoolProperty (org.apache.poi.ddf.EscherBoolProperty)3 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)3 EscherRGBProperty (org.apache.poi.ddf.EscherRGBProperty)3 ExObjRefAtom (org.apache.poi.hslf.record.ExObjRefAtom)3