TSpan.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { __extends } from "tslib";
  2. import Displayable from './Displayable.js';
  3. import { DEFAULT_PATH_STYLE } from './Path.js';
  4. import { createObject, defaults } from '../core/util.js';
  5. import { DEFAULT_FONT } from '../core/platform.js';
  6. import { tSpanCreateBoundingRect, tSpanHasStroke } from './helper/parseText.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. return tSpanHasStroke(this.style);
  23. };
  24. TSpan.prototype.hasFill = function () {
  25. var style = this.style;
  26. var fill = style.fill;
  27. return fill != null && fill !== 'none';
  28. };
  29. TSpan.prototype.createStyle = function (obj) {
  30. return createObject(DEFAULT_TSPAN_STYLE, obj);
  31. };
  32. TSpan.prototype.setBoundingRect = function (rect) {
  33. this._rect = rect;
  34. };
  35. TSpan.prototype.getBoundingRect = function () {
  36. if (!this._rect) {
  37. this._rect = tSpanCreateBoundingRect(this.style);
  38. }
  39. return this._rect;
  40. };
  41. TSpan.initDefaultProps = (function () {
  42. var tspanProto = TSpan.prototype;
  43. tspanProto.dirtyRectTolerance = 10;
  44. })();
  45. return TSpan;
  46. }(Displayable));
  47. TSpan.prototype.type = 'tspan';
  48. export default TSpan;