[AppleScript] 纯文本查看 复制代码
public class MyView extends View {
private static final String TAG = "MyView";
public MyView(Context context) {
super(context);
}
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.RED);
paint.setTextSize(40);
Paint.FontMetrics fm = paint.getFontMetrics();
Log.d(TAG,"top = " + fm.top);
Log.d(TAG,"ascent = " + fm.ascent);
Log.d(TAG,"descent = " + fm.descent);
Log.d(TAG,"bottom = " + fm.bottom);
Log.d(TAG,"leading = " + fm.leading);
int textHeight = (int) (Math.ceil(fm.descent - fm.ascent) + 2);
Log.d(TAG,"textHeight = " + textHeight);
float lineWidth = 480.0f;
float baselineYStartPosition = 200.0f;
float offsetAscent = baselineYStartPosition + fm.ascent;
float offsetDescent = baselineYStartPosition + fm.descent;
float offsetTop = baselineYStartPosition + fm.top;
float offsetBottom = baselineYStartPosition + fm.bottom;
canvas.drawText("中文,AaBbPpQqGg", 0, baselineYStartPosition, paint);
paint.setColor(Color.GREEN);
canvas.drawLine(0, baselineYStartPosition, lineWidth, baselineYStartPosition, paint);//baseline
paint.setColor(Color.GRAY);
canvas.drawLine(0, offsetAscent, lineWidth, offsetAscent, paint);//ascent
canvas.drawLine(0, offsetDescent, lineWidth, offsetDescent, paint);//descent
canvas.drawLine(0, offsetTop, lineWidth, offsetTop, paint);//top
canvas.drawLine(0, offsetBottom, lineWidth, offsetBottom, paint);//bottom
}
}