in poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java [51:147]
public static void createShapeTree(EscherContainerRecord container, EscherAggregate agg, HSSFShapeContainer out, DirectoryNode root) {
if (container.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
ObjRecord obj = null;
EscherRecord child = container.getChild(0);
if (!(child instanceof EscherContainerRecord)) {
throw new IllegalArgumentException("Had unexpected type of child: " + child.getClass());
}
EscherClientDataRecord clientData = ((EscherContainerRecord) child).getChildById(EscherClientDataRecord.RECORD_ID);
if (null != clientData) {
Record record = agg.getShapeToObjMapping().get(clientData);
if (!(record instanceof ObjRecord)) {
throw new IllegalArgumentException("Had unexpected type of clientData: " + (record == null ? "<null>" : record.getClass()));
}
obj = (ObjRecord) record;
}
HSSFShapeGroup group = new HSSFShapeGroup(container, obj);
List<EscherContainerRecord> children = container.getChildContainers();
// skip the first child record, it is group descriptor
if (children.size() > 1) {
children.subList(1, children.size()).forEach(c -> createShapeTree(c, agg, group, root));
}
out.addShape(group);
} else if (container.getRecordId() == EscherContainerRecord.SP_CONTAINER) {
Map<EscherRecord, Record> shapeToObj = agg.getShapeToObjMapping();
ObjRecord objRecord = null;
TextObjectRecord txtRecord = null;
for (EscherRecord record : container) {
switch (EscherRecordTypes.forTypeID(record.getRecordId())) {
case CLIENT_DATA: {
Record subRecord = shapeToObj.get(record);
if (!(subRecord instanceof ObjRecord)) {
throw new RecordFormatException("Did not have a ObjRecord: " + subRecord);
}
objRecord = (ObjRecord) subRecord;
break;
}
case CLIENT_TEXTBOX: {
Record subRecord = shapeToObj.get(record);
if (!(subRecord instanceof TextObjectRecord)) {
throw new RecordFormatException("Did not have a TextObjRecord: " + subRecord);
}
txtRecord = (TextObjectRecord) subRecord;
break;
}
default:
break;
}
}
if (objRecord == null) {
throw new RecordFormatException("EscherClientDataRecord can't be found.");
}
if (isEmbeddedObject(objRecord)) {
HSSFObjectData objectData = new HSSFObjectData(container, objRecord, root);
out.addShape(objectData);
return;
}
CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord) objRecord.getSubRecords().get(0);
final HSSFShape shape;
switch (cmo.getObjectType()) {
case CommonObjectDataSubRecord.OBJECT_TYPE_PICTURE:
shape = new HSSFPicture(container, objRecord);
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_RECTANGLE:
shape = new HSSFSimpleShape(container, objRecord, txtRecord);
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_LINE:
shape = new HSSFSimpleShape(container, objRecord);
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_COMBO_BOX:
shape = new HSSFCombobox(container, objRecord);
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING:
EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID);
if(optRecord == null) {
shape = new HSSFSimpleShape(container, objRecord, txtRecord);
} else {
EscherProperty property = optRecord.lookup(EscherPropertyTypes.GEOMETRY__VERTICES);
if (null != property) {
shape = new HSSFPolygon(container, objRecord, txtRecord);
} else {
shape = new HSSFSimpleShape(container, objRecord, txtRecord);
}
}
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_TEXT:
shape = new HSSFTextbox(container, objRecord, txtRecord);
break;
case CommonObjectDataSubRecord.OBJECT_TYPE_COMMENT:
shape = new HSSFComment(container, objRecord, txtRecord, agg.getNoteRecordByObj(objRecord));
break;
default:
shape = new HSSFSimpleShape(container, objRecord, txtRecord);
}
out.addShape(shape);
}
}