use of org.apache.poi.ddf.EscherContainerRecord 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);
}
use of org.apache.poi.ddf.EscherContainerRecord in project poi by apache.
the class InternalWorkbook method createDrawingGroup.
/**
* Creates a primary drawing group record. If it already
* exists then it's modified.
*/
public void createDrawingGroup() {
if (drawingManager == null) {
EscherContainerRecord dggContainer = new EscherContainerRecord();
EscherDggRecord dgg = new EscherDggRecord();
EscherOptRecord opt = new EscherOptRecord();
EscherSplitMenuColorsRecord splitMenuColors = new EscherSplitMenuColorsRecord();
dggContainer.setRecordId((short) 0xF000);
dggContainer.setOptions((short) 0x000F);
dgg.setRecordId(EscherDggRecord.RECORD_ID);
dgg.setOptions((short) 0x0000);
dgg.setShapeIdMax(1024);
dgg.setNumShapesSaved(0);
dgg.setDrawingsSaved(0);
dgg.setFileIdClusters(new EscherDggRecord.FileIdCluster[] {});
drawingManager = new DrawingManager2(dgg);
EscherContainerRecord bstoreContainer = null;
if (!escherBSERecords.isEmpty()) {
bstoreContainer = new EscherContainerRecord();
bstoreContainer.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);
bstoreContainer.setOptions((short) ((escherBSERecords.size() << 4) | 0xF));
for (EscherRecord escherRecord : escherBSERecords) {
bstoreContainer.addChildRecord(escherRecord);
}
}
opt.setRecordId((short) 0xF00B);
opt.setOptions((short) 0x0033);
opt.addEscherProperty(new EscherBoolProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 524296));
opt.addEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, 0x08000041));
opt.addEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, 134217792));
splitMenuColors.setRecordId((short) 0xF11E);
splitMenuColors.setOptions((short) 0x0040);
splitMenuColors.setColor1(0x0800000D);
splitMenuColors.setColor2(0x0800000C);
splitMenuColors.setColor3(0x08000017);
splitMenuColors.setColor4(0x100000F7);
dggContainer.addChildRecord(dgg);
if (bstoreContainer != null) {
dggContainer.addChildRecord(bstoreContainer);
}
dggContainer.addChildRecord(opt);
dggContainer.addChildRecord(splitMenuColors);
int dgLoc = findFirstRecordLocBySid(DrawingGroupRecord.sid);
if (dgLoc == -1) {
DrawingGroupRecord drawingGroup = new DrawingGroupRecord();
drawingGroup.addEscherRecord(dggContainer);
int loc = findFirstRecordLocBySid(CountryRecord.sid);
getRecords().add(loc + 1, drawingGroup);
} else {
DrawingGroupRecord drawingGroup = new DrawingGroupRecord();
drawingGroup.addEscherRecord(dggContainer);
getRecords().set(dgLoc, drawingGroup);
}
}
}
use of org.apache.poi.ddf.EscherContainerRecord 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);
}
}
}
}
}
}
}
use of org.apache.poi.ddf.EscherContainerRecord in project poi by apache.
the class InternalWorkbook method findDrawingManager.
private static DrawingManager2 findDrawingManager(DrawingGroupRecord dg, List<EscherBSERecord> escherBSERecords) {
if (dg == null) {
return null;
}
// If there is one, does it have a EscherDggRecord?
EscherContainerRecord cr = dg.getEscherContainer();
if (cr == null) {
return null;
}
EscherDggRecord dgg = null;
EscherContainerRecord bStore = null;
for (EscherRecord er : cr) {
if (er instanceof EscherDggRecord) {
dgg = (EscherDggRecord) er;
} else if (er.getRecordId() == EscherContainerRecord.BSTORE_CONTAINER) {
bStore = (EscherContainerRecord) er;
}
}
if (dgg == null) {
return null;
}
DrawingManager2 dm = new DrawingManager2(dgg);
if (bStore != null) {
for (EscherRecord bs : bStore.getChildRecords()) {
if (bs instanceof EscherBSERecord) {
escherBSERecords.add((EscherBSERecord) bs);
}
}
}
return dm;
}
use of org.apache.poi.ddf.EscherContainerRecord in project poi by apache.
the class InternalWorkbook method addBSERecord.
public int addBSERecord(EscherBSERecord e) {
createDrawingGroup();
// maybe we don't need that as an instance variable anymore
escherBSERecords.add(e);
int dgLoc = findFirstRecordLocBySid(DrawingGroupRecord.sid);
DrawingGroupRecord drawingGroup = (DrawingGroupRecord) getRecords().get(dgLoc);
EscherContainerRecord dggContainer = (EscherContainerRecord) drawingGroup.getEscherRecord(0);
EscherContainerRecord bstoreContainer;
if (dggContainer.getChild(1).getRecordId() == EscherContainerRecord.BSTORE_CONTAINER) {
bstoreContainer = (EscherContainerRecord) dggContainer.getChild(1);
} else {
bstoreContainer = new EscherContainerRecord();
bstoreContainer.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);
List<EscherRecord> childRecords = dggContainer.getChildRecords();
childRecords.add(1, bstoreContainer);
dggContainer.setChildRecords(childRecords);
}
bstoreContainer.setOptions((short) ((escherBSERecords.size() << 4) | 0xF));
bstoreContainer.addChildRecord(e);
return escherBSERecords.size();
}
Aggregations