Search in sources :

Example 1 with DecorationShape

use of org.apache.poi.sl.usermodel.LineDecoration.DecorationShape in project poi by apache.

the class XSLFSimpleShape method getLineTailDecoration.

/**
     * @return the line end decoration shape
     */
public DecorationShape getLineTailDecoration() {
    CTLineProperties ln = getLn(this, false);
    DecorationShape ds = DecorationShape.NONE;
    if (ln != null && ln.isSetTailEnd() && ln.getTailEnd().isSetType()) {
        ds = DecorationShape.fromOoxmlId(ln.getTailEnd().getType().intValue());
    }
    return ds;
}
Also used : CTLineProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties) DecorationShape(org.apache.poi.sl.usermodel.LineDecoration.DecorationShape)

Example 2 with DecorationShape

use of org.apache.poi.sl.usermodel.LineDecoration.DecorationShape in project poi by apache.

the class DrawSimpleShape method getHeadDecoration.

protected Outline getHeadDecoration(Graphics2D graphics, LineDecoration deco, BasicStroke stroke) {
    if (deco == null || stroke == null) {
        return null;
    }
    DecorationSize headLength = deco.getHeadLength();
    if (headLength == null) {
        headLength = DecorationSize.MEDIUM;
    }
    DecorationSize headWidth = deco.getHeadWidth();
    if (headWidth == null) {
        headWidth = DecorationSize.MEDIUM;
    }
    double lineWidth = Math.max(2.5, stroke.getLineWidth());
    Rectangle2D anchor = getAnchor(graphics, getShape());
    double x1 = anchor.getX(), y1 = anchor.getY();
    double alpha = Math.atan(anchor.getHeight() / anchor.getWidth());
    AffineTransform at = new AffineTransform();
    java.awt.Shape headShape = null;
    Path p = null;
    Rectangle2D bounds;
    final double scaleY = Math.pow(DECO_SIZE_POW, headWidth.ordinal() + 1.);
    final double scaleX = Math.pow(DECO_SIZE_POW, headLength.ordinal() + 1.);
    DecorationShape headShapeEnum = deco.getHeadShape();
    if (headShapeEnum == null) {
        return null;
    }
    switch(headShapeEnum) {
        case OVAL:
            p = new Path();
            headShape = new Ellipse2D.Double(0, 0, lineWidth * scaleX, lineWidth * scaleY);
            bounds = headShape.getBounds2D();
            at.translate(x1 - bounds.getWidth() / 2, y1 - bounds.getHeight() / 2);
            at.rotate(alpha, bounds.getX() + bounds.getWidth() / 2, bounds.getY() + bounds.getHeight() / 2);
            break;
        case STEALTH:
        case ARROW:
            p = new Path(false, true);
            Path2D.Double arrow = new Path2D.Double();
            arrow.moveTo((lineWidth * scaleX), (-lineWidth * scaleY / 2));
            arrow.lineTo(0, 0);
            arrow.lineTo((lineWidth * scaleX), (lineWidth * scaleY / 2));
            headShape = arrow;
            at.translate(x1, y1);
            at.rotate(alpha);
            break;
        case TRIANGLE:
            p = new Path();
            Path2D.Double triangle = new Path2D.Double();
            triangle.moveTo((lineWidth * scaleX), (-lineWidth * scaleY / 2));
            triangle.lineTo(0, 0);
            triangle.lineTo((lineWidth * scaleX), (lineWidth * scaleY / 2));
            triangle.closePath();
            headShape = triangle;
            at.translate(x1, y1);
            at.rotate(alpha);
            break;
        default:
            break;
    }
    if (headShape != null) {
        headShape = at.createTransformedShape(headShape);
    }
    return headShape == null ? null : new Outline(headShape, p);
}
Also used : Path(org.apache.poi.sl.draw.geom.Path) DecorationSize(org.apache.poi.sl.usermodel.LineDecoration.DecorationSize) Path2D(java.awt.geom.Path2D) Rectangle2D(java.awt.geom.Rectangle2D) Outline(org.apache.poi.sl.draw.geom.Outline) Ellipse2D(java.awt.geom.Ellipse2D) AffineTransform(java.awt.geom.AffineTransform) DecorationShape(org.apache.poi.sl.usermodel.LineDecoration.DecorationShape)

Example 3 with DecorationShape

use of org.apache.poi.sl.usermodel.LineDecoration.DecorationShape in project poi by apache.

the class XSLFSimpleShape method getLineHeadDecoration.

/**
     * @return the line end decoration shape
     */
