GraphicalLabel.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. "use strict";
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  4. function __() { this.constructor = d; }
  5. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6. };
  7. var TextAlignment_1 = require("../../Common/Enums/TextAlignment");
  8. var Clickable_1 = require("./Clickable");
  9. var BoundingBox_1 = require("./BoundingBox");
  10. var EngravingRules_1 = require("./EngravingRules");
  11. var MusicSheetCalculator_1 = require("./MusicSheetCalculator");
  12. var GraphicalLabel = (function (_super) {
  13. __extends(GraphicalLabel, _super);
  14. function GraphicalLabel(label, textHeight, alignment, parent) {
  15. if (parent === void 0) { parent = undefined; }
  16. _super.call(this);
  17. this.label = label;
  18. this.boundingBox = new BoundingBox_1.BoundingBox(this, parent);
  19. this.label.fontHeight = textHeight;
  20. this.label.textAlignment = alignment;
  21. }
  22. Object.defineProperty(GraphicalLabel.prototype, "Label", {
  23. get: function () {
  24. return this.label;
  25. },
  26. enumerable: true,
  27. configurable: true
  28. });
  29. GraphicalLabel.prototype.toString = function () {
  30. return this.label.text;
  31. };
  32. GraphicalLabel.prototype.setLabelPositionAndShapeBorders = function () {
  33. if (this.Label.text.trim() === "") {
  34. return;
  35. }
  36. var labelMarginBorderFactor = EngravingRules_1.EngravingRules.Rules.LabelMarginBorderFactor;
  37. var widthToHeightRatio = MusicSheetCalculator_1.MusicSheetCalculator.TextMeasurer.computeTextWidthToHeightRatio(this.Label.text, this.Label.font, this.Label.fontStyle);
  38. var height = this.Label.fontHeight;
  39. var width = height * widthToHeightRatio;
  40. var psi = this.PositionAndShape;
  41. switch (this.Label.textAlignment) {
  42. case TextAlignment_1.TextAlignment.CenterBottom:
  43. psi.BorderTop = -height;
  44. psi.BorderLeft = -width / 2;
  45. psi.BorderBottom = 0;
  46. psi.BorderRight = width / 2;
  47. break;
  48. case TextAlignment_1.TextAlignment.CenterCenter:
  49. psi.BorderTop = -height / 2;
  50. psi.BorderLeft = -width / 2;
  51. psi.BorderBottom = height / 2;
  52. psi.BorderRight = width / 2;
  53. break;
  54. case TextAlignment_1.TextAlignment.CenterTop:
  55. psi.BorderTop = 0;
  56. psi.BorderLeft = -width / 2;
  57. psi.BorderBottom = height;
  58. psi.BorderRight = width / 2;
  59. break;
  60. case TextAlignment_1.TextAlignment.LeftBottom:
  61. psi.BorderTop = -height;
  62. psi.BorderLeft = 0;
  63. psi.BorderBottom = 0;
  64. psi.BorderRight = width;
  65. break;
  66. case TextAlignment_1.TextAlignment.LeftCenter:
  67. psi.BorderTop = -height / 2;
  68. psi.BorderLeft = 0;
  69. psi.BorderBottom = height / 2;
  70. psi.BorderRight = width;
  71. break;
  72. case TextAlignment_1.TextAlignment.LeftTop:
  73. psi.BorderTop = 0;
  74. psi.BorderLeft = 0;
  75. psi.BorderBottom = height;
  76. psi.BorderRight = width;
  77. break;
  78. case TextAlignment_1.TextAlignment.RightBottom:
  79. psi.BorderTop = -height;
  80. psi.BorderLeft = -width;
  81. psi.BorderBottom = 0;
  82. psi.BorderRight = 0;
  83. break;
  84. case TextAlignment_1.TextAlignment.RightCenter:
  85. psi.BorderTop = -height / 2;
  86. psi.BorderLeft = -width;
  87. psi.BorderBottom = height / 2;
  88. psi.BorderRight = 0;
  89. break;
  90. case TextAlignment_1.TextAlignment.RightTop:
  91. psi.BorderTop = 0;
  92. psi.BorderLeft = -width;
  93. psi.BorderBottom = height;
  94. psi.BorderRight = 0;
  95. break;
  96. default:
  97. }
  98. psi.BorderMarginTop = psi.BorderTop - height * labelMarginBorderFactor;
  99. psi.BorderMarginLeft = psi.BorderLeft - height * labelMarginBorderFactor;
  100. psi.BorderMarginBottom = psi.BorderBottom + height * labelMarginBorderFactor;
  101. psi.BorderMarginRight = psi.BorderRight + height * labelMarginBorderFactor;
  102. };
  103. return GraphicalLabel;
  104. }(Clickable_1.Clickable));
  105. exports.GraphicalLabel = GraphicalLabel;