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