Search in sources :

Example 71 with AffineTransform

use of java.awt.geom.AffineTransform in project poi by apache.

the class DrawSheet method draw.

@Override
public void draw(Graphics2D graphics) {
    Dimension dim = sheet.getSlideShow().getPageSize();
    Color whiteTrans = new Color(1f, 1f, 1f, 0f);
    graphics.setColor(whiteTrans);
    graphics.fillRect(0, 0, (int) dim.getWidth(), (int) dim.getHeight());
    DrawFactory drawFact = DrawFactory.getInstance(graphics);
    MasterSheet<?, ?> master = sheet.getMasterSheet();
    if (sheet.getFollowMasterGraphics() && master != null) {
        Drawable drawer = drawFact.getDrawable(master);
        drawer.draw(graphics);
    }
    graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, new AffineTransform());
    for (Shape<?, ?> shape : sheet.getShapes()) {
        if (!canDraw(graphics, shape)) {
            continue;
        }
        // remember the initial transform and restore it after we are done with drawing
        AffineTransform at = graphics.getTransform();
        // concrete implementations can make sense of this hint,
        // for example PSGraphics2D or PDFGraphics2D would call gsave() / grestore
        graphics.setRenderingHint(Drawable.GSAVE, true);
        // apply rotation and flipping
        Drawable drawer = drawFact.getDrawable(shape);
        drawer.applyTransform(graphics);
        // draw stuff
        drawer.draw(graphics);
        // restore the coordinate system
        graphics.setTransform(at);
        graphics.setRenderingHint(Drawable.GRESTORE, true);
    }
}
Also used : Color(java.awt.Color) AffineTransform(java.awt.geom.AffineTransform) Dimension(java.awt.Dimension)

Example 72 with AffineTransform

use of java.awt.geom.AffineTransform 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 73 with AffineTransform

use of java.awt.geom.AffineTransform in project poi by apache.

the class BitmapImageRenderer method getImage.

@Override
public BufferedImage getImage(Dimension dim) {
    double w_old = img.getWidth();
    double h_old = img.getHeight();
    BufferedImage scaled = new BufferedImage((int) w_old, (int) h_old, BufferedImage.TYPE_INT_ARGB);
    double w_new = dim.getWidth();
    double h_new = dim.getHeight();
    AffineTransform at = new AffineTransform();
    at.scale(w_new / w_old, h_new / h_old);
    AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
    scaleOp.filter(img, scaled);
    return scaled;
}
Also used : AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage) AffineTransformOp(java.awt.image.AffineTransformOp)

Example 74 with AffineTransform

use of java.awt.geom.AffineTransform in project poi by apache.

the class BitmapImageRenderer method drawImage.

@Override
public boolean drawImage(Graphics2D graphics, Rectangle2D anchor, Insets clip) {
    if (img == null)
        return false;
    boolean isClipped = true;
    if (clip == null) {
        isClipped = false;
        clip = new Insets(0, 0, 0, 0);
    }
    int iw = img.getWidth();
    int ih = img.getHeight();
    double cw = (100000 - clip.left - clip.right) / 100000.0;
    double ch = (100000 - clip.top - clip.bottom) / 100000.0;
    double sx = anchor.getWidth() / (iw * cw);
    double sy = anchor.getHeight() / (ih * ch);
    double tx = anchor.getX() - (iw * sx * clip.left / 100000.0);
    double ty = anchor.getY() - (ih * sy * clip.top / 100000.0);
    AffineTransform at = new AffineTransform(sx, 0, 0, sy, tx, ty);
    Shape clipOld = graphics.getClip();
    if (isClipped)
        graphics.clip(anchor.getBounds2D());
    graphics.drawRenderedImage(img, at);
    graphics.setClip(clipOld);
    return true;
}
Also used : Insets(java.awt.Insets) Shape(java.awt.Shape) AffineTransform(java.awt.geom.AffineTransform)

Example 75 with AffineTransform

use of java.awt.geom.AffineTransform in project poi by apache.

the class DrawGroupShape method draw.

public void draw(Graphics2D graphics) {
    // the coordinate system of this group of shape
    Rectangle2D interior = getShape().getInteriorAnchor();
    // anchor of this group relative to the parent shape
    Rectangle2D exterior = getShape().getAnchor();
    AffineTransform tx = (AffineTransform) graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
    AffineTransform tx0 = new AffineTransform(tx);
    double scaleX = interior.getWidth() == 0. ? 1.0 : exterior.getWidth() / interior.getWidth();
    double scaleY = interior.getHeight() == 0. ? 1.0 : exterior.getHeight() / interior.getHeight();
    tx.translate(exterior.getX(), exterior.getY());
    tx.scale(scaleX, scaleY);
    tx.translate(-interior.getX(), -interior.getY());
    DrawFactory drawFact = DrawFactory.getInstance(graphics);
    AffineTransform at2 = graphics.getTransform();
    for (Shape<?, ?> child : getShape()) {
        // remember the initial transform and restore it after we are done with the drawing
        AffineTransform at = graphics.getTransform();
        graphics.setRenderingHint(Drawable.GSAVE, true);
        Drawable draw = drawFact.getDrawable(child);
        draw.applyTransform(graphics);
        draw.draw(graphics);
        // restore the coordinate system
        graphics.setTransform(at);
        graphics.setRenderingHint(Drawable.GRESTORE, true);
    }
    graphics.setTransform(at2);
    graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx0);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform)

Aggregations

AffineTransform (java.awt.geom.AffineTransform)370 BufferedImage (java.awt.image.BufferedImage)60 Graphics2D (java.awt.Graphics2D)54 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)42 Rectangle2D (java.awt.geom.Rectangle2D)40 Point2D (java.awt.geom.Point2D)28 Shape (java.awt.Shape)24 Font (java.awt.Font)23 Paint (java.awt.Paint)23 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)20 ArrayList (java.util.ArrayList)18 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)17 Rectangle (java.awt.Rectangle)16 PathIterator (java.awt.geom.PathIterator)16 Color (java.awt.Color)15 Point (java.awt.Point)15 FontRenderContext (java.awt.font.FontRenderContext)15 Area (java.awt.geom.Area)14 GeneralPath (java.awt.geom.GeneralPath)14 AffineTransformOp (java.awt.image.AffineTransformOp)13