Skip to content

Commit

Permalink
add function for text
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovilia committed Jun 12, 2018
1 parent bbf2ea2 commit ca1b5da
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/graphic/helper/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
each,
normalizeCssArray,
isString,
isObject
isObject,
isFunction
} from '../../core/util';
import * as textContain from '../../contain/text';
import * as roundRectHelper from './roundRect';
Expand Down Expand Up @@ -252,6 +253,7 @@ function applyTextRotation(ctx, style, rect, x, y) {

function placeToken(hostEl, ctx, token, style, lineHeight, lineTop, x, textAlign) {
var tokenStyle = style.rich[token.styleName] || {};
tokenStyle.text = token.text;

// 'ctx.textBaseline' is always set as 'middle', for sake of
// the bias of "Microsoft YaHei".
Expand Down Expand Up @@ -317,7 +319,7 @@ function needDrawBackground(style) {
|| (style.textBorderWidth && style.textBorderColor);
}

// style: {textBackgroundColor, textBorderWidth, textBorderColor, textBorderRadius}
// style: {textBackgroundColor, textBorderWidth, textBorderColor, textBorderRadius, text}
// shape: {x, y, width, height}
function drawBackground(hostEl, ctx, style, x, y, width, height) {
var textBackgroundColor = style.textBackgroundColor;
Expand Down Expand Up @@ -348,6 +350,10 @@ function drawBackground(hostEl, ctx, style, x, y, width, height) {
setCtx(ctx, 'fillStyle', textBackgroundColor);
ctx.fill();
}
else if (isFunction(textBackgroundColor)) {
setCtx(ctx, 'fillStyle', textBackgroundColor(style));
ctx.fill();
}
else if (isObject(textBackgroundColor)) {
var image = textBackgroundColor.image;

Expand Down

0 comments on commit ca1b5da

Please sign in to comment.