Search in sources :

Example 26 with EscherSpRecord

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

the class HSSFSimpleShape method createSpContainer.

@Override
protected EscherContainerRecord createSpContainer() {
    EscherContainerRecord spContainer = new EscherContainerRecord();
    spContainer.setRecordId(EscherContainerRecord.SP_CONTAINER);
    spContainer.setOptions((short) 0x000F);
    EscherSpRecord sp = new EscherSpRecord();
    sp.setRecordId(EscherSpRecord.RECORD_ID);
    sp.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE);
    sp.setVersion((short) 0x2);
    EscherClientDataRecord clientData = new EscherClientDataRecord();
    clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
    clientData.setOptions((short) (0x0000));
    EscherOptRecord optRecord = new EscherOptRecord();
    optRecord.setEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, LINESTYLE_SOLID));
    optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
    //        optRecord.setEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, LINEWIDTH_DEFAULT));
    optRecord.setEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, FILL__FILLCOLOR_DEFAULT));
    optRecord.setEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, LINESTYLE__COLOR_DEFAULT));
    optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, NO_FILLHITTEST_FALSE));
    optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
    optRecord.setEscherProperty(new EscherShapePathProperty(EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX));
    optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x080000));
    optRecord.setRecordId(EscherOptRecord.RECORD_ID);
    EscherTextboxRecord escherTextbox = new EscherTextboxRecord();
    escherTextbox.setRecordId(EscherTextboxRecord.RECORD_ID);
    escherTextbox.setOptions((short) 0x0000);
    spContainer.addChildRecord(sp);
    spContainer.addChildRecord(optRecord);
    spContainer.addChildRecord(getAnchor().getEscherAnchor());
    spContainer.addChildRecord(clientData);
    spContainer.addChildRecord(escherTextbox);
    return spContainer;
}
Also used : EscherBoolProperty(org.apache.poi.ddf.EscherBoolProperty) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) EscherClientDataRecord(org.apache.poi.ddf.EscherClientDataRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherShapePathProperty(org.apache.poi.ddf.EscherShapePathProperty) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherRGBProperty(org.apache.poi.ddf.EscherRGBProperty)

Example 27 with EscherSpRecord

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

the class TestDrawingGroupRecord method testGetRecordSize.

public void testGetRecordSize() {
    DrawingGroupRecord r = new DrawingGroupRecord();
    assertEquals(4, r.getRecordSize());
    EscherSpRecord sp = new EscherSpRecord();
    sp.setRecordId(EscherSpRecord.RECORD_ID);
    sp.setOptions((short) 0x1111);
    sp.setFlags(-1);
    sp.setShapeId(-1);
    EscherContainerRecord dggContainer = new EscherContainerRecord();
    dggContainer.setOptions((short) 0x000F);
    dggContainer.setRecordId((short) 0xF000);
    dggContainer.addChildRecord(sp);
    r.addEscherRecord(dggContainer);
    assertEquals(28, r.getRecordSize());
    byte[] data = new byte[28];
    int size = r.serialize(0, data);
    assertEquals("[EB, 00, 18, 00, 0F, 00, 00, F0, 10, 00, 00, 00, 11, 11, 0A, F0, 08, 00, 00, 00, FF, FF, FF, FF, FF, FF, FF, FF]", HexDump.toHex(data));
    assertEquals(28, size);
    assertEquals(24, dggContainer.getRecordSize());
    r = new DrawingGroupRecord();
    r.setRawData(new byte[MAX_DATA_SIZE]);
    assertEquals(MAX_RECORD_SIZE, r.getRecordSize());
    r.setRawData(new byte[MAX_DATA_SIZE + 1]);
    assertEquals(MAX_RECORD_SIZE + 5, r.getRecordSize());
    r.setRawData(new byte[MAX_DATA_SIZE * 2]);
    assertEquals(MAX_RECORD_SIZE * 2, r.getRecordSize());
    r.setRawData(new byte[MAX_DATA_SIZE * 2 + 1]);
    assertEquals(MAX_RECORD_SIZE * 2 + 5, r.getRecordSize());
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord)

Example 28 with EscherSpRecord

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

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

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

the class PPDrawing method findInDgContainer.

private EscherTextboxWrapper[] findInDgContainer(final EscherContainerRecord dgContainer) {
    final List<EscherTextboxWrapper> found = new LinkedList<EscherTextboxWrapper>();
    final EscherContainerRecord spgrContainer = findFirstEscherContainerRecordOfType(RecordTypes.EscherSpgrContainer, dgContainer);
    final EscherContainerRecord[] spContainers = findAllEscherContainerRecordOfType(RecordTypes.EscherSpContainer, spgrContainer);
    for (EscherContainerRecord spContainer : spContainers) {
        EscherSpRecord sp = (EscherSpRecord) findFirstEscherRecordOfType(RecordTypes.EscherSp, spContainer);
        EscherTextboxRecord clientTextbox = (EscherTextboxRecord) findFirstEscherRecordOfType(RecordTypes.EscherClientTextbox, spContainer);
        if (null == clientTextbox) {
            continue;
        }
        EscherTextboxWrapper w = new EscherTextboxWrapper(clientTextbox);
        StyleTextProp9Atom nineAtom = findInSpContainer(spContainer);
        w.setStyleTextProp9Atom(nineAtom);
        if (null != sp) {
            w.setShapeId(sp.getShapeId());
        }
        found.add(w);
    }
    return found.toArray(new EscherTextboxWrapper[found.size()]);
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) LinkedList(java.util.LinkedList)

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