Search in sources :

Example 11 with EscherBSERecord

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);
}
Also used : EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) Document(org.apache.poi.hslf.record.Document) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 12 with EscherBSERecord

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);
        }
    }
}
Also used : AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 13 with EscherBSERecord

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);
        }
    }
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) DrawPaint(org.apache.poi.sl.draw.DrawPaint) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 14 with EscherBSERecord

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;
}
Also used : EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 15 with EscherBSERecord

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);
    }
}
Also used : Picture(org.apache.poi.hwpf.usermodel.Picture) EscherRecord(org.apache.poi.ddf.EscherRecord) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) EscherBlipRecord(org.apache.poi.ddf.EscherBlipRecord) EscherRecordFactory(org.apache.poi.ddf.EscherRecordFactory) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory)

Aggregations

EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)23 EscherRecord (org.apache.poi.ddf.EscherRecord)9 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)8 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)6 EscherBlipRecord (org.apache.poi.ddf.EscherBlipRecord)5 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)4 Document (org.apache.poi.hslf.record.Document)4 InternalWorkbook (org.apache.poi.hssf.model.InternalWorkbook)3 Test (org.junit.Test)3 DefaultEscherRecordFactory (org.apache.poi.ddf.DefaultEscherRecordFactory)2 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)2 EscherRecordFactory (org.apache.poi.ddf.EscherRecordFactory)2 EscherAggregate (org.apache.poi.hssf.record.EscherAggregate)2 DrawPaint (org.apache.poi.sl.draw.DrawPaint)2 GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)2 TexturePaint (org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)2 Rectangle (java.awt.Rectangle)1 Rectangle2D (java.awt.geom.Rectangle2D)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 EscherBitmapBlip (org.apache.poi.ddf.EscherBitmapBlip)1