Search in sources :

Example 86 with Rectangle2D

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

the class GraphicComponent method handleGetVisualBounds.

public Rectangle2D handleGetVisualBounds() {
    Rectangle2D bounds = graphic.getBounds();
    float width = (float) bounds.getWidth() + graphicAdvance * (graphicCount - 1);
    return new Rectangle2D.Float((float) bounds.getX(), (float) bounds.getY(), width, (float) bounds.getHeight());
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D)

Example 87 with Rectangle2D

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

the class GraphicComponent method handleGetCharVisualBounds.

public Rectangle2D handleGetCharVisualBounds(int index) {
    Rectangle2D bounds = graphic.getBounds();
    // don't modify their rectangle, just in case they don't copy
    Rectangle2D.Float charBounds = new Rectangle2D.Float();
    charBounds.setRect(bounds);
    charBounds.x += graphicAdvance * index;
    return charBounds;
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D)

Example 88 with Rectangle2D

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

the class StandardGlyphVector method getGlyphMetrics.

public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }
    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(), vb.getMinY() - pt.getY(), vb.getWidth(), vb.getHeight());
    Point2D.Float adv = getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y, vb, GlyphMetrics.STANDARD);
    return gm;
}
Also used : Point2D(java.awt.geom.Point2D) GlyphMetrics(java.awt.font.GlyphMetrics) Rectangle2D(java.awt.geom.Rectangle2D)

Example 89 with Rectangle2D

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

the class SunGraphics2D method validateCompClip.

protected void validateCompClip() {
    int origClipState = clipState;
    if (usrClip == null) {
        clipState = CLIP_DEVICE;
        clipRegion = devClip;
    } else if (usrClip instanceof Rectangle2D) {
        clipState = CLIP_RECTANGULAR;
        if (usrClip instanceof Rectangle) {
            clipRegion = devClip.getIntersection((Rectangle) usrClip);
        } else {
            clipRegion = devClip.getIntersection(usrClip.getBounds());
        }
    } else {
        PathIterator cpi = usrClip.getPathIterator(null);
        int[] box = new int[4];
        ShapeSpanIterator sr = LoopPipe.getFillSSI(this);
        try {
            sr.setOutputArea(devClip);
            sr.appendPath(cpi);
            sr.getPathBox(box);
            Region r = Region.getInstance(box);
            r.appendSpans(sr);
            clipRegion = r;
            clipState = r.isRectangular() ? CLIP_RECTANGULAR : CLIP_SHAPE;
        } finally {
            sr.dispose();
        }
    }
    if (origClipState != clipState && (clipState == CLIP_SHAPE || origClipState == CLIP_SHAPE)) {
        validFontInfo = false;
        invalidatePipe();
    }
}
Also used : ShapeSpanIterator(sun.java2d.pipe.ShapeSpanIterator) PathIterator(java.awt.geom.PathIterator) Rectangle2D(java.awt.geom.Rectangle2D) Rectangle(java.awt.Rectangle) Region(sun.java2d.pipe.Region) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint)

Example 90 with Rectangle2D

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

the class SunGraphics2D method intersectRectShape.

/*
     * Intersect a Rectangle with a Shape by the simplest method,
     * attempting to produce a simplified result.
     * The boolean arguments keep1 and keep2 specify whether or not
     * the first or second shapes can be modified during the operation
     * or whether that shape must be "kept" unmodified.
     */
Shape intersectRectShape(Rectangle2D r, Shape s, boolean keep1, boolean keep2) {
    if (s instanceof Rectangle2D) {
        Rectangle2D r2 = (Rectangle2D) s;
        Rectangle2D outrect;
        if (!keep1) {
            outrect = r;
        } else if (!keep2) {
            outrect = r2;
        } else {
            outrect = new Rectangle2D.Float();
        }
        double x1 = Math.max(r.getX(), r2.getX());
        double x2 = Math.min(r.getX() + r.getWidth(), r2.getX() + r2.getWidth());
        double y1 = Math.max(r.getY(), r2.getY());
        double y2 = Math.min(r.getY() + r.getHeight(), r2.getY() + r2.getHeight());
        if (((x2 - x1) < 0) || ((y2 - y1) < 0))
            // Width or height is negative. No intersection.
            outrect.setFrameFromDiagonal(0, 0, 0, 0);
        else
            outrect.setFrameFromDiagonal(x1, y1, x2, y2);
        return outrect;
    }
    if (r.contains(s.getBounds2D())) {
        if (keep2) {
            s = cloneShape(s);
        }
        return s;
    }
    return intersectByArea(r, s, keep1, keep2);
}
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