use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class OfficeDrawingsImpl method getBitmapRecord.
private EscherBlipRecord getBitmapRecord(int bitmapIndex) {
List<? extends EscherContainerRecord> bContainers = _escherRecordHolder.getBStoreContainers();
if (bContainers == null || bContainers.size() != 1)
return null;
EscherContainerRecord bContainer = bContainers.get(0);
final List<EscherRecord> bitmapRecords = bContainer.getChildRecords();
if (bitmapRecords.size() < bitmapIndex)
return null;
EscherRecord imageRecord = bitmapRecords.get(bitmapIndex - 1);
if (imageRecord instanceof EscherBlipRecord) {
return (EscherBlipRecord) imageRecord;
}
if (imageRecord instanceof EscherBSERecord) {
EscherBSERecord bseRecord = (EscherBSERecord) imageRecord;
EscherBlipRecord blip = bseRecord.getBlipRecord();
if (blip != null) {
return blip;
}
if (bseRecord.getOffset() > 0) {
/*
* Blip stored in delay stream, which in a word doc, is the main
* stream
*/
EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
EscherRecord record = recordFactory.createRecord(_mainStream, bseRecord.getOffset());
if (record instanceof EscherBlipRecord) {
record.fillFields(_mainStream, bseRecord.getOffset(), recordFactory);
return (EscherBlipRecord) record;
}
}
}
return null;
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class TestBackground method getFillPictureRefCount.
private int getFillPictureRefCount(HSLFShape shape, HSLFFill fill) {
AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
if (p != null) {
int idx = p.getPropertyValue();
HSLFSheet sheet = shape.getSheet();
HSLFSlideShow ppt = sheet.getSlideShow();
Document doc = ppt.getDocumentRecord();
EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
List<EscherRecord> lst = bstore.getChildRecords();
return ((EscherBSERecord) lst.get(idx - 1)).getRef();
}
return 0;
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class HSSFWorkbook 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<HSSFPictureData> pictures) {
for (EscherRecord escherRecord : escherRecords) {
if (escherRecord instanceof EscherBSERecord) {
EscherBlipRecord blip = ((EscherBSERecord) escherRecord).getBlipRecord();
if (blip != null) {
// TODO: Some kind of structure.
HSSFPictureData picture = new HSSFPictureData(blip);
pictures.add(picture);
}
}
// Recursive call.
searchForPictures(escherRecord.getChildRecords(), pictures);
}
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class TestPicture method multiplePictures.
/**
* Test that the reference count of a blip is incremented every time the picture is inserted.
* This is important when the same image appears multiple times in a slide show.
*
*/
@Test
public void multiplePictures() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide s = ppt.createSlide();
HSLFSlide s2 = ppt.createSlide();
HSLFSlide s3 = ppt.createSlide();
HSLFPictureData data = ppt.addPicture(_slTests.readFile("clock.jpg"), PictureType.JPEG);
HSLFPictureShape pict = new HSLFPictureShape(data);
HSLFPictureShape pict2 = new HSLFPictureShape(data);
HSLFPictureShape pict3 = new HSLFPictureShape(data);
pict.setAnchor(new Rectangle(10, 10, 100, 100));
s.addShape(pict);
EscherBSERecord bse1 = pict.getEscherBSERecord();
assertEquals(1, bse1.getRef());
pict2.setAnchor(new Rectangle(10, 10, 100, 100));
s2.addShape(pict2);
EscherBSERecord bse2 = pict.getEscherBSERecord();
assertSame(bse1, bse2);
assertEquals(2, bse1.getRef());
pict3.setAnchor(new Rectangle(10, 10, 100, 100));
s3.addShape(pict3);
EscherBSERecord bse3 = pict.getEscherBSERecord();
assertSame(bse2, bse3);
assertEquals(3, bse1.getRef());
ppt.close();
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class TestHSSFPicture method bsePictureRef.
@SuppressWarnings("unused")
@Test
public void bsePictureRef() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sh = wb.createSheet("Pictures");
HSSFPatriarch dr = sh.createDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor();
InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
//register a picture
byte[] data1 = new byte[] { 1, 2, 3 };
int idx1 = wb.addPicture(data1, Workbook.PICTURE_TYPE_JPEG);
assertEquals(1, idx1);
HSSFPicture p1 = dr.createPicture(anchor, idx1);
EscherBSERecord bse = wb.getWorkbook().getBSERecord(idx1);
assertEquals(bse.getRef(), 1);
dr.createPicture(new HSSFClientAnchor(), idx1);
assertEquals(bse.getRef(), 2);
HSSFShapeGroup gr = dr.createGroup(new HSSFClientAnchor());
gr.createPicture(new HSSFChildAnchor(), idx1);
assertEquals(bse.getRef(), 3);
wb.close();
}
Aggregations