Search in sources :

Example 26 with Rectangle2D

use of java.awt.geom.Rectangle2D in project android_frameworks_base by DirtyUnicorns.

the class BidiRenderer method render.

/**
     * Renders the text to the right of the bounds with the given font.
     * @param font The font to render the text with.
     */
private void render(int start, int limit, Font font, int flag, float[] advances, int advancesIndex, boolean draw) {
    FontRenderContext frc;
    if (mGraphics != null) {
        frc = mGraphics.getFontRenderContext();
    } else {
        frc = Toolkit.getDefaultToolkit().getFontMetrics(font).getFontRenderContext();
        // Metrics obtained this way don't have anti-aliasing set. So,
        // we create a new FontRenderContext with anti-aliasing set.
        frc = new FontRenderContext(font.getTransform(), mPaint.isAntiAliased(), frc.usesFractionalMetrics());
    }
    GlyphVector gv = font.layoutGlyphVector(frc, mText, start, limit, flag);
    int ng = gv.getNumGlyphs();
    int[] ci = gv.getGlyphCharIndices(0, ng, null);
    if (advances != null) {
        for (int i = 0; i < ng; i++) {
            int adv_idx = advancesIndex + ci[i];
            advances[adv_idx] += gv.getGlyphMetrics(i).getAdvanceX();
        }
    }
    if (draw && mGraphics != null) {
        mGraphics.drawGlyphVector(gv, mBounds.right, mBaseline);
    }
    // Update the bounds.
    Rectangle2D awtBounds = gv.getLogicalBounds();
    RectF bounds = awtRectToAndroidRect(awtBounds, mBounds.right, mBaseline);
    // coordinates from the bounds as an offset.
    if (Math.abs(mBounds.right - mBounds.left) == 0) {
        mBounds = bounds;
    } else {
        mBounds.union(bounds);
    }
}
Also used : GlyphVector(java.awt.font.GlyphVector) Rectangle2D(java.awt.geom.Rectangle2D) FontRenderContext(java.awt.font.FontRenderContext)

Example 27 with Rectangle2D

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

the class StyledSpaceAdvance method test.

static void test(int sz) {
    Font reg = new Font(name, Font.PLAIN, sz);
    Font bold = new Font(name, Font.BOLD, sz);
    //System.out.println("reg="+reg);
    //System.out.println("bold="+bold);
    FontRenderContext frc = new FontRenderContext(null, false, false);
    if (reg.getFontName(Locale.ENGLISH).equals(name) && bold.getFontName(Locale.ENGLISH).equals(name)) {
        Rectangle2D rb = reg.getStringBounds(" ", frc);
        Rectangle2D bb = bold.getStringBounds(" ", frc);
        if (bb.getWidth() > rb.getWidth() + 1.01f) {
            System.err.println("reg=" + reg + " bds = " + rb);
            System.err.println("bold=" + bold + " bds = " + bb);
            throw new RuntimeException("Advance difference too great.");
        }
    } else {
        System.out.println("Skipping test because fonts aren't as expected");
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) FontRenderContext(java.awt.font.FontRenderContext) Font(java.awt.Font)

Example 28 with Rectangle2D

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

the class Path2DCopyConstructor method testGetBounds.

static void testGetBounds(Path2D pathA, Path2D pathB) {
    final Rectangle rA = pathA.getBounds();
    final Rectangle rB = pathB.getBounds();
    if (!rA.equals(rB)) {
        throw new IllegalStateException("Bounds are not equals [" + rA + "|" + rB + "] !");
    }
    final Rectangle2D r2dA = pathA.getBounds2D();
    final Rectangle2D r2dB = pathB.getBounds2D();
    if (!equalsRectangle2D(r2dA, r2dB)) {
        throw new IllegalStateException("Bounds2D are not equals [" + r2dA + "|" + r2dB + "] !");
    }
    log("testGetBounds: passed.");
}
Also used : Rectangle(java.awt.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D)

Example 29 with Rectangle2D

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

the class ContainsTest method main.

public static void main(String[] args) throws Exception {
    CubicCurve2D c = new CubicCurve2D.Double(0, 0, 4, -4, -2, -4, 2, 0);
    Rectangle2D r = new Rectangle2D.Double(0.75, -2.5, 0.5, 2);
    if (c.contains(r)) {
        throw new Exception("The rectangle should not be contained in the curve");
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) CubicCurve2D(java.awt.geom.CubicCurve2D)

Example 30 with Rectangle2D

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

the class IntersectsTest method main.

public static void main(String[] args) throws Exception {
    CubicCurve2D c = new CubicCurve2D.Double(50.0, 300.0, 150.0, 166.6666717529297, 238.0, 456.66668701171875, 350.0, 300.0);
    Rectangle2D r = new Rectangle2D.Double(260, 300, 10, 10);
    if (!c.intersects(r)) {
        throw new Exception("The rectangle is contained. " + "intersects(Rectangle2D) should return true");
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) CubicCurve2D(java.awt.geom.CubicCurve2D)

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