use of org.apache.poi.ddf.EscherSpRecord in project poi by apache.
the class HSLFSimpleShape method setPlaceholder.
@Override
public void setPlaceholder(Placeholder placeholder) {
EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
int flags = spRecord.getFlags();
if (placeholder == null) {
flags ^= EscherSpRecord.FLAG_HAVEMASTER;
} else {
flags |= EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HAVEMASTER;
}
spRecord.setFlags(flags);
// Placeholders can't be grouped
setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, (placeholder == null ? -1 : 262144));
HSLFEscherClientDataRecord clientData = getClientData(false);
if (placeholder == null) {
if (clientData != null) {
clientData.removeChild(OEPlaceholderAtom.class);
clientData.removeChild(RoundTripHFPlaceholder12.class);
// remove client data if the placeholder was the only child to be carried
if (clientData.getChildRecords().isEmpty()) {
getSpContainer().removeChildRecord(clientData);
}
}
return;
}
if (clientData == null) {
clientData = getClientData(true);
}
// OEPlaceholderAtom tells powerpoint that this shape is a placeholder
OEPlaceholderAtom oep = null;
RoundTripHFPlaceholder12 rtp = null;
for (Record r : clientData.getHSLFChildRecords()) {
if (r instanceof OEPlaceholderAtom) {
oep = (OEPlaceholderAtom) r;
break;
}
if (r instanceof RoundTripHFPlaceholder12) {
rtp = (RoundTripHFPlaceholder12) r;
break;
}
}
/**
* Extract from MSDN:
*
* There is a special case when the placeholder does not have a position in the layout.
* This occurs when the user has moved the placeholder from its original position.
* In this case the placeholder ID is -1.
*/
byte phId;
HSLFSheet sheet = getSheet();
// TODO: implement/switch NotesMaster
if (sheet instanceof HSLFSlideMaster) {
phId = (byte) placeholder.nativeSlideMasterId;
} else if (sheet instanceof HSLFNotes) {
phId = (byte) placeholder.nativeNotesId;
} else {
phId = (byte) placeholder.nativeSlideId;
}
if (phId == -2) {
throw new HSLFException("Placeholder " + placeholder.name() + " not supported for this sheet type (" + sheet.getClass() + ")");
}
switch(placeholder) {
case HEADER:
case FOOTER:
if (rtp == null) {
rtp = new RoundTripHFPlaceholder12();
rtp.setPlaceholderId(phId);
clientData.addChild(rtp);
}
if (oep != null) {
clientData.removeChild(OEPlaceholderAtom.class);
}
break;
default:
if (rtp != null) {
clientData.removeChild(RoundTripHFPlaceholder12.class);
}
if (oep == null) {
oep = new OEPlaceholderAtom();
oep.setPlaceholderSize((byte) OEPlaceholderAtom.PLACEHOLDER_FULLSIZE);
// TODO: placement id only "SHOULD" be unique ... check other placeholders on sheet for unique id
oep.setPlacementId(-1);
oep.setPlaceholderId(phId);
clientData.addChild(oep);
}
break;
}
}
use of org.apache.poi.ddf.EscherSpRecord 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.EscherSpRecord in project poi by apache.
the class HSLFLine method createSpContainer.
@Override
protected EscherContainerRecord createSpContainer(boolean isChild) {
EscherContainerRecord ecr = super.createSpContainer(isChild);
setShapeType(ShapeType.LINE);
EscherSpRecord spRecord = ecr.getChildById(EscherSpRecord.RECORD_ID);
short type = (short) ((ShapeType.LINE.nativeId << 4) | 0x2);
spRecord.setOptions(type);
//set default properties for a line
AbstractEscherOptRecord opt = getEscherOptRecord();
//default line properties
setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, 4);
setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, 0x10000);
setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x100000);
setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, 0x8000001);
setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0xA0008);
setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
return ecr;
}
use of org.apache.poi.ddf.EscherSpRecord in project poi by apache.
the class HSLFPictureShape method createSpContainer.
/**
* Create a new Picture and populate the inital structure of the <code>EscherSp</code> record which holds information about this picture.
* @param idx the index of the picture which refers to <code>EscherBSE</code> container.
* @return the create Picture object
*/
protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {
EscherContainerRecord ecr = super.createSpContainer(isChild);
EscherSpRecord spRecord = ecr.getChildById(EscherSpRecord.RECORD_ID);
spRecord.setOptions((short) ((ShapeType.FRAME.nativeId << 4) | 0x2));
//set default properties for a picture
AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x800080);
//another weird feature of powerpoint: for picture id we must add 0x4000.
setEscherProperty(opt, (short) (EscherProperties.BLIP__BLIPTODISPLAY + 0x4000), idx);
return ecr;
}
use of org.apache.poi.ddf.EscherSpRecord in project poi by apache.
the class TestCloneSheet method testCloneSheetWithEmptyDrawingAggregate.
@Test
public void testCloneSheetWithEmptyDrawingAggregate() {
HSSFWorkbook b = new HSSFWorkbook();
HSSFSheet s = b.createSheet("Test");
HSSFPatriarch patriarch = s.createDrawingPatriarch();
EscherAggregate agg1 = patriarch.getBoundAggregate();
HSSFSheet s2 = s.cloneSheet(b);
patriarch = s2.getDrawingPatriarch();
EscherAggregate agg2 = patriarch.getBoundAggregate();
EscherSpRecord sp1 = (EscherSpRecord) agg1.getEscherContainer().getChild(1).getChild(0).getChild(1);
EscherSpRecord sp2 = (EscherSpRecord) agg2.getEscherContainer().getChild(1).getChild(0).getChild(1);
assertEquals(sp1.getShapeId(), 1024);
assertEquals(sp2.getShapeId(), 2048);
EscherDgRecord dg = (EscherDgRecord) agg2.getEscherContainer().getChild(0);
assertEquals(dg.getLastMSOSPID(), 2048);
assertEquals(dg.getInstance(), 0x2);
//everything except id and DgRecord.lastMSOSPID and DgRecord.Instance must be the same
sp2.setShapeId(1024);
dg.setLastMSOSPID(1024);
dg.setInstance((short) 0x1);
assertEquals(agg1.serialize().length, agg2.serialize().length);
assertEquals(agg1.toXml(""), agg2.toXml(""));
assertArrayEquals(agg1.serialize(), agg2.serialize());
}
Aggregations