use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class HSLFPictureShape method getEscherBSERecord.
@SuppressWarnings("resource")
protected EscherBSERecord getEscherBSERecord() {
HSLFSlideShow ppt = getSheet().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();
int idx = getPictureIndex();
if (idx == 0) {
LOG.log(POILogger.DEBUG, "picture index was not found, returning ");
return null;
}
return (EscherBSERecord) lst.get(idx - 1);
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class HSLFFill method getPictureData.
/**
* <code>PictureData</code> object used in a texture, pattern of picture fill.
*/
@SuppressWarnings("resource")
public HSLFPictureData getPictureData() {
AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
if (p == null) {
return null;
}
HSLFSlideShow ppt = shape.getSheet().getSlideShow();
List<HSLFPictureData> pict = ppt.getPictureData();
Document doc = ppt.getDocumentRecord();
EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
java.util.List<EscherRecord> lst = bstore.getChildRecords();
int idx = p.getPropertyValue();
if (idx == 0) {
LOG.log(POILogger.WARN, "no reference to picture data found ");
} else {
EscherBSERecord bse = (EscherBSERecord) lst.get(idx - 1);
for (HSLFPictureData pd : pict) {
if (pd.getOffset() == bse.getOffset()) {
return pd;
}
}
}
return null;
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class TestHSSFWorkbook method clonePictures.
@Test
public void clonePictures() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithImages.xls");
InternalWorkbook iwb = wb.getWorkbook();
iwb.findDrawingGroup();
for (int pictureIndex = 1; pictureIndex <= 4; pictureIndex++) {
EscherBSERecord bse = iwb.getBSERecord(pictureIndex);
assertEquals(1, bse.getRef());
}
wb.cloneSheet(0);
for (int pictureIndex = 1; pictureIndex <= 4; pictureIndex++) {
EscherBSERecord bse = iwb.getBSERecord(pictureIndex);
assertEquals(2, bse.getRef());
}
wb.cloneSheet(0);
for (int pictureIndex = 1; pictureIndex <= 4; pictureIndex++) {
EscherBSERecord bse = iwb.getBSERecord(pictureIndex);
assertEquals(3, bse.getRef());
}
wb.close();
}
use of org.apache.poi.ddf.EscherBSERecord 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.EscherBSERecord 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;
}
Aggregations