12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- var Displayable = require("./Displayable");
- var zrUtil = require("../core/util");
- var textContain = require("../contain/text");
- var textHelper = require("./helper/text");
- var _constant = require("./constant");
- var ContextCachedBy = _constant.ContextCachedBy;
- var Text = function (opts) {
-
- Displayable.call(this, opts);
- };
- Text.prototype = {
- constructor: Text,
- type: 'text',
- brush: function (ctx, prevEl) {
- var style = this.style;
- this.__dirty && textHelper.normalizeTextStyle(style, true);
- style.fill = style.stroke = style.shadowBlur = style.shadowColor = style.shadowOffsetX = style.shadowOffsetY = null;
- var text = style.text;
- text != null && (text += '');
-
-
-
- if (!textHelper.needDrawText(text, style)) {
-
-
- ctx.__attrCachedBy = ContextCachedBy.NONE;
- return;
- }
- this.setTransform(ctx);
- textHelper.renderText(this, ctx, text, style, null, prevEl);
- this.restoreTransform(ctx);
- },
- getBoundingRect: function () {
- var style = this.style;
- this.__dirty && textHelper.normalizeTextStyle(style, true);
- if (!this._rect) {
- var text = style.text;
- text != null ? text += '' : text = '';
- var rect = textContain.getBoundingRect(style.text + '', style.font, style.textAlign, style.textVerticalAlign, style.textPadding, style.textLineHeight, style.rich);
- rect.x += style.x || 0;
- rect.y += style.y || 0;
- if (textHelper.getStroke(style.textStroke, style.textStrokeWidth)) {
- var w = style.textStrokeWidth;
- rect.x -= w / 2;
- rect.y -= w / 2;
- rect.width += w;
- rect.height += w;
- }
- this._rect = rect;
- }
- return this._rect;
- }
- };
- zrUtil.inherits(Text, Displayable);
- var _default = Text;
- module.exports = _default;
|