Example usage for android.graphics Paint getTextPath

List of usage examples for android.graphics Paint getTextPath

Introduction

In this page you can find the example usage for android.graphics Paint getTextPath.

Prototype

public void getTextPath(String text, int start, int end, float x, float y, Path path) 

Source Link

Document

Return the path (outline) for the specified text.

Usage

From source file:com.codegarden.nativenavigation.JuceActivity.java

public final int[] renderGlyph(char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) {
    Path p = new Path();
    paint.getTextPath(String.valueOf(glyph), 0, 1, 0.0f, 0.0f, p);

    RectF boundsF = new RectF();
    p.computeBounds(boundsF, true);/*from ww w.  j a  va2  s  . co m*/
    matrix.mapRect(boundsF);

    boundsF.roundOut(bounds);
    bounds.left--;
    bounds.right++;

    final int w = bounds.width();
    final int h = Math.max(1, bounds.height());

    Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(bm);
    matrix.postTranslate(-bounds.left, -bounds.top);
    c.setMatrix(matrix);
    c.drawPath(p, paint);

    final int sizeNeeded = w * h;
    if (cachedRenderArray.length < sizeNeeded)
        cachedRenderArray = new int[sizeNeeded];

    bm.getPixels(cachedRenderArray, 0, w, 0, 0, w, h);
    bm.recycle();
    return cachedRenderArray;
}

From source file:com.juce.JuceAppActivity.java

public final int[] renderGlyph (char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds)
{
    Path p = new Path();
    paint.getTextPath (String.valueOf (glyph), 0, 1, 0.0f, 0.0f, p);

    RectF boundsF = new RectF();
    p.computeBounds (boundsF, true);//from w ww  . ja  va 2 s . c o m
    matrix.mapRect (boundsF);

    boundsF.roundOut (bounds);
    bounds.left--;
    bounds.right++;

    final int w = bounds.width();
    final int h = Math.max (1, bounds.height());

    Bitmap bm = Bitmap.createBitmap (w, h, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas (bm);
    matrix.postTranslate (-bounds.left, -bounds.top);
    c.setMatrix (matrix);
    c.drawPath (p, paint);

    final int sizeNeeded = w * h;
    if (cachedRenderArray.length < sizeNeeded)
        cachedRenderArray = new int [sizeNeeded];

    bm.getPixels (cachedRenderArray, 0, w, 0, 0, w, h);
    bm.recycle();
    return cachedRenderArray;
}