Search in sources :

Example 6 with EscherBSERecord

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);
}
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 7 with EscherBSERecord

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

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();
}
Also used : InternalWorkbook(org.apache.poi.hssf.model.InternalWorkbook) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) Test(org.junit.Test)

Example 9 with EscherBSERecord

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) RecordFormatException(org.apache.poi.util.RecordFormatException) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 10 with EscherBSERecord

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

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