use of org.apache.poi.ddf.EscherSpRecord 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.EscherSpRecord 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.EscherSpRecord in project poi by apache.
the class HSLFGroupShape method getShapeType.
/**
* Return type of the shape.
* In most cases shape group type is {@link org.apache.poi.sl.usermodel.ShapeType#NOT_PRIMITIVE}
*
* @return type of the shape.
*/
@Override
public ShapeType getShapeType() {
EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
int nativeId = spRecord.getOptions() >> 4;
return ShapeType.forId(nativeId, false);
}
use of org.apache.poi.ddf.EscherSpRecord in project poi by apache.
the class HSLFShape method setAnchor.
/**
* Sets the anchor (the bounding box rectangle) of this shape.
* All coordinates should be expressed in points (72 dpi).
*
* @param anchor new anchor
*/
public void setAnchor(Rectangle2D anchor) {
int x = Units.pointsToMaster(anchor.getX());
int y = Units.pointsToMaster(anchor.getY());
int w = Units.pointsToMaster(anchor.getWidth() + anchor.getX());
int h = Units.pointsToMaster(anchor.getHeight() + anchor.getY());
EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
int flags = spRecord.getFlags();
if ((flags & EscherSpRecord.FLAG_CHILD) != 0) {
EscherChildAnchorRecord rec = (EscherChildAnchorRecord) getEscherChild(EscherChildAnchorRecord.RECORD_ID);
rec.setDx1(x);
rec.setDy1(y);
rec.setDx2(w);
rec.setDy2(h);
} else {
EscherClientAnchorRecord rec = (EscherClientAnchorRecord) getEscherChild(EscherClientAnchorRecord.RECORD_ID);
rec.setCol1((short) x);
rec.setFlag((short) y);
rec.setDx1((short) w);
rec.setRow1((short) h);
}
}
use of org.apache.poi.ddf.EscherSpRecord in project poi by apache.
the class HSLFShape method setShapeType.
public void setShapeType(ShapeType type) {
EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
spRecord.setShapeType((short) type.nativeId);
spRecord.setVersion((short) 0x2);
}
Aggregations