textStyle.js 1.5 KB
Newer Older
P
pah100 已提交
1
define(function (require) {
P
pah100 已提交
2

P
pah100 已提交
3
    var textContain = require('zrender/contain/text');
P
pah100 已提交
4
    var graphicUtil = require('../../util/graphic');
L
lang 已提交
5

P
pah100 已提交
6 7
    var PATH_COLOR = ['textStyle', 'color'];

P
pah100 已提交
8
    return {
L
lang 已提交
9 10
        /**
         * Get color property or get color from option.textStyle.color
S
sushuang 已提交
11
         * @param {boolean} [isEmphasis]
L
lang 已提交
12 13
         * @return {string}
         */
S
sushuang 已提交
14
        getTextColor: function (isEmphasis) {
L
lang 已提交
15 16
            var ecModel = this.ecModel;
            return this.getShallow('color')
S
tweak  
sushuang 已提交
17
                || (
S
sushuang 已提交
18
                    (!isEmphasis && ecModel) ? ecModel.get(PATH_COLOR) : null
S
tweak  
sushuang 已提交
19
                );
L
lang 已提交
20 21 22 23 24 25
        },

        /**
         * Create font string from fontStyle, fontWeight, fontSize, fontFamily
         * @return {string}
         */
P
pah100 已提交
26
        getFont: function () {
P
pah100 已提交
27 28 29 30 31 32
            return graphicUtil.getFont({
                fontStyle: this.getShallow('fontStyle'),
                fontWeight: this.getShallow('fontWeight'),
                fontSize: this.getShallow('fontSize'),
                fontFamily: this.getShallow('fontFamily')
            }, this.ecModel);
P
pah100 已提交
33
        },
P
pah100 已提交
34

P
pah100 已提交
35
        getTextRect: function (text) {
P
pah100 已提交
36
            return textContain.getBoundingRect(
P
pah100 已提交
37 38
                text,
                this.getFont(),
39
                this.getShallow('align'),
S
sushuang 已提交
40 41 42 43
                this.getShallow('verticalAlign') || this.getShallow('baseline'),
                this.getShallow('padding'),
                this.getShallow('rich'),
                this.getShallow('truncateText')
P
pah100 已提交
44
            );
P
pah100 已提交
45 46
        }
    };
L
lang 已提交
47
});