@Override public HSLFGroupShape createGroup() { HSLFGroupShape s = new HSLFGroupShape(this); s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100)); addShape(s); return s; }
/** * Create a new ShapeGroup. This constructor is used when a new shape is created. * */ public HSLFGroupShape(){ this(null, null); createSpContainer(false); }
/** * Moves and scales this <code>ShapeGroup</code> to the specified anchor. */ protected void moveAndScale(Rectangle2D anchorDest){ Rectangle2D anchorSrc = getAnchor(); double scaleX = (anchorSrc.getWidth() == 0) ? 0 : anchorDest.getWidth() / anchorSrc.getWidth(); double scaleY = (anchorSrc.getHeight() == 0) ? 0 : anchorDest.getHeight() / anchorSrc.getHeight(); setExteriorAnchor(anchorDest); for (HSLFShape shape : getShapes()) { Rectangle2D chanchor = shape.getAnchor(); double x = anchorDest.getX()+(chanchor.getX()-anchorSrc.getX())*scaleX; double y = anchorDest.getY()+(chanchor.getY()-anchorSrc.getY())*scaleY; double width = chanchor.getWidth()*scaleX; double height = chanchor.getHeight()*scaleY; shape.setAnchor(new Rectangle2D.Double(x, y, width, height)); } }
@Override public void setAnchor(Rectangle2D anchor) { EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID); boolean isInitialized = !(clientAnchor.getDx1() == 0 && clientAnchor.getRow1() == 0); if (isInitialized) { moveAndScale(anchor); } else { setExteriorAnchor(anchor); } }
@Override public HSLFGroupShape createGroup() { HSLFGroupShape s = new HSLFGroupShape(); s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100)); addShape(s); return s; }
HSLFGroupShape group = new HSLFGroupShape(); group.setAnchor(bounds); group.setInteriorAnchor(new Rectangle(0, 0, 100, 100)); slide.addShape(group); Graphics2D graphics = new PPGraphics2D(group); graphics.draw(group.getInteriorAnchor()); graphics.drawString("Performance", x + 30, y + 10);
protected void setExteriorAnchor(Rectangle2D anchor) { EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID); //hack. internal variable EscherClientAnchorRecord.shortRecord can be //initialized only in fillFields(). We need to set shortRecord=false; byte[] header = new byte[16]; LittleEndian.putUShort(header, 0, 0); LittleEndian.putUShort(header, 2, 0); LittleEndian.putInt(header, 4, 8); clientAnchor.fillFields(header, 0, null); // All coordinates need to be converted to Master units (576 dpi) clientAnchor.setFlag((short)Units.pointsToMaster(anchor.getY())); clientAnchor.setCol1((short)Units.pointsToMaster(anchor.getX())); clientAnchor.setDx1((short)Units.pointsToMaster(anchor.getWidth() + anchor.getX())); clientAnchor.setRow1((short)Units.pointsToMaster(anchor.getHeight() + anchor.getY())); // TODO: does this make sense? setInteriorAnchor(anchor); }
@Override public HSLFPictureShape createPicture(PictureData pictureData) { if (!(pictureData instanceof HSLFPictureData)) { throw new IllegalArgumentException("pictureData needs to be of type HSLFPictureData"); } HSLFPictureShape s = new HSLFPictureShape((HSLFPictureData)pictureData, this); s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100)); addShape(s); return s; }
public static HSLFGroupShape createShapeGroup(EscherContainerRecord spContainer, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){ boolean isTable = false; EscherContainerRecord ecr = (EscherContainerRecord)spContainer.getChild(0); EscherRecord opt = HSLFShape.getEscherChild(ecr, RecordTypes.EscherUserDefined); if (opt != null) { EscherPropertyFactory f = new EscherPropertyFactory(); List<EscherProperty> props = f.createProperties( opt.serialize(), 8, opt.getInstance() ); for (EscherProperty ep : props) { if (ep.getPropertyNumber() == EscherProperties.GROUPSHAPE__TABLEPROPERTIES && ep instanceof EscherSimpleProperty && (((EscherSimpleProperty)ep).getPropertyValue() & 1) == 1) { isTable = true; break; } } } HSLFGroupShape group; if (isTable) { group = new HSLFTable(spContainer, parent); } else { group = new HSLFGroupShape(spContainer, parent); } return group; }
/** * Return type of the shape. * In most cases shape group type is {@link org.apache.poi.sl.usermodel.ShapeType#NOT_PRIMITIVE} * * @return type of the shape. */ @Override public ShapeType getShapeType(){ EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID); int nativeId = spRecord.getOptions() >> 4; return ShapeType.forId(nativeId, false); }
@Override public Iterator<HSLFShape> iterator() { return getShapes().iterator(); }
@Override protected void afterInsert(HSLFSheet sh){ super.afterInsert(sh); Set<HSLFLine> lineSet = new HashSet<>(); for (HSLFTableCell row[] : cells) { for (HSLFTableCell c : row) { addShape(c); for (HSLFLine bt : new HSLFLine[]{ c.borderTop, c.borderRight, c.borderBottom, c.borderLeft }) { if (bt != null) { lineSet.add(bt); } } } } for (HSLFLine l : lineSet) { addShape(l); } updateRowHeightsProperty(); }
@Override public HSLFObjectShape createOleShape(PictureData pictureData) { if (!(pictureData instanceof HSLFPictureData)) { throw new IllegalArgumentException("pictureData needs to be of type HSLFPictureData"); } HSLFObjectShape s = new HSLFObjectShape((HSLFPictureData)pictureData, this); s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100)); addShape(s); return s; } }
@Override public void setInteriorAnchor(Rectangle2D anchor){ EscherSpgrRecord spgr = getEscherChild(EscherSpgrRecord.RECORD_ID); int x1 = Units.pointsToMaster(anchor.getX()); int y1 = Units.pointsToMaster(anchor.getY()); int x2 = Units.pointsToMaster(anchor.getX() + anchor.getWidth()); int y2 = Units.pointsToMaster(anchor.getY() + anchor.getHeight()); spgr.setRectX1(x1); spgr.setRectY1(y1); spgr.setRectX2(x2); spgr.setRectY2(y2); }
@Override public HSLFConnectorShape createConnector() { HSLFConnectorShape s = new HSLFConnectorShape(this); s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100)); addShape(s); return s; }
@Override public Rectangle2D getInteriorAnchor(){ EscherSpgrRecord rec = getEscherChild(EscherSpgrRecord.RECORD_ID); double x1 = Units.masterToPoints(rec.getRectX1()); double y1 = Units.masterToPoints(rec.getRectY1()); double x2 = Units.masterToPoints(rec.getRectX2()); double y2 = Units.masterToPoints(rec.getRectY2()); return new Rectangle2D.Double(x1,y1,x2-x1,y2-y1); }
/** * Create a new ShapeGroup. This constructor is used when a new shape is created. * * @param parent the parent of the shape */ public HSLFGroupShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){ this(null, parent); createSpContainer(parent instanceof HSLFGroupShape); }
@Override public HSLFTable createTable(int numRows, int numCols) { if (numRows < 1 || numCols < 1) { throw new IllegalArgumentException("numRows and numCols must be greater than 0"); } HSLFTable s = new HSLFTable(numRows,numCols,this); s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100)); addShape(s); return s; }
/** * Returns the anchor (the bounding box rectangle) of this shape group. * All coordinates are expressed in points (72 dpi). * * @return the anchor of this shape group */ @Override public Rectangle2D getAnchor(){ EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID); int x1,y1,x2,y2; if(clientAnchor == null){ LOG.log(POILogger.INFO, "EscherClientAnchorRecord was not found for shape group. Searching for EscherChildAnchorRecord."); EscherChildAnchorRecord rec = getEscherChild(EscherChildAnchorRecord.RECORD_ID); x1 = rec.getDx1(); y1 = rec.getDy1(); x2 = rec.getDx2(); y2 = rec.getDy2(); } else { x1 = clientAnchor.getCol1(); y1 = clientAnchor.getFlag(); x2 = clientAnchor.getDx1(); y2 = clientAnchor.getRow1(); } return new Rectangle2D.Double( (x1 == -1 ? -1 : Units.masterToPoints(x1)), (y1 == -1 ? -1 : Units.masterToPoints(y1)), (x2 == -1 ? -1 : Units.masterToPoints(x2-x1)), (y2 == -1 ? -1 : Units.masterToPoints(y2-y1)) ); }
@Override public HSLFTextBox createTextBox() { HSLFTextBox s = new HSLFTextBox(this); s.setHorizontalCentered(true); s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100)); addShape(s); return s; }