Search in sources :

Example 16 with EscherBSERecord

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

Example 17 with EscherBSERecord

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;
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) HSLFSheet(org.apache.poi.hslf.usermodel.HSLFSheet) 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) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 18 with EscherBSERecord

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

Example 19 with EscherBSERecord

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();
}
Also used : Rectangle(java.awt.Rectangle) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) Test(org.junit.Test)

Example 20 with EscherBSERecord

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

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