use of java.awt.geom.Rectangle2D in project poi by apache.
the class XSLFFreeformShape method setPath.
@Override
public int setPath(Path2D.Double path) {
CTPath2D ctPath = CTPath2D.Factory.newInstance();
Rectangle2D bounds = path.getBounds2D();
int x0 = Units.toEMU(bounds.getX());
int y0 = Units.toEMU(bounds.getY());
PathIterator it = path.getPathIterator(new AffineTransform());
int numPoints = 0;
ctPath.setH(Units.toEMU(bounds.getHeight()));
ctPath.setW(Units.toEMU(bounds.getWidth()));
while (!it.isDone()) {
double[] vals = new double[6];
int type = it.currentSegment(vals);
switch(type) {
case PathIterator.SEG_MOVETO:
CTAdjPoint2D mv = ctPath.addNewMoveTo().addNewPt();
mv.setX(Units.toEMU(vals[0]) - x0);
mv.setY(Units.toEMU(vals[1]) - y0);
numPoints++;
break;
case PathIterator.SEG_LINETO:
CTAdjPoint2D ln = ctPath.addNewLnTo().addNewPt();
ln.setX(Units.toEMU(vals[0]) - x0);
ln.setY(Units.toEMU(vals[1]) - y0);
numPoints++;
break;
case PathIterator.SEG_QUADTO:
CTPath2DQuadBezierTo qbez = ctPath.addNewQuadBezTo();
CTAdjPoint2D qp1 = qbez.addNewPt();
qp1.setX(Units.toEMU(vals[0]) - x0);
qp1.setY(Units.toEMU(vals[1]) - y0);
CTAdjPoint2D qp2 = qbez.addNewPt();
qp2.setX(Units.toEMU(vals[2]) - x0);
qp2.setY(Units.toEMU(vals[3]) - y0);
numPoints += 2;
break;
case PathIterator.SEG_CUBICTO:
CTPath2DCubicBezierTo bez = ctPath.addNewCubicBezTo();
CTAdjPoint2D p1 = bez.addNewPt();
p1.setX(Units.toEMU(vals[0]) - x0);
p1.setY(Units.toEMU(vals[1]) - y0);
CTAdjPoint2D p2 = bez.addNewPt();
p2.setX(Units.toEMU(vals[2]) - x0);
p2.setY(Units.toEMU(vals[3]) - y0);
CTAdjPoint2D p3 = bez.addNewPt();
p3.setX(Units.toEMU(vals[4]) - x0);
p3.setY(Units.toEMU(vals[5]) - y0);
numPoints += 3;
break;
case PathIterator.SEG_CLOSE:
numPoints++;
ctPath.addNewClose();
break;
default:
throw new IllegalStateException("Unrecognized path segment type: " + type);
}
it.next();
}
XmlObject xo = getShapeProperties();
if (!(xo instanceof CTShapeProperties)) {
return -1;
}
((CTShapeProperties) xo).getCustGeom().getPathLst().setPathArray(new CTPath2D[] { ctPath });
setAnchor(bounds);
return numPoints;
}
use of java.awt.geom.Rectangle2D in project poi by apache.
the class HSLFPictureShape method afterInsert.
/**
* By default set the orininal image size
*/
@Override
protected void afterInsert(HSLFSheet sh) {
super.afterInsert(sh);
EscherBSERecord bse = getEscherBSERecord();
bse.setRef(bse.getRef() + 1);
Rectangle2D anchor = getAnchor();
if (anchor.isEmpty()) {
new DrawPictureShape(this).resize();
}
}
use of java.awt.geom.Rectangle2D in project poi by apache.
the class HSLFShape method moveTo.
/**
* Moves the top left corner of the shape to the specified point.
*
* @param x the x coordinate of the top left corner of the shape
* @param y the y coordinate of the top left corner of the shape
*/
public final void moveTo(double x, double y) {
// This convenience method should be implemented via setAnchor in subclasses
// see HSLFGroupShape.setAnchor() for a reference
Rectangle2D anchor = getAnchor();
anchor.setRect(x, y, anchor.getWidth(), anchor.getHeight());
setAnchor(anchor);
}
use of java.awt.geom.Rectangle2D in project poi by apache.
the class HSLFShape method getAnchor.
/**
* Returns the anchor (the bounding box rectangle) of this shape.
* All coordinates are expressed in points (72 dpi).
*
* @return the anchor of this shape
*/
@Override
public Rectangle2D getAnchor() {
EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
int flags = spRecord.getFlags();
int x1, y1, x2, y2;
EscherChildAnchorRecord childRec = getEscherChild(EscherChildAnchorRecord.RECORD_ID);
boolean useChildRec = ((flags & EscherSpRecord.FLAG_CHILD) != 0);
if (useChildRec && childRec != null) {
x1 = childRec.getDx1();
y1 = childRec.getDy1();
x2 = childRec.getDx2();
y2 = childRec.getDy2();
} else {
if (useChildRec) {
LOG.log(POILogger.WARN, "EscherSpRecord.FLAG_CHILD is set but EscherChildAnchorRecord was not found");
}
EscherClientAnchorRecord clientRec = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
x1 = clientRec.getCol1();
y1 = clientRec.getFlag();
x2 = clientRec.getDx1();
y2 = clientRec.getRow1();
}
// TODO: find out where this -1 value comes from at #57820 (link to ms docs?)
Rectangle2D anchor = 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)));
return anchor;
}
use of java.awt.geom.Rectangle2D in project poi by apache.
the class HSLFGroupShape method moveAndScale.
/**
* 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));
}
}
Aggregations