mglyph.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. Object.defineProperty(exports, "__esModule", { value: true });
  43. exports.CommonMglyphMixin = void 0;
  44. function CommonMglyphMixin(Base) {
  45. return (function (_super) {
  46. __extends(class_1, _super);
  47. function class_1() {
  48. var args = [];
  49. for (var _i = 0; _i < arguments.length; _i++) {
  50. args[_i] = arguments[_i];
  51. }
  52. var _this = _super.apply(this, __spreadArray([], __read(args), false)) || this;
  53. _this.getParameters();
  54. return _this;
  55. }
  56. class_1.prototype.getParameters = function () {
  57. var _a = this.node.attributes.getList('width', 'height', 'valign', 'src', 'index'), width = _a.width, height = _a.height, valign = _a.valign, src = _a.src, index = _a.index;
  58. if (src) {
  59. this.width = (width === 'auto' ? 1 : this.length2em(width));
  60. this.height = (height === 'auto' ? 1 : this.length2em(height));
  61. this.valign = this.length2em(valign || '0');
  62. }
  63. else {
  64. var text = String.fromCodePoint(parseInt(index));
  65. var mmlFactory = this.node.factory;
  66. this.charWrapper = this.wrap(mmlFactory.create('text').setText(text));
  67. this.charWrapper.parent = this;
  68. }
  69. };
  70. class_1.prototype.computeBBox = function (bbox, _recompute) {
  71. if (_recompute === void 0) { _recompute = false; }
  72. if (this.charWrapper) {
  73. bbox.updateFrom(this.charWrapper.getBBox());
  74. }
  75. else {
  76. bbox.w = this.width;
  77. bbox.h = this.height + this.valign;
  78. bbox.d = -this.valign;
  79. }
  80. };
  81. return class_1;
  82. }(Base));
  83. }
  84. exports.CommonMglyphMixin = CommonMglyphMixin;
  85. //# sourceMappingURL=mglyph.js.map