msubsup.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 __read = (this && this.__read) || function (o, n) {
  18. var m = typeof Symbol === "function" && o[Symbol.iterator];
  19. if (!m) return o;
  20. var i = m.call(o), r, ar = [], e;
  21. try {
  22. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  23. }
  24. catch (error) { e = { error: error }; }
  25. finally {
  26. try {
  27. if (r && !r.done && (m = i["return"])) m.call(i);
  28. }
  29. finally { if (e) throw e.error; }
  30. }
  31. return ar;
  32. };
  33. Object.defineProperty(exports, "__esModule", { value: true });
  34. exports.CommonMsubsupMixin = exports.CommonMsupMixin = exports.CommonMsubMixin = void 0;
  35. function CommonMsubMixin(Base) {
  36. var _a;
  37. return _a = (function (_super) {
  38. __extends(class_1, _super);
  39. function class_1() {
  40. return _super !== null && _super.apply(this, arguments) || this;
  41. }
  42. Object.defineProperty(class_1.prototype, "scriptChild", {
  43. get: function () {
  44. return this.childNodes[this.node.sub];
  45. },
  46. enumerable: false,
  47. configurable: true
  48. });
  49. class_1.prototype.getOffset = function () {
  50. return [0, -this.getV()];
  51. };
  52. return class_1;
  53. }(Base)),
  54. _a.useIC = false,
  55. _a;
  56. }
  57. exports.CommonMsubMixin = CommonMsubMixin;
  58. function CommonMsupMixin(Base) {
  59. return (function (_super) {
  60. __extends(class_2, _super);
  61. function class_2() {
  62. return _super !== null && _super.apply(this, arguments) || this;
  63. }
  64. Object.defineProperty(class_2.prototype, "scriptChild", {
  65. get: function () {
  66. return this.childNodes[this.node.sup];
  67. },
  68. enumerable: false,
  69. configurable: true
  70. });
  71. class_2.prototype.getOffset = function () {
  72. var x = this.getAdjustedIc() - (this.baseRemoveIc ? 0 : this.baseIc);
  73. return [x, this.getU()];
  74. };
  75. return class_2;
  76. }(Base));
  77. }
  78. exports.CommonMsupMixin = CommonMsupMixin;
  79. function CommonMsubsupMixin(Base) {
  80. var _a;
  81. return _a = (function (_super) {
  82. __extends(class_3, _super);
  83. function class_3() {
  84. var _this = _super !== null && _super.apply(this, arguments) || this;
  85. _this.UVQ = null;
  86. return _this;
  87. }
  88. Object.defineProperty(class_3.prototype, "subChild", {
  89. get: function () {
  90. return this.childNodes[this.node.sub];
  91. },
  92. enumerable: false,
  93. configurable: true
  94. });
  95. Object.defineProperty(class_3.prototype, "supChild", {
  96. get: function () {
  97. return this.childNodes[this.node.sup];
  98. },
  99. enumerable: false,
  100. configurable: true
  101. });
  102. class_3.prototype.computeBBox = function (bbox, recompute) {
  103. if (recompute === void 0) { recompute = false; }
  104. var basebox = this.baseChild.getOuterBBox();
  105. var _a = __read([this.subChild.getOuterBBox(), this.supChild.getOuterBBox()], 2), subbox = _a[0], supbox = _a[1];
  106. bbox.empty();
  107. bbox.append(basebox);
  108. var w = this.getBaseWidth();
  109. var x = this.getAdjustedIc();
  110. var _b = __read(this.getUVQ(), 2), u = _b[0], v = _b[1];
  111. bbox.combine(subbox, w, v);
  112. bbox.combine(supbox, w + x, u);
  113. bbox.w += this.font.params.scriptspace;
  114. bbox.clean();
  115. this.setChildPWidths(recompute);
  116. };
  117. class_3.prototype.getUVQ = function (subbox, supbox) {
  118. if (subbox === void 0) { subbox = this.subChild.getOuterBBox(); }
  119. if (supbox === void 0) { supbox = this.supChild.getOuterBBox(); }
  120. var basebox = this.baseCore.getOuterBBox();
  121. if (this.UVQ)
  122. return this.UVQ;
  123. var tex = this.font.params;
  124. var t = 3 * tex.rule_thickness;
  125. var subscriptshift = this.length2em(this.node.attributes.get('subscriptshift'), tex.sub2);
  126. var drop = this.baseCharZero(basebox.d * this.baseScale + tex.sub_drop * subbox.rscale);
  127. var _a = __read([this.getU(), Math.max(drop, subscriptshift)], 2), u = _a[0], v = _a[1];
  128. var q = (u - supbox.d * supbox.rscale) - (subbox.h * subbox.rscale - v);
  129. if (q < t) {
  130. v += t - q;
  131. var p = (4 / 5) * tex.x_height - (u - supbox.d * supbox.rscale);
  132. if (p > 0) {
  133. u += p;
  134. v -= p;
  135. }
  136. }
  137. u = Math.max(this.length2em(this.node.attributes.get('superscriptshift'), u), u);
  138. v = Math.max(this.length2em(this.node.attributes.get('subscriptshift'), v), v);
  139. q = (u - supbox.d * supbox.rscale) - (subbox.h * subbox.rscale - v);
  140. this.UVQ = [u, -v, q];
  141. return this.UVQ;
  142. };
  143. return class_3;
  144. }(Base)),
  145. _a.useIC = false,
  146. _a;
  147. }
  148. exports.CommonMsubsupMixin = CommonMsubsupMixin;
  149. //# sourceMappingURL=msubsup.js.map