vexflow 5.0.0-alpha.2 → 5.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/build/cjs/vexflow-bravura.js +2 -2
  2. package/build/cjs/vexflow-bravura.js.map +1 -1
  3. package/build/cjs/vexflow-core.js +2 -2
  4. package/build/cjs/vexflow-core.js.map +1 -1
  5. package/build/cjs/vexflow-debug-with-tests.js +528 -492
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +460 -452
  8. package/build/cjs/vexflow-debug.js.map +1 -1
  9. package/build/cjs/vexflow.js +2 -2
  10. package/build/cjs/vexflow.js.map +1 -1
  11. package/build/esm/src/accidental.js +22 -28
  12. package/build/esm/src/beam.js +24 -42
  13. package/build/esm/src/clefnote.js +6 -1
  14. package/build/esm/src/element.js +83 -101
  15. package/build/esm/src/fonts/gonville.js +1 -1
  16. package/build/esm/src/formatter.js +9 -17
  17. package/build/esm/src/fraction.js +15 -22
  18. package/build/esm/src/glyphnote.js +3 -2
  19. package/build/esm/src/metrics.js +3 -0
  20. package/build/esm/src/modifier.js +6 -21
  21. package/build/esm/src/multimeasurerest.js +16 -25
  22. package/build/esm/src/note.js +7 -0
  23. package/build/esm/src/registry.js +5 -19
  24. package/build/esm/src/stave.js +4 -6
  25. package/build/esm/src/stavenote.js +26 -40
  26. package/build/esm/src/stavetempo.js +4 -11
  27. package/build/esm/src/stavetie.js +82 -36
  28. package/build/esm/src/svgcontext.js +5 -12
  29. package/build/esm/src/tickable.js +13 -26
  30. package/build/esm/src/tickcontext.js +20 -2
  31. package/build/esm/src/version.js +3 -3
  32. package/build/esm/src/vibrato.js +6 -1
  33. package/build/esm/tests/clef_tests.js +5 -1
  34. package/build/esm/tests/glyphnote_tests.js +6 -0
  35. package/build/esm/tests/stavetie_tests.js +29 -0
  36. package/build/esm/tests/tabstave_tests.js +1 -0
  37. package/build/esm/tests/vexflow_test_helpers.js +25 -39
  38. package/build/types/src/accidental.d.ts +19 -1
  39. package/build/types/src/annotation.d.ts +1 -1
  40. package/build/types/src/beam.d.ts +12 -1
  41. package/build/types/src/clefnote.d.ts +2 -0
  42. package/build/types/src/element.d.ts +13 -3
  43. package/build/types/src/fonts/gonville.d.ts +1 -1
  44. package/build/types/src/formatter.d.ts +5 -3
  45. package/build/types/src/fraction.d.ts +12 -7
  46. package/build/types/src/modifier.d.ts +2 -1
  47. package/build/types/src/multimeasurerest.d.ts +4 -1
  48. package/build/types/src/note.d.ts +2 -0
  49. package/build/types/src/registry.d.ts +1 -1
  50. package/build/types/src/stavenote.d.ts +2 -1
  51. package/build/types/src/stavetempo.d.ts +3 -3
  52. package/build/types/src/stavetie.d.ts +39 -2
  53. package/build/types/src/svgcontext.d.ts +1 -1
  54. package/build/types/src/tickable.d.ts +2 -1
  55. package/build/types/src/tickcontext.d.ts +30 -0
  56. package/package.json +2 -4
  57. package/tests/flow.html +2 -2
  58. package/entry/vexflow-bravura.ts +0 -25
  59. package/entry/vexflow-core.ts +0 -16
  60. package/entry/vexflow-debug-with-tests.ts +0 -64
  61. package/entry/vexflow-debug.ts +0 -54
  62. package/entry/vexflow.ts +0 -47
  63. package/src/accidental.ts +0 -570
  64. package/src/annotation.ts +0 -294
  65. package/src/articulation.ts +0 -383
  66. package/src/barnote.ts +0 -95
  67. package/src/beam.ts +0 -999
  68. package/src/bend.ts +0 -268
  69. package/src/boundingbox.ts +0 -108
  70. package/src/canvascontext.ts +0 -348
  71. package/src/chordsymbol.ts +0 -473
  72. package/src/clef.ts +0 -164
  73. package/src/clefnote.ts +0 -50
  74. package/src/crescendo.ts +0 -132
  75. package/src/curve.ts +0 -195
  76. package/src/dot.ts +0 -171
  77. package/src/easyscore.ts +0 -538
  78. package/src/element.ts +0 -692
  79. package/src/factory.ts +0 -694
  80. package/src/font.ts +0 -343
  81. package/src/fonts/academico.ts +0 -2
  82. package/src/fonts/academicobold.ts +0 -2
  83. package/src/fonts/bravura.ts +0 -2
  84. package/src/fonts/gonville.ts +0 -2
  85. package/src/fonts/petaluma.ts +0 -2
  86. package/src/fonts/petalumascript.ts +0 -2
  87. package/src/formatter.ts +0 -1107
  88. package/src/fraction.ts +0 -245
  89. package/src/frethandfinger.ts +0 -180
  90. package/src/ghostnote.ts +0 -75
  91. package/src/glyphnote.ts +0 -68
  92. package/src/glyphs.ts +0 -5880
  93. package/src/gracenote.ts +0 -146
  94. package/src/gracenotegroup.ts +0 -194
  95. package/src/gracetabnote.ts +0 -30
  96. package/src/index.ts +0 -90
  97. package/src/keymanager.ts +0 -153
  98. package/src/keysignature.ts +0 -272
  99. package/src/keysignote.ts +0 -46
  100. package/src/metrics.ts +0 -222
  101. package/src/modifier.ts +0 -216
  102. package/src/modifiercontext.ts +0 -177
  103. package/src/multimeasurerest.ts +0 -229
  104. package/src/music.ts +0 -443
  105. package/src/note.ts +0 -690
  106. package/src/notehead.ts +0 -158
  107. package/src/notesubgroup.ts +0 -88
  108. package/src/ornament.ts +0 -301
  109. package/src/parenthesis.ts +0 -89
  110. package/src/parser.ts +0 -263
  111. package/src/pedalmarking.ts +0 -273
  112. package/src/registry.ts +0 -146
  113. package/src/rendercontext.ts +0 -98
  114. package/src/renderer.ts +0 -166
  115. package/src/repeatnote.ts +0 -25
  116. package/src/stave.ts +0 -885
  117. package/src/stavebarline.ts +0 -231
  118. package/src/staveconnector.ts +0 -281
  119. package/src/stavehairpin.ts +0 -209
  120. package/src/staveline.ts +0 -343
  121. package/src/stavemodifier.ts +0 -93
  122. package/src/stavenote.ts +0 -1230
  123. package/src/staverepetition.ts +0 -148
  124. package/src/stavesection.ts +0 -54
  125. package/src/stavetempo.ts +0 -162
  126. package/src/stavetext.ts +0 -69
  127. package/src/stavetie.ts +0 -235
  128. package/src/stavevolta.ts +0 -66
  129. package/src/stem.ts +0 -225
  130. package/src/stemmablenote.ts +0 -248
  131. package/src/stringnumber.ts +0 -286
  132. package/src/strokes.ts +0 -214
  133. package/src/svgcontext.ts +0 -639
  134. package/src/system.ts +0 -327
  135. package/src/tables.ts +0 -796
  136. package/src/tabnote.ts +0 -449
  137. package/src/tabslide.ts +0 -115
  138. package/src/tabstave.ts +0 -31
  139. package/src/tabtie.ts +0 -44
  140. package/src/textbracket.ts +0 -231
  141. package/src/textdynamics.ts +0 -101
  142. package/src/textnote.ts +0 -175
  143. package/src/tickable.ts +0 -374
  144. package/src/tickcontext.ts +0 -280
  145. package/src/timesignature.ts +0 -229
  146. package/src/timesignote.ts +0 -45
  147. package/src/tremolo.ts +0 -51
  148. package/src/tuning.ts +0 -90
  149. package/src/tuplet.ts +0 -349
  150. package/src/typeguard.ts +0 -136
  151. package/src/util.ts +0 -169
  152. package/src/version.ts +0 -4
  153. package/src/vexflow.ts +0 -378
  154. package/src/vibrato.ts +0 -99
  155. package/src/vibratobracket.ts +0 -81
  156. package/src/voice.ts +0 -302
  157. package/src/web.ts +0 -35
