Search in sources :

Example 41 with EscherContainerRecord

use of org.apache.poi.ddf.EscherContainerRecord 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 42 with EscherContainerRecord

use of org.apache.poi.ddf.EscherContainerRecord in project poi by apache.

the class HSSFSimpleShape method createSpContainer.

@Override
protected EscherContainerRecord createSpContainer() {
    EscherContainerRecord spContainer = new EscherContainerRecord();
    spContainer.setRecordId(EscherContainerRecord.SP_CONTAINER);
    spContainer.setOptions((short) 0x000F);
    EscherSpRecord sp = new EscherSpRecord();
    sp.setRecordId(EscherSpRecord.RECORD_ID);
    sp.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE);
    sp.setVersion((short) 0x2);
    EscherClientDataRecord clientData = new EscherClientDataRecord();
    clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
    clientData.setOptions((short) (0x0000));
    EscherOptRecord optRecord = new EscherOptRecord();
    optRecord.setEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, LINESTYLE_SOLID));
    optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
    //        optRecord.setEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, LINEWIDTH_DEFAULT));
    optRecord.setEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, FILL__FILLCOLOR_DEFAULT));
    optRecord.setEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, LINESTYLE__COLOR_DEFAULT));
    optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, NO_FILLHITTEST_FALSE));
    optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
    optRecord.setEscherProperty(new EscherShapePathProperty(EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX));
    optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x080000));
    optRecord.setRecordId(EscherOptRecord.RECORD_ID);
    EscherTextboxRecord escherTextbox = new EscherTextboxRecord();
    escherTextbox.setRecordId(EscherTextboxRecord.RECORD_ID);
    escherTextbox.setOptions((short) 0x0000);
    spContainer.addChildRecord(sp);
    spContainer.addChildRecord(optRecord);
    spContainer.addChildRecord(getAnchor().getEscherAnchor());
    spContainer.addChildRecord(clientData);
    spContainer.addChildRecord(escherTextbox);
    return spContainer;
}
Also used : EscherBoolProperty(org.apache.poi.ddf.EscherBoolProperty) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) EscherClientDataRecord(org.apache.poi.ddf.EscherClientDataRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherShapePathProperty(org.apache.poi.ddf.EscherShapePathProperty) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherRGBProperty(org.apache.poi.ddf.EscherRGBProperty)

Example 43 with EscherContainerRecord

use of org.apache.poi.ddf.EscherContainerRecord 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 44 with EscherContainerRecord

use of org.apache.poi.ddf.EscherContainerRecord in project poi by apache.

the class TestEscherRecordFactory method testDgContainerMustBeRootOfHSSFSheetEscherRecords.

public void testDgContainerMustBeRootOfHSSFSheetEscherRecords() throws IOException {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("47251.xls");
    HSSFSheet sh = wb.getSheetAt(0);
    InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
    List<RecordBase> records = ish.getRecords();
    // records to be aggregated
    List<RecordBase> dgRecords = records.subList(19, 23);
    byte[] dgBytes = toByteArray(dgRecords);
    sh.getDrawingPatriarch();
    EscherAggregate agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
    assertEquals(true, agg.getEscherRecords().get(0) instanceof EscherContainerRecord);
    assertEquals(EscherContainerRecord.DG_CONTAINER, agg.getEscherRecords().get(0).getRecordId());
    assertEquals((short) 0x0, agg.getEscherRecords().get(0).getOptions());
    agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
    byte[] dgBytesAfterSave = agg.serialize();
    assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
    assertTrue("drawing data before and after save is different", Arrays.equals(dgBytes, dgBytesAfterSave));
}
Also used : EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) RecordBase(org.apache.poi.hssf.record.RecordBase) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 45 with EscherContainerRecord

use of org.apache.poi.ddf.EscherContainerRecord in project poi by apache.

the class TestDrawingGroupRecord method testGetRecordSize.

public void testGetRecordSize() {
    DrawingGroupRecord r = new DrawingGroupRecord();
    assertEquals(4, r.getRecordSize());
    EscherSpRecord sp = new EscherSpRecord();
    sp.setRecordId(EscherSpRecord.RECORD_ID);
    sp.setOptions((short) 0x1111);
    sp.setFlags(-1);
    sp.setShapeId(-1);
    EscherContainerRecord dggContainer = new EscherContainerRecord();
    dggContainer.setOptions((short) 0x000F);
    dggContainer.setRecordId((short) 0xF000);
    dggContainer.addChildRecord(sp);
    r.addEscherRecord(dggContainer);
    assertEquals(28, r.getRecordSize());
    byte[] data = new byte[28];
    int size = r.serialize(0, data);
    assertEquals("[EB, 00, 18, 00, 0F, 00, 00, F0, 10, 00, 00, 00, 11, 11, 0A, F0, 08, 00, 00, 00, FF, FF, FF, FF, FF, FF, FF, FF]", HexDump.toHex(data));
    assertEquals(28, size);
    assertEquals(24, dggContainer.getRecordSize());
    r = new DrawingGroupRecord();
    r.setRawData(new byte[MAX_DATA_SIZE]);
    assertEquals(MAX_RECORD_SIZE, r.getRecordSize());
    r.setRawData(new byte[MAX_DATA_SIZE + 1]);
    assertEquals(MAX_RECORD_SIZE + 5, r.getRecordSize());
    r.setRawData(new byte[MAX_DATA_SIZE * 2]);
    assertEquals(MAX_RECORD_SIZE * 2, r.getRecordSize());
    r.setRawData(new byte[MAX_DATA_SIZE * 2 + 1]);
    assertEquals(MAX_RECORD_SIZE * 2 + 5, r.getRecordSize());
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord)

Aggregations

EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)53 EscherRecord (org.apache.poi.ddf.EscherRecord)17 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)17 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)11 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)8 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)8 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)6 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)6 DefaultEscherRecordFactory (org.apache.poi.ddf.DefaultEscherRecordFactory)5 ObjRecord (org.apache.poi.hssf.record.ObjRecord)5 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)4 EscherSpgrRecord (org.apache.poi.ddf.EscherSpgrRecord)4 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)4 Document (org.apache.poi.hslf.record.Document)4 PPDrawing (org.apache.poi.hslf.record.PPDrawing)4 LinkedList (java.util.LinkedList)3 EscherBoolProperty (org.apache.poi.ddf.EscherBoolProperty)3 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)3 EscherRGBProperty (org.apache.poi.ddf.EscherRGBProperty)3 ExObjRefAtom (org.apache.poi.hslf.record.ExObjRefAtom)3