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