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));
}
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());
}
}
}
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;
}
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;
}
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);
}
Aggregations