Search in sources :

Example 6 with EscherRecordFactory

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

Aggregations

DefaultEscherRecordFactory (org.apache.poi.ddf.DefaultEscherRecordFactory)6 EscherRecord (org.apache.poi.ddf.EscherRecord)6 EscherRecordFactory (org.apache.poi.ddf.EscherRecordFactory)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)2 EscherBlipRecord (org.apache.poi.ddf.EscherBlipRecord)2 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)2 IOException (java.io.IOException)1 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)1 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)1 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)1 EscherSpgrRecord (org.apache.poi.ddf.EscherSpgrRecord)1 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)1 Picture (org.apache.poi.hwpf.usermodel.Picture)1 Test (org.junit.Test)1