TextNode.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. var __values = (this && this.__values) || function(o) {
  18. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  19. if (m) return m.call(o);
  20. if (o && typeof o.length === "number") return {
  21. next: function () {
  22. if (o && i >= o.length) o = void 0;
  23. return { value: o && o[i++], done: !o };
  24. }
  25. };
  26. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  27. };
  28. var __read = (this && this.__read) || function (o, n) {
  29. var m = typeof Symbol === "function" && o[Symbol.iterator];
  30. if (!m) return o;
  31. var i = m.call(o), r, ar = [], e;
  32. try {
  33. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  34. }
  35. catch (error) { e = { error: error }; }
  36. finally {
  37. try {
  38. if (r && !r.done && (m = i["return"])) m.call(i);
  39. }
  40. finally { if (e) throw e.error; }
  41. }
  42. return ar;
  43. };
  44. Object.defineProperty(exports, "__esModule", { value: true });
  45. exports.CommonTextNodeMixin = void 0;
  46. function CommonTextNodeMixin(Base) {
  47. return (function (_super) {
  48. __extends(class_1, _super);
  49. function class_1() {
  50. return _super !== null && _super.apply(this, arguments) || this;
  51. }
  52. class_1.prototype.computeBBox = function (bbox, _recompute) {
  53. var e_1, _a;
  54. if (_recompute === void 0) { _recompute = false; }
  55. var variant = this.parent.variant;
  56. var text = this.node.getText();
  57. if (variant === '-explicitFont') {
  58. var font = this.jax.getFontData(this.parent.styles);
  59. var _b = this.jax.measureText(text, variant, font), w = _b.w, h = _b.h, d = _b.d;
  60. bbox.h = h;
  61. bbox.d = d;
  62. bbox.w = w;
  63. }
  64. else {
  65. var chars = this.remappedText(text, variant);
  66. bbox.empty();
  67. try {
  68. for (var chars_1 = __values(chars), chars_1_1 = chars_1.next(); !chars_1_1.done; chars_1_1 = chars_1.next()) {
  69. var char = chars_1_1.value;
  70. var _c = __read(this.getVariantChar(variant, char), 4), h = _c[0], d = _c[1], w = _c[2], data = _c[3];
  71. if (data.unknown) {
  72. var cbox = this.jax.measureText(String.fromCodePoint(char), variant);
  73. w = cbox.w;
  74. h = cbox.h;
  75. d = cbox.d;
  76. }
  77. bbox.w += w;
  78. if (h > bbox.h)
  79. bbox.h = h;
  80. if (d > bbox.d)
  81. bbox.d = d;
  82. bbox.ic = data.ic || 0;
  83. bbox.sk = data.sk || 0;
  84. bbox.dx = data.dx || 0;
  85. }
  86. }
  87. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  88. finally {
  89. try {
  90. if (chars_1_1 && !chars_1_1.done && (_a = chars_1.return)) _a.call(chars_1);
  91. }
  92. finally { if (e_1) throw e_1.error; }
  93. }
  94. if (chars.length > 1) {
  95. bbox.sk = 0;
  96. }
  97. bbox.clean();
  98. }
  99. };
  100. class_1.prototype.remappedText = function (text, variant) {
  101. var c = this.parent.stretch.c;
  102. return (c ? [c] : this.parent.remapChars(this.unicodeChars(text, variant)));
  103. };
  104. class_1.prototype.getStyles = function () { };
  105. class_1.prototype.getVariant = function () { };
  106. class_1.prototype.getScale = function () { };
  107. class_1.prototype.getSpace = function () { };
  108. return class_1;
  109. }(Base));
  110. }
  111. exports.CommonTextNodeMixin = CommonTextNodeMixin;
  112. //# sourceMappingURL=TextNode.js.map