美文网首页我爱编程
Android Font Metrics

Android Font Metrics

作者: 星空下奔跑 | 来源:发表于2018-04-16 22:52 被阅读0次

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的内部类,主要定义了绘制字体相关的度量(参数):

11.gif 22.png

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

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

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

相关文章

网友评论

    本文标题:Android Font Metrics

    本文链接:https://www.haomeiwen.com/subject/jreykftx.html