use of org.apache.poi.ddf.EscherClientAnchorRecord in project poi by apache.
the class HSLFGroupShape method getAnchor.
/**
* Returns the anchor (the bounding box rectangle) of this shape group.
* All coordinates are expressed in points (72 dpi).
*
* @return the anchor of this shape group
*/
@Override
public Rectangle2D getAnchor() {
EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
int x1, y1, x2, y2;
if (clientAnchor == null) {
LOG.log(POILogger.INFO, "EscherClientAnchorRecord was not found for shape group. Searching for EscherChildAnchorRecord.");
EscherChildAnchorRecord rec = getEscherChild(EscherChildAnchorRecord.RECORD_ID);
x1 = rec.getDx1();
y1 = rec.getDy1();
x2 = rec.getDx2();
y2 = rec.getDy2();
} else {
x1 = clientAnchor.getCol1();
y1 = clientAnchor.getFlag();
x2 = clientAnchor.getDx1();
y2 = clientAnchor.getRow1();
}
Rectangle2D anchor = new Rectangle2D.Double((x1 == -1 ? -1 : Units.masterToPoints(x1)), (y1 == -1 ? -1 : Units.masterToPoints(y1)), (x2 == -1 ? -1 : Units.masterToPoints(x2 - x1)), (y2 == -1 ? -1 : Units.masterToPoints(y2 - y1)));
return anchor;
}
use of org.apache.poi.ddf.EscherClientAnchorRecord 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.EscherClientAnchorRecord in project poi by apache.
the class HSLFGroupShape method setExteriorAnchor.
protected void setExteriorAnchor(Rectangle2D anchor) {
EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
//hack. internal variable EscherClientAnchorRecord.shortRecord can be
//initialized only in fillFields(). We need to set shortRecord=false;
byte[] header = new byte[16];
LittleEndian.putUShort(header, 0, 0);
LittleEndian.putUShort(header, 2, 0);
LittleEndian.putInt(header, 4, 8);
clientAnchor.fillFields(header, 0, null);
// All coordinates need to be converted to Master units (576 dpi)
clientAnchor.setFlag((short) Units.pointsToMaster(anchor.getY()));
clientAnchor.setCol1((short) Units.pointsToMaster(anchor.getX()));
clientAnchor.setDx1((short) Units.pointsToMaster(anchor.getWidth() + anchor.getX()));
clientAnchor.setRow1((short) Units.pointsToMaster(anchor.getHeight() + anchor.getY()));
// TODO: does this make sense?
setInteriorAnchor(anchor);
}
use of org.apache.poi.ddf.EscherClientAnchorRecord in project poi by apache.
the class HSLFSimpleShape method createSpContainer.
/**
* Create a new Shape
*
* @param isChild <code>true</code> if the Line is inside a group, <code>false</code> otherwise
* @return the record container which holds this shape
*/
@Override
protected EscherContainerRecord createSpContainer(boolean isChild) {
EscherContainerRecord ecr = super.createSpContainer(isChild);
ecr.setRecordId(EscherContainerRecord.SP_CONTAINER);
EscherSpRecord sp = new EscherSpRecord();
int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
if (isChild) {
flags |= EscherSpRecord.FLAG_CHILD;
}
sp.setFlags(flags);
ecr.addChildRecord(sp);
AbstractEscherOptRecord opt = new EscherOptRecord();
opt.setRecordId(EscherOptRecord.RECORD_ID);
ecr.addChildRecord(opt);
EscherRecord anchor;
if (isChild) {
anchor = new EscherChildAnchorRecord();
} else {
anchor = new EscherClientAnchorRecord();
//hack. internal variable EscherClientAnchorRecord.shortRecord can be
//initialized only in fillFields(). We need to set shortRecord=false;
byte[] header = new byte[16];
LittleEndian.putUShort(header, 0, 0);
LittleEndian.putUShort(header, 2, 0);
LittleEndian.putInt(header, 4, 8);
anchor.fillFields(header, 0, null);
}
ecr.addChildRecord(anchor);
return ecr;
}
use of org.apache.poi.ddf.EscherClientAnchorRecord in project poi by apache.
the class HSSFShape method setAnchor.
/**
* Sets a particular anchor. A top-level shape must have an anchor of
* HSSFClientAnchor. A child anchor must have an anchor of HSSFChildAnchor
*
* @param anchor the anchor to use.
* @throws IllegalArgumentException when the wrong anchor is used for
* this particular shape.
* @see HSSFChildAnchor
* @see HSSFClientAnchor
*/
public void setAnchor(HSSFAnchor anchor) {
int i = 0;
int recordId = -1;
if (parent == null) {
if (anchor instanceof HSSFChildAnchor)
throw new IllegalArgumentException("Must use client anchors for shapes directly attached to sheet.");
EscherClientAnchorRecord anch = _escherContainer.getChildById(EscherClientAnchorRecord.RECORD_ID);
if (null != anch) {
for (i = 0; i < _escherContainer.getChildRecords().size(); i++) {
if (_escherContainer.getChild(i).getRecordId() == EscherClientAnchorRecord.RECORD_ID) {
if (i != _escherContainer.getChildRecords().size() - 1) {
recordId = _escherContainer.getChild(i + 1).getRecordId();
}
}
}
_escherContainer.removeChildRecord(anch);
}
} else {
if (anchor instanceof HSSFClientAnchor)
throw new IllegalArgumentException("Must use child anchors for shapes attached to groups.");
EscherChildAnchorRecord anch = _escherContainer.getChildById(EscherChildAnchorRecord.RECORD_ID);
if (null != anch) {
for (i = 0; i < _escherContainer.getChildRecords().size(); i++) {
if (_escherContainer.getChild(i).getRecordId() == EscherChildAnchorRecord.RECORD_ID) {
if (i != _escherContainer.getChildRecords().size() - 1) {
recordId = _escherContainer.getChild(i + 1).getRecordId();
}
}
}
_escherContainer.removeChildRecord(anch);
}
}
if (-1 == recordId) {
_escherContainer.addChildRecord(anchor.getEscherAnchor());
} else {
_escherContainer.addChildBefore(anchor.getEscherAnchor(), recordId);
}
this.anchor = anchor;
}
Aggregations