Android Font Metrics

FontMetrics类源码:

/**
     * Class that describes the various metrics for a font at a given text size.
     * Remember, Y values increase going down, so those values will be positive,
     * and values that measure distances going up will be negative. This class
     * is returned by getFontMetrics().
     */
    public static class FontMetrics {
        /**
         * The maximum distance above the baseline for the tallest glyph in
         * the font at a given text size.
         */
        public float   top;
        /**
         * The recommended distance above the baseline for singled spaced text.
         */
        public float   ascent;
        /**
         * The recommended distance below the baseline for singled spaced text.
         */
        public float   descent;
        /**
         * The maximum distance below the baseline for the lowest glyph in
         * the font at a given text size.
         */
        public float   bottom;
        /**
         * The recommended additional space to add between lines of text.
         */
        public float   leading;
    }

FontMetrics类是Paint的内部类,主要定义了绘制字体相关的度量(参数):

Android Font Metrics_第1张图片
11.gif
Android Font Metrics_第2张图片
22.png

然而top和bottom都要比ascent和descent要更远离baseline,这种情况的原因是为了兼容诸如拉丁字符等字符。

其他的就是TextPaint中的各种方法用于设置绘制字体的各种属性。

坑:在drawtext时发现,颜色设置Paint.setColor如果是0x000000这样的rgb就不显示,必须设置成0x000000ff这样argb才可以。要么就是Color.argb(int,int,int,int)来取得颜色.

你可能感兴趣的:(Android Font Metrics)