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.
- package/build/cjs/vexflow-bravura.js +2 -2
- package/build/cjs/vexflow-bravura.js.map +1 -1
- package/build/cjs/vexflow-core.js +2 -2
- package/build/cjs/vexflow-core.js.map +1 -1
- package/build/cjs/vexflow-debug-with-tests.js +528 -492
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +460 -452
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/src/accidental.js +22 -28
- package/build/esm/src/beam.js +24 -42
- package/build/esm/src/clefnote.js +6 -1
- package/build/esm/src/element.js +83 -101
- package/build/esm/src/fonts/gonville.js +1 -1
- package/build/esm/src/formatter.js +9 -17
- package/build/esm/src/fraction.js +15 -22
- package/build/esm/src/glyphnote.js +3 -2
- package/build/esm/src/metrics.js +3 -0
- package/build/esm/src/modifier.js +6 -21
- package/build/esm/src/multimeasurerest.js +16 -25
- package/build/esm/src/note.js +7 -0
- package/build/esm/src/registry.js +5 -19
- package/build/esm/src/stave.js +4 -6
- package/build/esm/src/stavenote.js +26 -40
- package/build/esm/src/stavetempo.js +4 -11
- package/build/esm/src/stavetie.js +82 -36
- package/build/esm/src/svgcontext.js +5 -12
- package/build/esm/src/tickable.js +13 -26
- package/build/esm/src/tickcontext.js +20 -2
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vibrato.js +6 -1
- package/build/esm/tests/clef_tests.js +5 -1
- package/build/esm/tests/glyphnote_tests.js +6 -0
- package/build/esm/tests/stavetie_tests.js +29 -0
- package/build/esm/tests/tabstave_tests.js +1 -0
- package/build/esm/tests/vexflow_test_helpers.js +25 -39
- package/build/types/src/accidental.d.ts +19 -1
- package/build/types/src/annotation.d.ts +1 -1
- package/build/types/src/beam.d.ts +12 -1
- package/build/types/src/clefnote.d.ts +2 -0
- package/build/types/src/element.d.ts +13 -3
- package/build/types/src/fonts/gonville.d.ts +1 -1
- package/build/types/src/formatter.d.ts +5 -3
- package/build/types/src/fraction.d.ts +12 -7
- package/build/types/src/modifier.d.ts +2 -1
- package/build/types/src/multimeasurerest.d.ts +4 -1
- package/build/types/src/note.d.ts +2 -0
- package/build/types/src/registry.d.ts +1 -1
- package/build/types/src/stavenote.d.ts +2 -1
- package/build/types/src/stavetempo.d.ts +3 -3
- package/build/types/src/stavetie.d.ts +39 -2
- package/build/types/src/svgcontext.d.ts +1 -1
- package/build/types/src/tickable.d.ts +2 -1
- package/build/types/src/tickcontext.d.ts +30 -0
- package/package.json +2 -4
- package/tests/flow.html +2 -2
- package/entry/vexflow-bravura.ts +0 -25
- package/entry/vexflow-core.ts +0 -16
- package/entry/vexflow-debug-with-tests.ts +0 -64
- package/entry/vexflow-debug.ts +0 -54
- package/entry/vexflow.ts +0 -47
- package/src/accidental.ts +0 -570
- package/src/annotation.ts +0 -294
- package/src/articulation.ts +0 -383
- package/src/barnote.ts +0 -95
- package/src/beam.ts +0 -999
- package/src/bend.ts +0 -268
- package/src/boundingbox.ts +0 -108
- package/src/canvascontext.ts +0 -348
- package/src/chordsymbol.ts +0 -473
- package/src/clef.ts +0 -164
- package/src/clefnote.ts +0 -50
- package/src/crescendo.ts +0 -132
- package/src/curve.ts +0 -195
- package/src/dot.ts +0 -171
- package/src/easyscore.ts +0 -538
- package/src/element.ts +0 -692
- package/src/factory.ts +0 -694
- package/src/font.ts +0 -343
- package/src/fonts/academico.ts +0 -2
- package/src/fonts/academicobold.ts +0 -2
- package/src/fonts/bravura.ts +0 -2
- package/src/fonts/gonville.ts +0 -2
- package/src/fonts/petaluma.ts +0 -2
- package/src/fonts/petalumascript.ts +0 -2
- package/src/formatter.ts +0 -1107
- package/src/fraction.ts +0 -245
- package/src/frethandfinger.ts +0 -180
- package/src/ghostnote.ts +0 -75
- package/src/glyphnote.ts +0 -68
- package/src/glyphs.ts +0 -5880
- package/src/gracenote.ts +0 -146
- package/src/gracenotegroup.ts +0 -194
- package/src/gracetabnote.ts +0 -30
- package/src/index.ts +0 -90
- package/src/keymanager.ts +0 -153
- package/src/keysignature.ts +0 -272
- package/src/keysignote.ts +0 -46
- package/src/metrics.ts +0 -222
- package/src/modifier.ts +0 -216
- package/src/modifiercontext.ts +0 -177
- package/src/multimeasurerest.ts +0 -229
- package/src/music.ts +0 -443
- package/src/note.ts +0 -690
- package/src/notehead.ts +0 -158
- package/src/notesubgroup.ts +0 -88
- package/src/ornament.ts +0 -301
- package/src/parenthesis.ts +0 -89
- package/src/parser.ts +0 -263
- package/src/pedalmarking.ts +0 -273
- package/src/registry.ts +0 -146
- package/src/rendercontext.ts +0 -98
- package/src/renderer.ts +0 -166
- package/src/repeatnote.ts +0 -25
- package/src/stave.ts +0 -885
- package/src/stavebarline.ts +0 -231
- package/src/staveconnector.ts +0 -281
- package/src/stavehairpin.ts +0 -209
- package/src/staveline.ts +0 -343
- package/src/stavemodifier.ts +0 -93
- package/src/stavenote.ts +0 -1230
- package/src/staverepetition.ts +0 -148
- package/src/stavesection.ts +0 -54
- package/src/stavetempo.ts +0 -162
- package/src/stavetext.ts +0 -69
- package/src/stavetie.ts +0 -235
- package/src/stavevolta.ts +0 -66
- package/src/stem.ts +0 -225
- package/src/stemmablenote.ts +0 -248
- package/src/stringnumber.ts +0 -286
- package/src/strokes.ts +0 -214
- package/src/svgcontext.ts +0 -639
- package/src/system.ts +0 -327
- package/src/tables.ts +0 -796
- package/src/tabnote.ts +0 -449
- package/src/tabslide.ts +0 -115
- package/src/tabstave.ts +0 -31
- package/src/tabtie.ts +0 -44
- package/src/textbracket.ts +0 -231
- package/src/textdynamics.ts +0 -101
- package/src/textnote.ts +0 -175
- package/src/tickable.ts +0 -374
- package/src/tickcontext.ts +0 -280
- package/src/timesignature.ts +0 -229
- package/src/timesignote.ts +0 -45
- package/src/tremolo.ts +0 -51
- package/src/tuning.ts +0 -90
- package/src/tuplet.ts +0 -349
- package/src/typeguard.ts +0 -136
- package/src/util.ts +0 -169
- package/src/version.ts +0 -4
- package/src/vexflow.ts +0 -378
- package/src/vibrato.ts +0 -99
- package/src/vibratobracket.ts +0 -81
- package/src/voice.ts +0 -302
- package/src/web.ts +0 -35
package/src/textbracket.ts
DELETED
|
@@ -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
|
-
}
|
package/src/textdynamics.ts
DELETED
|
@@ -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
|
-
}
|