1 | import { __extends } from "tslib";
|
2 | import Displayable from './Displayable.js';
|
3 | import { getBoundingRect } from '../contain/text.js';
|
4 | import { DEFAULT_PATH_STYLE } from './Path.js';
|
5 | import { createObject, defaults } from '../core/util.js';
|
6 | import { DEFAULT_FONT } from '../core/platform.js';
|
7 | export var DEFAULT_TSPAN_STYLE = defaults({
|
8 | strokeFirst: true,
|
9 | font: DEFAULT_FONT,
|
10 | x: 0,
|
11 | y: 0,
|
12 | textAlign: 'left',
|
13 | textBaseline: 'top',
|
14 | miterLimit: 2
|
15 | }, DEFAULT_PATH_STYLE);
|
16 | var TSpan = (function (_super) {
|
17 | __extends(TSpan, _super);
|
18 | function TSpan() {
|
19 | return _super !== null && _super.apply(this, arguments) || this;
|
20 | }
|
21 | TSpan.prototype.hasStroke = function () {
|
22 | var style = this.style;
|
23 | var stroke = style.stroke;
|
24 | return stroke != null && stroke !== 'none' && style.lineWidth > 0;
|
25 | };
|
26 | TSpan.prototype.hasFill = function () {
|
27 | var style = this.style;
|
28 | var fill = style.fill;
|
29 | return fill != null && fill !== 'none';
|
30 | };
|
31 | TSpan.prototype.createStyle = function (obj) {
|
32 | return createObject(DEFAULT_TSPAN_STYLE, obj);
|
33 | };
|
34 | TSpan.prototype.setBoundingRect = function (rect) {
|
35 | this._rect = rect;
|
36 | };
|
37 | TSpan.prototype.getBoundingRect = function () {
|
38 | var style = this.style;
|
39 | if (!this._rect) {
|
40 | var text = style.text;
|
41 | text != null ? (text += '') : (text = '');
|
42 | var rect = getBoundingRect(text, style.font, style.textAlign, style.textBaseline);
|
43 | rect.x += style.x || 0;
|
44 | rect.y += style.y || 0;
|
45 | if (this.hasStroke()) {
|
46 | var w = style.lineWidth;
|
47 | rect.x -= w / 2;
|
48 | rect.y -= w / 2;
|
49 | rect.width += w;
|
50 | rect.height += w;
|
51 | }
|
52 | this._rect = rect;
|
53 | }
|
54 | return this._rect;
|
55 | };
|
56 | TSpan.initDefaultProps = (function () {
|
57 | var tspanProto = TSpan.prototype;
|
58 | tspanProto.dirtyRectTolerance = 10;
|
59 | })();
|
60 | return TSpan;
|
61 | }(Displayable));
|
62 | TSpan.prototype.type = 'tspan';
|
63 | export default TSpan;
|