Search in sources :

Example 6 with FontMetrics

use of android.graphics.Paint.FontMetrics in project Qblog_Android by qiaoyhh.

the class ColorTrackView method measureText.

private void measureText() {
    mTextWidth = (int) mPaint.measureText(mText);
    FontMetrics fm = mPaint.getFontMetrics();
    mTextHeight = (int) Math.ceil(fm.descent - fm.top);
    mPaint.getTextBounds(mText, 0, mText.length(), mTextBound);
    mTextHeight = mTextBound.height();
}
Also used : FontMetrics(android.graphics.Paint.FontMetrics)

Example 7 with FontMetrics

use of android.graphics.Paint.FontMetrics in project var3dframe by Var3D.

the class VAndroidLauncher method getFontPixmap.

public Pixmap getFontPixmap(String txt, FreePaint vpaint) {
    Paint paint = new Paint();
    if (!vpaint.getTTFName().equals("")) {
        // Typeface fontFace = fontFaces.get(vpaint.getTTFName());
        Typeface fontFace = Typeface.createFromAsset(getAssets(), vpaint.getTTFName() + (vpaint.getTTFName().endsWith(".ttf") ? "" : ".ttf"));
        fontFaces.put(vpaint.getTTFName(), fontFace);
        paint.setTypeface(fontFace);
    }
    paint.setAntiAlias(true);
    paint.setTextSize(vpaint.getTextSize());
    FontMetrics fm = paint.getFontMetrics();
    int w = (int) paint.measureText(txt);
    int h = (int) (fm.descent - fm.ascent);
    if (w == 0) {
        w = h = vpaint.getTextSize();
    }
    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    // 如果是描边类型
    if (vpaint.getStrokeColor() != null) {
        // 绘制外层
        paint.setColor(getColor(vpaint.getStrokeColor()));
        // 描边宽度
        paint.setStrokeWidth(vpaint.getStrokeWidth());
        // 描边种类
        paint.setStyle(Style.FILL_AND_STROKE);
        // 外层text采用粗体
        paint.setFakeBoldText(true);
        canvas.drawText(txt, 0, -fm.ascent, paint);
        paint.setFakeBoldText(false);
    } else {
        paint.setUnderlineText(vpaint.getUnderlineText());
        paint.setStrikeThruText(vpaint.getStrikeThruText());
        paint.setFakeBoldText(vpaint.getFakeBoldText());
    }
    // 绘制内层
    paint.setStrokeWidth(0);
    paint.setColor(getColor(vpaint.getColor()));
    canvas.drawText(txt, 0, -fm.ascent, paint);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 100, buffer);
    byte[] encodedData = buffer.toByteArray();
    Pixmap pixmap = new Pixmap(encodedData, 0, encodedData.length);
    bitmap = null;
    canvas = null;
    return pixmap;
}
Also used : Bitmap(android.graphics.Bitmap) Typeface(android.graphics.Typeface) FontMetrics(android.graphics.Paint.FontMetrics) Canvas(android.graphics.Canvas) FreePaint(var3d.net.center.freefont.FreePaint) Paint(android.graphics.Paint) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FreePaint(var3d.net.center.freefont.FreePaint) Paint(android.graphics.Paint) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 8 with FontMetrics

use of android.graphics.Paint.FontMetrics in project android_packages_apps_Settings by omnirom.

the class PaletteListPreference method getTextLineHeight.

private int getTextLineHeight(Context context) {
    final TextView tempView = new TextView(context);
    final FontMetrics fontMetrics = tempView.getPaint().getFontMetrics();
    return Math.round(fontMetrics.bottom - fontMetrics.top);
}
Also used : FontMetrics(android.graphics.Paint.FontMetrics) TextView(android.widget.TextView)

Aggregations

FontMetrics (android.graphics.Paint.FontMetrics)8 Paint (android.graphics.Paint)3 TextView (android.widget.TextView)2 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 RectF (android.graphics.RectF)1 Typeface (android.graphics.Typeface)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 TextMetrics (com.xenoage.utils.font.TextMetrics)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FreePaint (var3d.net.center.freefont.FreePaint)1