use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class HSLFFill method getEscherBSERecord.
@SuppressWarnings("resource")
protected EscherBSERecord getEscherBSERecord(int idx) {
HSLFSheet sheet = shape.getSheet();
if (sheet == null) {
LOG.log(POILogger.DEBUG, "Fill has not yet been assigned to a sheet");
return null;
}
HSLFSlideShow ppt = sheet.getSlideShow();
Document doc = ppt.getDocumentRecord();
EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
if (bstore == null) {
LOG.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found ");
return null;
}
List<EscherRecord> lst = bstore.getChildRecords();
return (EscherBSERecord) lst.get(idx - 1);
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class HSLFFill method setPictureData.
/**
* Assign picture used to fill the underlying shape.
*
* @param data the picture data added to this ppt by {@link HSLFSlideShow#addPicture(byte[], org.apache.poi.sl.usermodel.PictureData.PictureType)} method.
*/
public void setPictureData(HSLFPictureData data) {
AbstractEscherOptRecord opt = shape.getEscherOptRecord();
HSLFShape.setEscherProperty(opt, (short) (EscherProperties.FILL__PATTERNTEXTURE + 0x4000), (data == null ? 0 : data.getIndex()));
if (data != null && shape.getSheet() != null) {
EscherBSERecord bse = getEscherBSERecord(data.getIndex());
if (bse != null) {
bse.setRef(bse.getRef() + 1);
}
}
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class HSLFFill method afterInsert.
/**
*/
protected void afterInsert(HSLFSheet sh) {
AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
if (p != null) {
int idx = p.getPropertyValue();
EscherBSERecord bse = getEscherBSERecord(idx);
if (bse != null) {
bse.setRef(bse.getRef() + 1);
}
}
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class HSLFSlideShow method addPicture.
@Override
public HSLFPictureData addPicture(byte[] data, PictureType format) throws IOException {
if (format == null || format.nativeId == -1) {
throw new IllegalArgumentException("Unsupported picture format: " + format);
}
HSLFPictureData pd = findPictureData(data);
if (pd != null) {
// identical picture was already added to the SlideShow
return pd;
}
EscherContainerRecord bstore;
EscherContainerRecord dggContainer = _documentRecord.getPPDrawingGroup().getDggContainer();
bstore = (EscherContainerRecord) HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
if (bstore == null) {
bstore = new EscherContainerRecord();
bstore.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);
dggContainer.addChildBefore(bstore, EscherOptRecord.RECORD_ID);
}
HSLFPictureData pict = HSLFPictureData.create(format);
pict.setData(data);
int offset = _hslfSlideShow.addPicture(pict);
EscherBSERecord bse = new EscherBSERecord();
bse.setRecordId(EscherBSERecord.RECORD_ID);
bse.setOptions((short) (0x0002 | (format.nativeId << 4)));
bse.setSize(pict.getRawData().length + 8);
byte[] uid = HSLFPictureData.getChecksum(data);
bse.setUid(uid);
bse.setBlipTypeMacOS((byte) format.nativeId);
bse.setBlipTypeWin32((byte) format.nativeId);
if (format == PictureType.EMF) {
bse.setBlipTypeMacOS((byte) PictureType.PICT.nativeId);
} else if (format == PictureType.WMF) {
bse.setBlipTypeMacOS((byte) PictureType.PICT.nativeId);
} else if (format == PictureType.PICT) {
bse.setBlipTypeWin32((byte) PictureType.WMF.nativeId);
}
bse.setRef(0);
bse.setOffset(offset);
bse.setRemainingData(new byte[0]);
bstore.addChildRecord(bse);
int count = bstore.getChildRecords().size();
bstore.setOptions((short) ((count << 4) | 0xF));
return pict;
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class PicturesTable method searchForPictures.
/**
* Performs a recursive search for pictures in the given list of escher records.
*
* @param escherRecords the escher records.
* @param pictures the list to populate with the pictures.
*/
private void searchForPictures(List<EscherRecord> escherRecords, List<Picture> pictures) {
for (EscherRecord escherRecord : escherRecords) {
if (escherRecord instanceof EscherBSERecord) {
EscherBSERecord bse = (EscherBSERecord) escherRecord;
EscherBlipRecord blip = bse.getBlipRecord();
if (blip != null) {
pictures.add(new Picture(blip));
} else if (bse.getOffset() > 0) {
try {
// Blip stored in delay stream, which in a word doc, is
// the main stream
EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
EscherRecord record = recordFactory.createRecord(_mainStream, bse.getOffset());
if (record instanceof EscherBlipRecord) {
record.fillFields(_mainStream, bse.getOffset(), recordFactory);
blip = (EscherBlipRecord) record;
pictures.add(new Picture(blip));
}
} catch (Exception exc) {
logger.log(POILogger.WARN, "Unable to load picture from BLIB record at offset #", Integer.valueOf(bse.getOffset()), exc);
}
}
}
// Recursive call.
searchForPictures(escherRecord.getChildRecords(), pictures);
}
}
Aggregations