/** * Create a new ShapeGroup and create an instance of <code>EscherSpgrContainer</code> which * represents a group of shapes */ protected EscherContainerRecord createSpContainer(boolean isChild) { EscherContainerRecord spgr = new EscherContainerRecord(); spgr.setRecordId(EscherContainerRecord.SPGR_CONTAINER); spgr.setOptions((short) 15); // The group itself is a shape, and always appears as the first EscherSpContainer in the group // container. EscherContainerRecord spcont = new EscherContainerRecord(); spcont.setRecordId(EscherContainerRecord.SP_CONTAINER); spcont.setOptions((short) 15); EscherSpgrRecord spg = new EscherSpgrRecord(); spg.setOptions((short) 1); spcont.addChildRecord(spg); EscherSpRecord sp = new EscherSpRecord(); short type = (ShapeTypes.NotPrimitive << 4) + 2; sp.setOptions(type); sp.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_GROUP); spcont.addChildRecord(sp); EscherClientAnchorRecord anchor = new EscherClientAnchorRecord(); spcont.addChildRecord(anchor); spgr.addChildRecord(spcont); return spgr; }
/** * Create a new shape object used to create the escher records. * * @param hssfShape The simple shape this is based on. */ public static AbstractShape createShape(HSSFShape hssfShape, int shapeId) { AbstractShape shape; if (hssfShape instanceof HSSFComment) { shape = new CommentShape((HSSFComment) hssfShape, shapeId); } else if (hssfShape instanceof HSSFTextbox) { shape = new TextboxShape((HSSFTextbox) hssfShape, shapeId); } else if (hssfShape instanceof HSSFPolygon) { shape = new PolygonShape((HSSFPolygon) hssfShape, shapeId); } else if (hssfShape instanceof HSSFSimpleShape) { HSSFSimpleShape simpleShape = (HSSFSimpleShape) hssfShape; switch (simpleShape.getShapeType()) { case HSSFSimpleShape.OBJECT_TYPE_PICTURE: shape = new PictureShape(simpleShape, shapeId); break; case HSSFSimpleShape.OBJECT_TYPE_LINE: shape = new LineShape(simpleShape, shapeId); break; case HSSFSimpleShape.OBJECT_TYPE_OVAL: case HSSFSimpleShape.OBJECT_TYPE_RECTANGLE: shape = new SimpleFilledShape(simpleShape, shapeId); break; default: throw new IllegalArgumentException("Do not know how to handle this type of shape"); } } else { throw new IllegalArgumentException("Unknown shape type"); } EscherSpRecord sp = shape.getSpContainer().getChildById(EscherSpRecord.RECORD_ID); if (hssfShape.getParent() != null) sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_CHILD); return shape; }
/** * Return type of the shape. In most cases shape group type is {@link * org.apache.poi.hslf.model.ShapeTypes#NotPrimitive} * * @return type of the shape. */ public int getShapeType() { EscherContainerRecord groupInfoContainer = (EscherContainerRecord) _escherContainer.getChild(0); EscherSpRecord spRecord = groupInfoContainer.getChildById(EscherSpRecord.RECORD_ID); return spRecord.getOptions() >> 4; }