public DecorationShape getLineHeadDecoration() {
    CTLineProperties ln = getLn(this, false);
    DecorationShape ds = DecorationShape.NONE;
    if (ln != null && ln.isSetHeadEnd() && ln.getHeadEnd().isSetType()) {
        ds = DecorationShape.fromOoxmlId(ln.getHeadEnd().getType().intValue());
    }
    return ds;
}
Also used : CTLineProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties) DecorationShape(org.apache.poi.sl.usermodel.LineDecoration.DecorationShape)

Example 4 with DecorationShape

use of org.apache.poi.sl.usermodel.LineDecoration.DecorationShape in project poi by apache.

the class DrawSimpleShape method getTailDecoration.

protected Outline getTailDecoration(Graphics2D graphics, LineDecoration deco, BasicStroke stroke) {
    if (deco == null || stroke == null) {
        return null;
    }
    DecorationSize tailLength = deco.getTailLength();
    if (tailLength == null) {
        tailLength = DecorationSize.MEDIUM;
    }
    DecorationSize tailWidth = deco.getTailWidth();
    if (tailWidth == null) {
        tailWidth = DecorationSize.MEDIUM;
    }
    double lineWidth = Math.max(2.5, stroke.getLineWidth());
    Rectangle2D anchor = getAnchor(graphics, getShape());
    double x2 = anchor.getX() + anchor.getWidth(), y2 = anchor.getY() + anchor.getHeight();
    double alpha = Math.atan(anchor.getHeight() / anchor.getWidth());
    AffineTransform at = new AffineTransform();
    java.awt.Shape tailShape = null;
    Path p = null;
    Rectangle2D bounds;
    final double scaleY = Math.pow(DECO_SIZE_POW, tailWidth.ordinal() + 1.);
    final double scaleX = Math.pow(DECO_SIZE_POW, tailLength.ordinal() + 1.);
    DecorationShape tailShapeEnum = deco.getTailShape();
    if (tailShapeEnum == null) {
        return null;
    }
    switch(tailShapeEnum) {
        case OVAL:
            p = new Path();
            tailShape = new Ellipse2D.Double(0, 0, lineWidth * scaleX, lineWidth * scaleY);
            bounds = tailShape.getBounds2D();
            at.translate(x2 - bounds.getWidth() / 2, y2 - bounds.getHeight() / 2);
            at.rotate(alpha, bounds.getX() + bounds.getWidth() / 2, bounds.getY() + bounds.getHeight() / 2);
            break;
        case STEALTH:
        case ARROW:
            p = new Path(false, true);
            Path2D.Double arrow = new Path2D.Double();
            arrow.moveTo((-lineWidth * scaleX), (-lineWidth * scaleY / 2));
            arrow.lineTo(0, 0);
            arrow.lineTo((-lineWidth * scaleX), (lineWidth * scaleY / 2));
            tailShape = arrow;
            at.translate(x2, y2);
            at.rotate(alpha);
            break;
        case TRIANGLE:
            p = new Path();
            Path2D.Double triangle = new Path2D.Double();
            triangle.moveTo((-lineWidth * scaleX), (-lineWidth * scaleY / 2));
            triangle.lineTo(0, 0);
            triangle.lineTo((-lineWidth * scaleX), (lineWidth * scaleY / 2));
            triangle.closePath();
            tailShape = triangle;
            at.translate(x2, y2);
            at.rotate(alpha);
            break;
        default:
            break;
    }
    if (tailShape != null) {
        tailShape = at.createTransformedShape(tailShape);
    }
    return tailShape == null ? null : new Outline(tailShape, p);
}
Also used : Path(org.apache.poi.sl.draw.geom.Path) DecorationSize(org.apache.poi.sl.usermodel.LineDecoration.DecorationSize) Path2D(java.awt.geom.Path2D) Rectangle2D(java.awt.geom.Rectangle2D) Outline(org.apache.poi.sl.draw.geom.Outline) Ellipse2D(java.awt.geom.Ellipse2D) AffineTransform(java.awt.geom.AffineTransform) DecorationShape(org.apache.poi.sl.usermodel.LineDecoration.DecorationShape)

Aggregations

DecorationShape (org.apache.poi.sl.usermodel.LineDecoration.DecorationShape)4 AffineTransform (java.awt.geom.AffineTransform)2 Ellipse2D (java.awt.geom.Ellipse2D)2 Path2D (java.awt.geom.Path2D)2 Rectangle2D (java.awt.geom.Rectangle2D)2 Outline (org.apache.poi.sl.draw.geom.Outline)2 Path (org.apache.poi.sl.draw.geom.Path)2 DecorationSize (org.apache.poi.sl.usermodel.LineDecoration.DecorationSize)2 CTLineProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties)2