Search in sources :

Example 56 with Rectangle2D

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

the class DrawBackground method draw.

@SuppressWarnings("rawtypes")
public void draw(Graphics2D graphics) {
    Dimension pg = shape.getSheet().getSlideShow().getPageSize();
    final Rectangle2D anchor = new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight());
    PlaceableShape<?, ?> ps = new PlaceableShape() {

        public ShapeContainer<?, ?> getParent() {
            return null;
        }

        public Rectangle2D getAnchor() {
            return anchor;
        }

        public void setAnchor(Rectangle2D newAnchor) {
        }

        public double getRotation() {
            return 0;
        }

        public void setRotation(double theta) {
        }

        public void setFlipHorizontal(boolean flip) {
        }

        public void setFlipVertical(boolean flip) {
        }

        public boolean getFlipHorizontal() {
            return false;
        }

        public boolean getFlipVertical() {
            return false;
        }

        public Sheet<?, ?> getSheet() {
            return shape.getSheet();
        }
    };
    DrawFactory drawFact = DrawFactory.getInstance(graphics);
    DrawPaint dp = drawFact.getPaint(ps);
    Paint fill = dp.getPaint(graphics, getShape().getFillStyle().getPaint());
    Rectangle2D anchor2 = getAnchor(graphics, anchor);
    if (fill != null) {
        graphics.setRenderingHint(Drawable.GRADIENT_SHAPE, anchor);
        graphics.setPaint(fill);
        graphics.fill(anchor2);
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Dimension(java.awt.Dimension) Paint(java.awt.Paint) PlaceableShape(org.apache.poi.sl.usermodel.PlaceableShape)

Example 57 with Rectangle2D

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

the class DrawPaint method createRadialGradientPaint.

protected Paint createRadialGradientPaint(GradientPaint fill, Graphics2D graphics) {
    Rectangle2D anchor = DrawShape.getAnchor(graphics, shape);
    Point2D pCenter = new Point2D.Double(anchor.getX() + anchor.getWidth() / 2, anchor.getY() + anchor.getHeight() / 2);
    float radius = (float) Math.max(anchor.getWidth(), anchor.getHeight());
    float[] fractions = fill.getGradientFractions();
    Color[] colors = new Color[fractions.length];
    int i = 0;
    for (ColorStyle fc : fill.getGradientColors()) {
        colors[i++] = applyColorTransform(fc);
    }
    return new RadialGradientPaint(pCenter, radius, fractions, colors);
}
Also used : Point2D(java.awt.geom.Point2D) ColorStyle(org.apache.poi.sl.usermodel.ColorStyle) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) RadialGradientPaint(java.awt.RadialGradientPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint)

Example 58 with Rectangle2D

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

the class DrawPictureShape method resize.

/**
     * Resize this picture to the default size.
     *
     * For PNG and JPEG resizes the image to 100%,
     * for other types, if the size can't be determined it will be 200x200 pixels.
     */
public void resize() {
    PictureShape<?, ?> ps = getShape();
    Dimension dim = ps.getPictureData().getImageDimension();
    Rectangle2D origRect = ps.getAnchor();
    double x = origRect.getX();
    double y = origRect.getY();
    double w = dim.getWidth();
    double h = dim.getHeight();
    ps.setAnchor(new Rectangle2D.Double(x, y, w, h));
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Dimension(java.awt.Dimension)

Example 59 with Rectangle2D

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

the class DrawPictureShape method drawContent.

@Override
public void drawContent(Graphics2D graphics) {
    PictureData data = getShape().getPictureData();
    if (data == null)
        return;
    Rectangle2D anchor = getAnchor(graphics, getShape());
    Insets insets = getShape().getClipping();
    try {
        ImageRenderer renderer = getImageRenderer(graphics, data.getContentType());
        renderer.loadImage(data.getData(), data.getContentType());
        renderer.drawImage(graphics, anchor, insets);
    } catch (IOException e) {
        LOG.log(POILogger.ERROR, "image can't be loaded/rendered.", e);
    }
}
Also used : Insets(java.awt.Insets) Rectangle2D(java.awt.geom.Rectangle2D) IOException(java.io.IOException) PictureData(org.apache.poi.sl.usermodel.PictureData)

Example 60 with Rectangle2D

use of java.awt.geom.Rectangle2D 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

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