Search in sources :

Example 61 with Rectangle2D

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;
}
Also used : CTAdjPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D) CTPath2DCubicBezierTo(org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DCubicBezierTo) CTPath2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPath2D) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) PathIterator(java.awt.geom.PathIterator) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform) XmlObject(org.apache.xmlbeans.XmlObject) CTPath2DQuadBezierTo(org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DQuadBezierTo)

Example 62 with Rectangle2D

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();
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) DrawPictureShape(org.apache.poi.sl.draw.DrawPictureShape) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 63 with Rectangle2D

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);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D)

Example 64 with Rectangle2D

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;
}
Also used : EscherChildAnchorRecord(org.apache.poi.ddf.EscherChildAnchorRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord) Rectangle2D(java.awt.geom.Rectangle2D)

Example 65 with Rectangle2D

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));
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D)

Aggregations

Rectangle2D (java.awt.geom.Rectangle2D)262 Graphics2D (java.awt.Graphics2D)42 AffineTransform (java.awt.geom.AffineTransform)34 Color (java.awt.Color)33 Paint (java.awt.Paint)28 Point2D (java.awt.geom.Point2D)26 BufferedImage (java.awt.image.BufferedImage)23 Font (java.awt.Font)21 FontMetrics (java.awt.FontMetrics)20 Dimension (java.awt.Dimension)19 RoundRectangle2D (java.awt.geom.RoundRectangle2D)18 Rectangle (java.awt.Rectangle)16 FontRenderContext (java.awt.font.FontRenderContext)15 Point (java.awt.Point)11 BasicStroke (java.awt.BasicStroke)10 ArrayList (java.util.ArrayList)10 GradientPaint (java.awt.GradientPaint)9 TextLayout (java.awt.font.TextLayout)9 RadialGradientPaint (java.awt.RadialGradientPaint)8 Shape (java.awt.Shape)7