use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class HSSFWorkbook method addPicture.
/**
* Adds a picture to the workbook.
*
* @param pictureData The bytes of the picture
* @param format The format of the picture. One of <code>PICTURE_TYPE_*</code>
*
* @return the index to this picture (1 based).
* @see #PICTURE_TYPE_WMF
* @see #PICTURE_TYPE_EMF
* @see #PICTURE_TYPE_PICT
* @see #PICTURE_TYPE_PNG
* @see #PICTURE_TYPE_JPEG
* @see #PICTURE_TYPE_DIB
*/
@SuppressWarnings("fallthrough")
@Override
public int addPicture(byte[] pictureData, int format) {
initDrawings();
byte[] uid = DigestUtils.md5(pictureData);
EscherBlipRecord blipRecord;
int blipSize;
short escherTag;
switch(format) {
case PICTURE_TYPE_WMF:
// see also http://de.wikipedia.org/wiki/Windows_Metafile#Hinweise_zur_WMF-Spezifikation
if (LittleEndian.getInt(pictureData) == 0x9AC6CDD7) {
byte[] picDataNoHeader = new byte[pictureData.length - 22];
System.arraycopy(pictureData, 22, picDataNoHeader, 0, pictureData.length - 22);
pictureData = picDataNoHeader;
}
// fall through
case PICTURE_TYPE_EMF:
EscherMetafileBlip blipRecordMeta = new EscherMetafileBlip();
blipRecord = blipRecordMeta;
blipRecordMeta.setUID(uid);
blipRecordMeta.setPictureData(pictureData);
// taken from libre office export, it won't open, if this is left to 0
blipRecordMeta.setFilter((byte) -2);
blipSize = blipRecordMeta.getCompressedSize() + 58;
escherTag = 0;
break;
default:
EscherBitmapBlip blipRecordBitmap = new EscherBitmapBlip();
blipRecord = blipRecordBitmap;
blipRecordBitmap.setUID(uid);
blipRecordBitmap.setMarker((byte) 0xFF);
blipRecordBitmap.setPictureData(pictureData);
blipSize = pictureData.length + 25;
escherTag = (short) 0xFF;
break;
}
blipRecord.setRecordId((short) (EscherBlipRecord.RECORD_ID_START + format));
switch(format) {
case PICTURE_TYPE_EMF:
blipRecord.setOptions(HSSFPictureData.MSOBI_EMF);
break;
case PICTURE_TYPE_WMF:
blipRecord.setOptions(HSSFPictureData.MSOBI_WMF);
break;
case PICTURE_TYPE_PICT:
blipRecord.setOptions(HSSFPictureData.MSOBI_PICT);
break;
case PICTURE_TYPE_PNG:
blipRecord.setOptions(HSSFPictureData.MSOBI_PNG);
break;
case PICTURE_TYPE_JPEG:
blipRecord.setOptions(HSSFPictureData.MSOBI_JPEG);
break;
case PICTURE_TYPE_DIB:
blipRecord.setOptions(HSSFPictureData.MSOBI_DIB);
break;
default:
throw new IllegalStateException("Unexpected picture format: " + format);
}
EscherBSERecord r = new EscherBSERecord();
r.setRecordId(EscherBSERecord.RECORD_ID);
r.setOptions((short) (0x0002 | (format << 4)));
r.setBlipTypeMacOS((byte) format);
r.setBlipTypeWin32((byte) format);
r.setUid(uid);
r.setTag(escherTag);
r.setSize(blipSize);
r.setRef(0);
r.setOffset(0);
r.setBlipRecord(blipRecord);
return workbook.addBSERecord(r);
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class HSSFPicture method getImageDimension.
/**
* Return the dimension of the embedded image in pixel
*
* @return image dimension in pixels
*/
@Override
public Dimension getImageDimension() {
InternalWorkbook iwb = getPatriarch().getSheet().getWorkbook().getWorkbook();
EscherBSERecord bse = iwb.getBSERecord(getPictureIndex());
byte[] data = bse.getBlipRecord().getPicturedata();
int type = bse.getBlipTypeWin32();
return ImageUtils.getImageDimension(new ByteArrayInputStream(data), type);
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class HSSFComment method setBackgroundImage.
public void setBackgroundImage(int pictureIndex) {
setPropertyValue(new EscherSimpleProperty(EscherProperties.FILL__PATTERNTEXTURE, false, true, pictureIndex));
setPropertyValue(new EscherSimpleProperty(EscherProperties.FILL__FILLTYPE, false, false, FILL_TYPE_PICTURE));
EscherBSERecord bse = getPatriarch().getSheet().getWorkbook().getWorkbook().getBSERecord(pictureIndex);
bse.setRef(bse.getRef() + 1);
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class HSLFPictureShape method afterInsert.
/**
* By default set the orininal image size
*/
@Override
protected void afterInsert(HSLFSheet sh) {
super.afterInsert(sh);
EscherBSERecord bse = getEscherBSERecord();
bse.setRef(bse.getRef() + 1);
Rectangle2D anchor = getAnchor();
if (anchor.isEmpty()) {
new DrawPictureShape(this).resize();
}
}
use of org.apache.poi.ddf.EscherBSERecord in project poi by apache.
the class HSLFPictureShape method getPictureData.
@SuppressWarnings("resource")
@Override
public HSLFPictureData getPictureData() {
HSLFSlideShow ppt = getSheet().getSlideShow();
List<HSLFPictureData> pict = ppt.getPictureData();
EscherBSERecord bse = getEscherBSERecord();
if (bse == null) {
LOG.log(POILogger.ERROR, "no reference to picture data found ");
} else {
for (HSLFPictureData pd : pict) {
if (pd.getOffset() == bse.getOffset()) {
return pd;
}
}
LOG.log(POILogger.ERROR, "no picture found for our BSE offset " + bse.getOffset());
}
return null;
}
Aggregations