Search in sources :

Example 21 with Rectangle2D

use of java.awt.geom.Rectangle2D in project binnavi by google.

the class ZoomHelpers method getMinimumZoom.

/**
   * Calculates the smallest valid zoom level.
   * 
   * @return The smallest valid zoom level.
   */
public static double getMinimumZoom(final Graph2DView view) {
    double zoomlevel = view.getZoom();
    if (zoomlevel < 0) {
        zoomlevel = 1;
    }
    final Point2D viewPoint = view.getViewPoint2D();
    final Rectangle2D box = view.getGraph2D().getBoundingBox();
    // why? => to gain the
    view.zoomToArea(box.getX(), box.getY(), box.getWidth(), box.getHeight());
    // minimum zoom level
    // in the next line
    final double minZoom = view.getZoom();
    // why? => to reset the original zoom level after the minimum zoom
    view.setZoom(zoomlevel);
    // level was calulated
    // why? => to reset the original view
    view.setViewPoint2D(viewPoint.getX(), viewPoint.getY());
    // point
    return minZoom - (minZoom / 2);
}
Also used : Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D)

Example 22 with Rectangle2D

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

the class Path_Delegate method fillBounds.

/**
     * Fills the given {@link RectF} with the path bounds.
     * @param bounds the RectF to be filled.
     */
public void fillBounds(RectF bounds) {
    Rectangle2D rect = mPath.getBounds2D();
    bounds.left = (float) rect.getMinX();
    bounds.right = (float) rect.getMaxX();
    bounds.top = (float) rect.getMinY();
    bounds.bottom = (float) rect.getMaxY();
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D)

Example 23 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 24 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 25 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)

Aggregations

Rectangle2D (java.awt.geom.Rectangle2D)211 AffineTransform (java.awt.geom.AffineTransform)33 Graphics2D (java.awt.Graphics2D)24 Point2D (java.awt.geom.Point2D)24 BufferedImage (java.awt.image.BufferedImage)20 FontMetrics (java.awt.FontMetrics)19 RoundRectangle2D (java.awt.geom.RoundRectangle2D)17 Color (java.awt.Color)16 Dimension (java.awt.Dimension)15 Font (java.awt.Font)14 FontRenderContext (java.awt.font.FontRenderContext)13 Paint (java.awt.Paint)12 Rectangle (java.awt.Rectangle)9 GradientPaint (java.awt.GradientPaint)8 ArrayList (java.util.ArrayList)8 Shape (java.awt.Shape)7 TextLayout (java.awt.font.TextLayout)7 GeneralPath (java.awt.geom.GeneralPath)6 Line2D (java.awt.geom.Line2D)6 Test (org.junit.Test)6