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);
}
}
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");
}
}
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.");
}
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");
}
}
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");
}
}
Aggregations