@@ -1,231 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // @author Cyril Silverman
3
- //
4
- // This file implements `TextBrackets` which extend between two notes.
5
- // The octave transposition markings (8va, 8vb, 15va, 15vb) can be created
6
- // using this class.
7
-
8
- import { Element } from './element';
9
- import { Font } from './font';
10
- import { Note } from './note';
11
- import { RenderContext } from './rendercontext';
12
- import { Renderer } from './renderer';
13
- import { Tables } from './tables';
14
- import { Category } from './typeguard';
15
- import { log, RuntimeError } from './util';
16
-
17
- export interface TextBracketParams {
18
- start: Note;
19
- stop: Note;
20
- text?: string;
21
- superscript?: string;
22
- position?: number | string;
23
- }
24
-
25
- // To enable logging for this class. Set `VexFlow.TextBracket.DEBUG` to `true`.
26
- // eslint-disable-next-line
27
- function L(...args: any[]) {
28
- if (TextBracket.DEBUG) log('VexFlow.TextBracket', args);
29
- }
30
-
31
- export enum TextBracketPosition {
32
- TOP = 1,
33
- BOTTOM = -1,
34
- }
35
-
36
- export class TextBracket extends Element {
37
- static DEBUG: boolean = false;
38
-
39
- static get CATEGORY(): string {
40
- return Category.TextBracket;
41
- }
42
-
43
- public renderOptions: {
44
- dashed: boolean;
45
- color: string;
46
- lineWidth: number;
47
- underlineSuperscript: boolean;
48
- showBracket: boolean;
49
- dash: number[];
50
- bracketHeight: number;
51
- };
52
-
53
- protected textElement: Element;
54
- protected superscriptElement: Element;
55
-
56
- protected line: number;
57
-
58
- readonly position: TextBracketPosition;
59
- readonly start: Note;
60
- readonly stop: Note;
61
-
62
- static get Position(): typeof TextBracketPosition {
63
- return TextBracketPosition;
64
- }
65
-
66
- static get PositionString(): Record<string, number> {
67
- return {
68
- top: TextBracketPosition.TOP,
69
- bottom: TextBracketPosition.BOTTOM,
70
- };
71
- }
72
-
73
- constructor({ start, stop, text = '', superscript = '', position = TextBracketPosition.TOP }: TextBracketParams) {
74
- super();
75
-
76
- this.start = start;
77
- this.stop = stop;
78
-
79
- this.textElement = new Element('TextBracket');
80
- this.textElement.setText(text);
81
- this.superscriptElement = new Element('TextBracket');
82
- this.superscriptElement.setText(superscript);
83
- const smallerFontSize = Font.scaleSize(this.fontInfo.size, 0.714286);
84
- this.superscriptElement.setFontSize(smallerFontSize);
85
-
86
- this.position = typeof position === 'string' ? TextBracket.PositionString[position] : position;
87
-
88
- this.line = 1;
89
-
90
- this.renderOptions = {
91
- dashed: true,
92
- dash: [5],
93
- color: 'black',
94
- lineWidth: 1,
95
- showBracket: true,
96
- bracketHeight: 8,
97
-
98
- // In the BOTTOM position, the bracket line can extend
99
- // under the superscript.
100
- underlineSuperscript: true,
101
- };
102
- }
103
-
104
- /**
105
- * Apply the text backet styling to the provided context.
106
- * @param ctx
107
- * @returns this
108
- */
109
- applyStyle(ctx: RenderContext): this {
110
- this.textElement.setFont(this.fontInfo);
111
- // We called this.resetFont() in the constructor, so we know this.textFont is available.
112
- const { family, size, weight, style } = this.fontInfo;
113
- // To draw the superscript, we scale the font size by 1/1.4.
114
- const smallerFontSize = Font.scaleSize(size, 0.714286);
115
- this.superscriptElement.setFont(family, smallerFontSize, weight, style);
116
-
117
- const options = this.renderOptions;
118
- ctx.setStrokeStyle(options.color);
119
- ctx.setFillStyle(options.color);
120
- ctx.setLineWidth(options.lineWidth);
121
-
122
- return this;
123
- }
124
-
125
- // Set whether the bracket line should be `dashed`. You can also
126
- // optionally set the `dash` pattern by passing in an array of numbers
127
- setDashed(dashed: boolean, dash?: number[]): this {
128
- this.renderOptions.dashed = dashed;
129
- if (dash) this.renderOptions.dash = dash;
130
- return this;
131
- }
132
-
133
- // Set the rendering `context` for the octave bracket
134
- setLine(line: number): this {
135
- this.line = line;
136
- return this;
137
- }
138
-
139
- // Draw the octave bracket on the rendering context
140
- draw(): void {
141
- const ctx = this.checkContext();
142
- this.setRendered();
143
-
144
- let y = 0;
145
- switch (this.position) {
146
- case TextBracketPosition.TOP:
147
- y = this.start.checkStave().getYForTopText(this.line);
148
- break;
149
- case TextBracketPosition.BOTTOM:
150
- y = this.start.checkStave().getYForBottomText(this.line + Tables.TEXT_HEIGHT_OFFSET_HACK);
151
- break;
152
- default:
153
- throw new RuntimeError('InvalidPosition', `The position ${this.position} is invalid.`);
154
- }
155
-
156
- // Get the preliminary start and stop coordintates for the bracket
157
- const start = { x: this.start.getAbsoluteX(), y };
158
- const stop = { x: this.stop.getAbsoluteX(), y };
159
-
160
- L('Rendering TextBracket: start:', start, 'stop:', stop, 'y:', y);
161
-
162
- const bracketHeight = this.renderOptions.bracketHeight * this.position;
163
-
164
- ctx.save();
165
- this.applyStyle(ctx);
166
-
167
- // Draw text
168
- this.textElement.renderText(ctx, start.x, start.y);
169
-
170
- // Get the width and height for the octave number
171
- const mainWidth = this.textElement.getWidth();
172
- const mainHeight = this.textElement.getHeight();
173
-
174
- // Calculate the y position for the super script
175
- const superY = start.y - mainHeight / 2.5;
176
-
177
- // To draw the superscript, we scale the font size by 1/1.4.
178
- this.superscriptElement.renderText(ctx, start.x + mainWidth + 1, superY);
179
-
180
- // Determine width and height of the superscript
181
- const superWidth = this.superscriptElement.getWidth();
182
- const superHeight = this.superscriptElement.getHeight();
183
-
184
- // Setup initial coordinates for the bracket line
185
- let startX = start.x;
186
- let lineY = superY;
187
- const endX = stop.x + this.stop.getGlyphWidth();
188
-
189
- // Adjust x and y coordinates based on position
190
- if (this.position === TextBracketPosition.TOP) {
191
- startX += mainWidth + superWidth + 5;
192
- lineY -= superHeight / 2.7;
193
- } else if (this.position === TextBracketPosition.BOTTOM) {
194
- lineY += superHeight / 2.7;
195
- startX += mainWidth + 2;
196
-
197
- if (!this.renderOptions.underlineSuperscript) {
198
- startX += superWidth;
199
- }
200
- }
201
-
202
- if (this.renderOptions.dashed) {
203
- // Main line
204
- Renderer.drawDashedLine(ctx, startX, lineY, endX, lineY, this.renderOptions.dash);
205
- // Ending Bracket
206
- if (this.renderOptions.showBracket) {
207
- Renderer.drawDashedLine(
208
- ctx,
209
- endX,
210
- lineY + 1 * this.position,
211
- endX,
212
- lineY + bracketHeight,
213
- this.renderOptions.dash
214
- );
215
- }
216
- } else {
217
- ctx.beginPath();
218
- ctx.moveTo(startX, lineY);
219
- // Main line
220
- ctx.lineTo(endX, lineY);
221
- if (this.renderOptions.showBracket) {
222
- // Ending bracket
223
- ctx.lineTo(endX, lineY + bracketHeight);
224
- }
225
- ctx.stroke();
226
- ctx.closePath();
227
- }
228
-
229
- ctx.restore();
230
- }
231
- }
@@ -1,101 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // MIT License
3
-
4
- import { Glyphs } from './glyphs';
5
- import { Note } from './note';
6
- import { TextNoteStruct } from './textnote';
7
- import { Category } from './typeguard';
8
- import { log, RuntimeError } from './util';
9
-
10
- // eslint-disable-next-line
11
- function L(...args: any[]) {
12
- if (TextDynamics.DEBUG) log('VexFlow.TextDynamics', args);
13
- }
14
-
15
- /**
16
- * `TextDynamics` renders traditional
17
- * text dynamics markings, **ie: p, f, sfz, rfz, ppp**
18
- *
19
- * You can render any dynamics string that contains a combination of
20
- * the following letters: P, M, F, Z, R, S
21
- */
22
- export class TextDynamics extends Note {
23
- /** To enable logging for this class. Set `VexFlow.TextDynamics.DEBUG` to `true`. */
24
- static DEBUG: boolean = false;
25
-
26
- static get CATEGORY(): string {
27
- return Category.TextDynamics;
28
- }
29
-
30
- protected sequence: string;
31
-
32
- protected line: number;
33
-
34
- /** The glyph data for each dynamics letter. */
35
- static get GLYPHS(): Record<string, string> {
36
- return {
37
- f: Glyphs.dynamicForte,
38
- p: Glyphs.dynamicPiano,
39
- m: Glyphs.dynamicMezzo,
40
- s: Glyphs.dynamicSforzando,
41
- z: Glyphs.dynamicZ,
42
- r: Glyphs.dynamicRinforzando,
43
- };
44
- }
45
-
46
- /**
47
- * Create the dynamics marking.
48
- *
49
- * A `TextDynamics` object inherits from `Note` so that it can be formatted
50
- * within a `Voice`.
51
- *
52
- * @param noteStruct an object that contains a `duration` property and a
53
- * `sequence` of letters that represents the letters to render.
54
- */
55
- constructor(noteStruct: TextNoteStruct) {
56
- super(noteStruct);
57
-
58
- this.sequence = (noteStruct.text ?? '').toLowerCase();
59
- this.line = noteStruct.line ?? 0;
60
- this.text = '';
61
-
62
- L('New Dynamics Text: ', this.sequence);
63
- }
64
-
65
- /** Set the Stave line on which the note should be placed. */
66
- setLine(line: number): this {
67
- this.line = line;
68
- return this;
69
- }
70
-
71
- /** Preformat the dynamics text. */
72
- preFormat(): this {
73
- // length of this.glyphs must be <=
74
- // length of this.sequence, so if we're formatted before
75
- // create new glyphs.
76
- this.text = '';
77
- // Iterate through each letter
78
- this.sequence.split('').forEach((letter) => {
79
- // Get the glyph data for the letter
80
- const glyph = TextDynamics.GLYPHS[letter];
81
- if (!glyph) throw new RuntimeError('Invalid dynamics character: ' + letter);
82
-
83
- // Add the glyph
84
- this.text += glyph;
85
- });
86
-
87
- this.preFormatted = true;
88
- return this;
89
- }
90
-
91
- /** Draw the dynamics text on the rendering context. */
92
- draw(): void {
93
- this.setRendered();
94
- const x = this.getAbsoluteX();
95
- const y = this.checkStave().getYForLine(this.line + -3);
96
-
97
- L('Rendering Dynamics: ', this.sequence);
98
-
99
- this.renderText(this.checkContext(), x, y);
100
- }
101
- }
package/src/textnote.ts DELETED
@@ -1,175 +0,0 @@
1
- // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2
- // MIT License
3
-
4
- import { Element } from './element';
5
- import { Font, FontInfo } from './font';
6
- import { Glyphs } from './glyphs';
7
- import { Metrics } from './metrics';
8
- import { Note, NoteStruct } from './note';
9
- import { Category } from './typeguard';
10
-
11
- export enum TextJustification {
12
- LEFT = 1,
13
- CENTER = 2,
14
- RIGHT = 3,
15
- }
16
-
17
- export interface TextNoteStruct extends NoteStruct {
18
- text?: string;
19
- glyph?: string;
20
- ignoreTicks?: boolean;
21
- smooth?: boolean;
22
- font?: FontInfo;
23
- subscript?: string;
24
- superscript?: string;
25
- }
26
-
27
- /**
28
- * `TextNote` is a notation element that is positioned in time. Generally
29
- * meant for objects that sit above/below the staff and inline with each other.
30
- * `TextNote` has to be assigned to a `Stave` before rendering by means of `setStave`.
31
- * Examples of this would be such as dynamics, lyrics, chord changes, etc.
32
- */
33
- export class TextNote extends Note {
34
- static get CATEGORY(): string {
35
- return Category.TextNote;
36
- }
37
-
38
- static readonly Justification = TextJustification;
39
-
40
- /** Glyph data. */
41
- static get GLYPHS(): Record<string, string> {
42
- return {
43
- segno: Glyphs.segno,
44
- tr: Glyphs.ornamentTrill,
45
- mordent: Glyphs.ornamentMordent,
46
- mordentUpper: Glyphs.ornamentShortTrill,
47
- mordentLower: Glyphs.ornamentMordent,
48
- f: Glyphs.dynamicForte,
49
- p: Glyphs.dynamicPiano,
50
- m: Glyphs.dynamicMezzo,
51
- s: Glyphs.dynamicSforzando,
52
- z: Glyphs.dynamicZ,
53
- coda: Glyphs.coda,
54
- pedalOpen: Glyphs.keyboardPedalPed,
55
- pedalClose: Glyphs.keyboardPedalUp,
56
- caesuraStraight: Glyphs.caesura,
57
- caesuraCurved: Glyphs.caesuraCurved,
58
- breath: Glyphs.breathMarkComma,
59
- tick: Glyphs.breathMarkTick,
60
- turn: Glyphs.ornamentTurn,
61
- turnInverted: Glyphs.ornamentTurnSlash,
62
- };
63
- }
64
-
65
- protected superscript?: Element;
66
- protected subscript?: Element;
67
- protected smooth: boolean;
68
- protected justification: TextJustification;
69
- protected line: number;
70
-
71
- constructor(noteStruct: TextNoteStruct) {
72
- super(noteStruct);
73
-
74
- this.text = noteStruct.text ?? '';
75
- if (noteStruct.glyph) {
76
- this.text += TextNote.GLYPHS[noteStruct.glyph] || noteStruct.glyph;
77
- }
78
- if (noteStruct.font) {
79
- this.setFont(noteStruct.font);
80
- } else if (noteStruct.glyph === undefined) {
81
- this.setFont(Metrics.getFontInfo('TextNote.text.fontSize'));
82
- }
83
-
84
- // Scale the font size by 1/1.3.
85
- const smallerFontSize = Font.convertSizeToPointValue(this.fontInfo.size) * 0.769231;
86
- if (noteStruct.superscript) {
87
- this.superscript = new Element('TexNote.subSuper');
88
- this.superscript.setText(noteStruct.superscript);
89
- this.superscript.setFontSize(smallerFontSize);
90
- }
91
- if (noteStruct.subscript) {
92
- this.subscript = new Element('TexNote.subSuper');
93
- this.subscript.setText(noteStruct.subscript);
94
- this.subscript.setFontSize(smallerFontSize);
95
- }
96
-
97
- this.line = noteStruct.line ?? 0;
98
- this.smooth = noteStruct.smooth || false;
99
- this.ignoreTicks = noteStruct.ignoreTicks || false;
100
- this.justification = TextJustification.LEFT;
101
- }
102
-
103
- /** Set the horizontal justification of the TextNote. */
104
- setJustification(just: TextJustification): this {
105
- this.justification = just;
106
- return this;
107
- }
108
-
109
- /** Set the Stave line on which the note should be placed. */
110
- setLine(line: number): this {
111
- this.line = line;
112
- return this;
113
- }
114
-
115
- /** Return the Stave line on which the TextNote is placed. */
116
- getLine(): number {
117
- return this.line;
118
- }
119
-
120
- /** Pre-render formatting. */
121
- preFormat(): void {
122
- if (this.preFormatted) return;
123
- const tickContext = this.checkTickContext(`Can't preformat without a TickContext.`);
124
-
125
- if (this.justification === TextJustification.CENTER) {
126
- this.leftDisplacedHeadPx = this.width / 2;
127
- } else if (this.justification === TextJustification.RIGHT) {
128
- this.leftDisplacedHeadPx = this.width;
129
- }
130
-
131
- // We reposition to the center of the note head
132
- this.rightDisplacedHeadPx = tickContext.getMetrics().glyphPx / 2;
133
- this.preFormatted = true;
134
- }
135
-
136
- /**
137
- * Renders the TextNote.
138
- * `TextNote` has to be assigned to a `Stave` before rendering by means of `setStave`.
139
- */
140
- draw(): void {
141
- const ctx = this.checkContext();
142
- const stave = this.checkStave();
143
- const tickContext = this.checkTickContext(`Can't draw without a TickContext.`);
144
-
145
- this.setRendered();
146
-
147
- // Reposition to center of note head
148
- let x = this.getAbsoluteX() + tickContext.getMetrics().glyphPx / 2;
149
-
150
- // Align based on tick-context width.
151
- const width = this.getWidth();
152
-
153
- if (this.justification === TextJustification.CENTER) {
154
- x -= width / 2;
155
- } else if (this.justification === TextJustification.RIGHT) {
156
- x -= width;
157
- }
158
-
159
- const y = stave.getYForLine(this.line + -3);
160
- this.applyStyle(ctx);
161
- this.renderText(ctx, x, y);
162
-
163
- const height = this.getHeight();
164
-
165
- if (this.superscript) {
166
- this.superscript.renderText(ctx, x + this.width + 2, y - height / 2.2);
167
- }
168
-
169
- if (this.subscript) {
170
- this.subscript.renderText(ctx, x + this.width + 2, y + height / 2.2 - 1);
171
- }
172
-
173
- this.restoreStyle(ctx);
174
- }
175
- }