Search in sources :

Example 76 with Rectangle2D

use of java.awt.geom.Rectangle2D in project jdk8u_jdk by JetBrains.

the class Rectangle method createIntersection.

/**
     * {@inheritDoc}
     * @since 1.2
     */
public Rectangle2D createIntersection(Rectangle2D r) {
    if (r instanceof Rectangle) {
        return intersection((Rectangle) r);
    }
    Rectangle2D dest = new Rectangle2D.Double();
    Rectangle2D.intersect(this, r, dest);
    return dest;
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D)

Example 77 with Rectangle2D

use of java.awt.geom.Rectangle2D in project jdk8u_jdk by JetBrains.

the class Rectangle method createUnion.

/**
     * {@inheritDoc}
     * @since 1.2
     */
public Rectangle2D createUnion(Rectangle2D r) {
    if (r instanceof Rectangle) {
        return union((Rectangle) r);
    }
    Rectangle2D dest = new Rectangle2D.Double();
    Rectangle2D.union(this, r, dest);
    return dest;
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D)

Example 78 with Rectangle2D

use of java.awt.geom.Rectangle2D in project jdk8u_jdk by JetBrains.

the class GlyphVector method getPixelBounds.

/**
     * Returns the pixel bounds of this <code>GlyphVector</code> when
     * rendered in a graphics with the given
     * <code>FontRenderContext</code> at the given location.  The
     * renderFRC need not be the same as the
     * <code>FontRenderContext</code> of this
     * <code>GlyphVector</code>, and can be null.  If it is null, the
     * <code>FontRenderContext</code> of this <code>GlyphVector</code>
     * is used.  The default implementation returns the visual bounds,
     * offset to x, y and rounded out to the next integer value (i.e. returns an
     * integer rectangle which encloses the visual bounds) and
     * ignores the FRC.  Subclassers should override this method.
     * @param renderFRC the <code>FontRenderContext</code> of the <code>Graphics</code>.
     * @param x the x-coordinate at which to render this <code>GlyphVector</code>.
     * @param y the y-coordinate at which to render this <code>GlyphVector</code>.
     * @return a <code>Rectangle</code> bounding the pixels that would be affected.
     * @since 1.4
     */
public Rectangle getPixelBounds(FontRenderContext renderFRC, float x, float y) {
    Rectangle2D rect = getVisualBounds();
    int l = (int) Math.floor(rect.getX() + x);
    int t = (int) Math.floor(rect.getY() + y);
    int r = (int) Math.ceil(rect.getMaxX() + x);
    int b = (int) Math.ceil(rect.getMaxY() + y);
    return new Rectangle(l, t, r - l, b - t);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Rectangle(java.awt.Rectangle)

Example 79 with Rectangle2D

use of java.awt.geom.Rectangle2D in project jdk8u_jdk by JetBrains.

the class BufferedPaints method setTexturePaint.

/************************** TexturePaint support ****************************/
/**
     * We use OpenGL's texture coordinate generator to automatically
     * map the TexturePaint image to the geometry being rendered.  The
     * generator uses two separate plane equations that take the (x,y)
     * location (in device space) of the fragment being rendered to
     * calculate (u,v) texture coordinates for that fragment:
     *     u = Ax + By + Cz + Dw
     *     v = Ex + Fy + Gz + Hw
     *
     * Since we use a 2D orthographic projection, we can assume that z=0
     * and w=1 for any fragment.  So we need to calculate appropriate
     * values for the plane equation constants (A,B,D) and (E,F,H) such
     * that {u,v}=0 for the top-left of the TexturePaint's anchor
     * rectangle and {u,v}=1 for the bottom-right of the anchor rectangle.
     * We can easily make the texture image repeat for {u,v} values
     * outside the range [0,1] by specifying the GL_REPEAT texture wrap
     * mode.
     *
     * Calculating the plane equation constants is surprisingly simple.
     * We can think of it as an inverse matrix operation that takes
     * device space coordinates and transforms them into user space
     * coordinates that correspond to a location relative to the anchor
     * rectangle.  First, we translate and scale the current user space
     * transform by applying the anchor rectangle bounds.  We then take
     * the inverse of this affine transform.  The rows of the resulting
     * inverse matrix correlate nicely to the plane equation constants
     * we were seeking.
     */
private static void setTexturePaint(RenderQueue rq, SunGraphics2D sg2d, TexturePaint paint, boolean useMask) {
    BufferedImage bi = paint.getImage();
    SurfaceData dstData = sg2d.surfaceData;
    SurfaceData srcData = dstData.getSourceSurfaceData(bi, SunGraphics2D.TRANSFORM_ISIDENT, CompositeType.SrcOver, null);
    boolean filter = (sg2d.interpolationType != AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    // calculate plane equation constants
    AffineTransform at = (AffineTransform) sg2d.transform.clone();
    Rectangle2D anchor = paint.getAnchorRect();
    at.translate(anchor.getX(), anchor.getY());
    at.scale(anchor.getWidth(), anchor.getHeight());
    double xp0, xp1, xp3, yp0, yp1, yp3;
    try {
        at.invert();
        xp0 = at.getScaleX();
        xp1 = at.getShearX();
        xp3 = at.getTranslateX();
        yp0 = at.getShearY();
        yp1 = at.getScaleY();
        yp3 = at.getTranslateY();
    } catch (java.awt.geom.NoninvertibleTransformException e) {
        xp0 = xp1 = xp3 = yp0 = yp1 = yp3 = 0.0;
    }
    // assert rq.lock.isHeldByCurrentThread();
    rq.ensureCapacityAndAlignment(68, 12);
    RenderBuffer buf = rq.getBuffer();
    buf.putInt(SET_TEXTURE_PAINT);
    buf.putInt(useMask ? 1 : 0);
    buf.putInt(filter ? 1 : 0);
    buf.putLong(srcData.getNativeOps());
    buf.putDouble(xp0).putDouble(xp1).putDouble(xp3);
    buf.putDouble(yp0).putDouble(yp1).putDouble(yp3);
}
Also used : SurfaceData(sun.java2d.SurfaceData) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage)

Example 80 with Rectangle2D

use of java.awt.geom.Rectangle2D in project jdk8u_jdk by JetBrains.

the class PixelToParallelogramConverter method fill.

public void fill(SunGraphics2D sg2d, Shape s) {
    if (s instanceof Rectangle2D) {
        Rectangle2D r2d = (Rectangle2D) s;
        double w = r2d.getWidth();
        double h = r2d.getHeight();
        if (w > 0 && h > 0) {
            double x = r2d.getX();
            double y = r2d.getY();
            fillRectangle(sg2d, x, y, w, h);
        }
        return;
    }
    outpipe.fill(sg2d, s);
}
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