use of org.apache.poi.hssf.model.DrawingManager2 in project poi by apache.
the class HSSFPatriarch method newShapeId.
/**
* @return new unique shapeId
*/
int newShapeId() {
DrawingManager2 dm = _sheet.getWorkbook().getWorkbook().getDrawingManager();
EscherDgRecord dg = _boundAggregate.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
short drawingGroupId = dg.getDrawingGroupId();
return dm.allocateShapeId(drawingGroupId, dg);
}
use of org.apache.poi.hssf.model.DrawingManager2 in project poi by apache.
the class TestHSSFSheet method cloneSheetWithDrawings.
/**
* If we clone a sheet containing drawings,
* we must allocate a new ID of the drawing group and re-create shape IDs
*
* See bug #45720.
*/
@Test
public void cloneSheetWithDrawings() throws IOException {
HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("45720.xls");
HSSFSheet sheet1 = wb1.getSheetAt(0);
wb1.getWorkbook().findDrawingGroup();
DrawingManager2 dm1 = wb1.getWorkbook().getDrawingManager();
wb1.cloneSheet(0);
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
wb1.close();
wb2.getWorkbook().findDrawingGroup();
DrawingManager2 dm2 = wb2.getWorkbook().getDrawingManager();
//check EscherDggRecord - a workbook-level registry of drawing objects
assertEquals(dm1.getDgg().getMaxDrawingGroupId() + 1, dm2.getDgg().getMaxDrawingGroupId());
HSSFSheet sheet2 = wb2.getSheetAt(1);
//check that id of the drawing group was updated
EscherDgRecord dg1 = (EscherDgRecord) sheet1.getDrawingPatriarch().getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
EscherDgRecord dg2 = (EscherDgRecord) sheet2.getDrawingPatriarch().getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
int dg_id_1 = dg1.getOptions() >> 4;
int dg_id_2 = dg2.getOptions() >> 4;
assertEquals(dg_id_1 + 1, dg_id_2);
//TODO: check shapeId in the cloned sheet
wb2.close();
}
use of org.apache.poi.hssf.model.DrawingManager2 in project poi by apache.
the class HSSFSheet method getPatriarch.
private HSSFPatriarch getPatriarch(boolean createIfMissing) {
if (_patriarch != null) {
return _patriarch;
}
DrawingManager2 dm = _book.findDrawingGroup();
if (null == dm) {
if (!createIfMissing) {
return null;
} else {
_book.createDrawingGroup();
dm = _book.getDrawingManager();
}
}
EscherAggregate agg = (EscherAggregate) _sheet.findFirstRecordBySid(EscherAggregate.sid);
if (null == agg) {
int pos = _sheet.aggregateDrawingRecords(dm, false);
if (-1 == pos) {
if (createIfMissing) {
pos = _sheet.aggregateDrawingRecords(dm, true);
agg = (EscherAggregate) _sheet.getRecords().get(pos);
HSSFPatriarch patriarch = new HSSFPatriarch(this, agg);
patriarch.afterCreate();
return patriarch;
} else {
return null;
}
}
agg = (EscherAggregate) _sheet.getRecords().get(pos);
}
return new HSSFPatriarch(this, agg);
}
use of org.apache.poi.hssf.model.DrawingManager2 in project poi by apache.
the class HSSFPatriarch method afterCreate.
void afterCreate() {
DrawingManager2 drawingManager = _sheet.getWorkbook().getWorkbook().getDrawingManager();
short dgId = drawingManager.findNewDrawingGroupId();
_boundAggregate.setDgId(dgId);
_boundAggregate.setMainSpRecordId(newShapeId());
drawingManager.incrementDrawingsSaved();
}
Aggregations