mmultiscripts.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  34. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  35. if (ar || !(i in from)) {
  36. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  37. ar[i] = from[i];
  38. }
  39. }
  40. return to.concat(ar || Array.prototype.slice.call(from));
  41. };
  42. var __values = (this && this.__values) || function(o) {
  43. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  44. if (m) return m.call(o);
  45. if (o && typeof o.length === "number") return {
  46. next: function () {
  47. if (o && i >= o.length) o = void 0;
  48. return { value: o && o[i++], done: !o };
  49. }
  50. };
  51. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  52. };
  53. Object.defineProperty(exports, "__esModule", { value: true });
  54. exports.CommonMmultiscriptsMixin = exports.ScriptNames = exports.NextScript = void 0;
  55. var BBox_js_1 = require("../../../util/BBox.js");
  56. exports.NextScript = {
  57. base: 'subList',
  58. subList: 'supList',
  59. supList: 'subList',
  60. psubList: 'psupList',
  61. psupList: 'psubList',
  62. };
  63. exports.ScriptNames = ['sup', 'sup', 'psup', 'psub'];
  64. function CommonMmultiscriptsMixin(Base) {
  65. return (function (_super) {
  66. __extends(class_1, _super);
  67. function class_1() {
  68. var args = [];
  69. for (var _i = 0; _i < arguments.length; _i++) {
  70. args[_i] = arguments[_i];
  71. }
  72. var _this = _super.apply(this, __spreadArray([], __read(args), false)) || this;
  73. _this.scriptData = null;
  74. _this.firstPrescript = 0;
  75. _this.getScriptData();
  76. return _this;
  77. }
  78. class_1.prototype.combinePrePost = function (pre, post) {
  79. var bbox = new BBox_js_1.BBox(pre);
  80. bbox.combine(post, 0, 0);
  81. return bbox;
  82. };
  83. class_1.prototype.computeBBox = function (bbox, recompute) {
  84. if (recompute === void 0) { recompute = false; }
  85. var scriptspace = this.font.params.scriptspace;
  86. var data = this.scriptData;
  87. var sub = this.combinePrePost(data.sub, data.psub);
  88. var sup = this.combinePrePost(data.sup, data.psup);
  89. var _a = __read(this.getUVQ(sub, sup), 2), u = _a[0], v = _a[1];
  90. bbox.empty();
  91. if (data.numPrescripts) {
  92. bbox.combine(data.psup, scriptspace, u);
  93. bbox.combine(data.psub, scriptspace, v);
  94. }
  95. bbox.append(data.base);
  96. if (data.numScripts) {
  97. var w = bbox.w;
  98. bbox.combine(data.sup, w, u);
  99. bbox.combine(data.sub, w, v);
  100. bbox.w += scriptspace;
  101. }
  102. bbox.clean();
  103. this.setChildPWidths(recompute);
  104. };
  105. class_1.prototype.getScriptData = function () {
  106. var data = this.scriptData = {
  107. base: null, sub: BBox_js_1.BBox.empty(), sup: BBox_js_1.BBox.empty(), psub: BBox_js_1.BBox.empty(), psup: BBox_js_1.BBox.empty(),
  108. numPrescripts: 0, numScripts: 0
  109. };
  110. var lists = this.getScriptBBoxLists();
  111. this.combineBBoxLists(data.sub, data.sup, lists.subList, lists.supList);
  112. this.combineBBoxLists(data.psub, data.psup, lists.psubList, lists.psupList);
  113. data.base = lists.base[0];
  114. data.numPrescripts = lists.psubList.length;
  115. data.numScripts = lists.subList.length;
  116. };
  117. class_1.prototype.getScriptBBoxLists = function () {
  118. var e_1, _a;
  119. var lists = {
  120. base: [], subList: [], supList: [], psubList: [], psupList: []
  121. };
  122. var script = 'base';
  123. try {
  124. for (var _b = __values(this.childNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
  125. var child = _c.value;
  126. if (child.node.isKind('mprescripts')) {
  127. script = 'psubList';
  128. }
  129. else {
  130. lists[script].push(child.getOuterBBox());
  131. script = exports.NextScript[script];
  132. }
  133. }
  134. }
  135. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  136. finally {
  137. try {
  138. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  139. }
  140. finally { if (e_1) throw e_1.error; }
  141. }
  142. this.firstPrescript = lists.subList.length + lists.supList.length + 2;
  143. this.padLists(lists.subList, lists.supList);
  144. this.padLists(lists.psubList, lists.psupList);
  145. return lists;
  146. };
  147. class_1.prototype.padLists = function (list1, list2) {
  148. if (list1.length > list2.length) {
  149. list2.push(BBox_js_1.BBox.empty());
  150. }
  151. };
  152. class_1.prototype.combineBBoxLists = function (bbox1, bbox2, list1, list2) {
  153. for (var i = 0; i < list1.length; i++) {
  154. var _a = __read(this.getScaledWHD(list1[i]), 3), w1 = _a[0], h1 = _a[1], d1 = _a[2];
  155. var _b = __read(this.getScaledWHD(list2[i]), 3), w2 = _b[0], h2 = _b[1], d2 = _b[2];
  156. var w = Math.max(w1, w2);
  157. bbox1.w += w;
  158. bbox2.w += w;
  159. if (h1 > bbox1.h)
  160. bbox1.h = h1;
  161. if (d1 > bbox1.d)
  162. bbox1.d = d1;
  163. if (h2 > bbox2.h)
  164. bbox2.h = h2;
  165. if (d2 > bbox2.d)
  166. bbox2.d = d2;
  167. }
  168. };
  169. class_1.prototype.getScaledWHD = function (bbox) {
  170. var w = bbox.w, h = bbox.h, d = bbox.d, rscale = bbox.rscale;
  171. return [w * rscale, h * rscale, d * rscale];
  172. };
  173. class_1.prototype.getUVQ = function (subbox, supbox) {
  174. var _a;
  175. if (!this.UVQ) {
  176. var _b = __read([0, 0, 0], 3), u = _b[0], v = _b[1], q = _b[2];
  177. if (subbox.h === 0 && subbox.d === 0) {
  178. u = this.getU();
  179. }
  180. else if (supbox.h === 0 && supbox.d === 0) {
  181. u = -this.getV();
  182. }
  183. else {
  184. _a = __read(_super.prototype.getUVQ.call(this, subbox, supbox), 3), u = _a[0], v = _a[1], q = _a[2];
  185. }
  186. this.UVQ = [u, v, q];
  187. }
  188. return this.UVQ;
  189. };
  190. return class_1;
  191. }(Base));
  192. }
  193. exports.CommonMmultiscriptsMixin = CommonMmultiscriptsMixin;
  194. //# sourceMappingURL=mmultiscripts.js.map