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