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/staveline.ts
DELETED
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
//
|
|
3
|
-
// ## Description
|
|
4
|
-
//
|
|
5
|
-
// This file implements `StaveLine` which are simply lines that connect
|
|
6
|
-
// two notes. This object is highly configurable, see the `renderOptions`.
|
|
7
|
-
// A simple line is often used for notating glissando articulations, but you
|
|
8
|
-
// can format a `StaveLine` with arrows or colors for more pedagogical
|
|
9
|
-
// purposes, such as diagrams.
|
|
10
|
-
|
|
11
|
-
import { Element } from './element';
|
|
12
|
-
import { RenderContext } from './rendercontext';
|
|
13
|
-
import { StaveNote } from './stavenote';
|
|
14
|
-
import { Tables } from './tables';
|
|
15
|
-
import { TextJustification } from './textnote';
|
|
16
|
-
import { Category } from './typeguard';
|
|
17
|
-
import { RuntimeError } from './util';
|
|
18
|
-
|
|
19
|
-
export interface StaveLineNotes {
|
|
20
|
-
firstNote: StaveNote;
|
|
21
|
-
firstIndexes: number[];
|
|
22
|
-
lastNote: StaveNote;
|
|
23
|
-
lastIndexes: number[];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Attribution: Arrow rendering implementations based off of
|
|
27
|
-
// Patrick Horgan's article, "Drawing lines and arcs with
|
|
28
|
-
// arrow heads on HTML5 Canvas"
|
|
29
|
-
//
|
|
30
|
-
// Draw an arrow head that connects between 3 coordinates.
|
|
31
|
-
function drawArrowHead(
|
|
32
|
-
ctx: RenderContext,
|
|
33
|
-
x0: number,
|
|
34
|
-
y0: number,
|
|
35
|
-
x1: number,
|
|
36
|
-
y1: number,
|
|
37
|
-
x2: number,
|
|
38
|
-
y2: number
|
|
39
|
-
): void {
|
|
40
|
-
// all cases do this.
|
|
41
|
-
ctx.beginPath();
|
|
42
|
-
ctx.moveTo(x0, y0);
|
|
43
|
-
ctx.lineTo(x1, y1);
|
|
44
|
-
ctx.lineTo(x2, y2);
|
|
45
|
-
ctx.lineTo(x0, y0);
|
|
46
|
-
ctx.closePath();
|
|
47
|
-
|
|
48
|
-
ctx.fill();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export class StaveLine extends Element {
|
|
52
|
-
static get CATEGORY(): string {
|
|
53
|
-
return Category.StaveLine;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Text Positioning
|
|
57
|
-
static readonly TextVerticalPosition = {
|
|
58
|
-
TOP: 1,
|
|
59
|
-
BOTTOM: 2,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
static readonly TextJustification = TextJustification;
|
|
63
|
-
|
|
64
|
-
public renderOptions: {
|
|
65
|
-
paddingLeft: number;
|
|
66
|
-
paddingRight: number;
|
|
67
|
-
lineWidth: number;
|
|
68
|
-
lineDash?: number[];
|
|
69
|
-
roundedEnd: boolean;
|
|
70
|
-
color?: string;
|
|
71
|
-
drawStartArrow: boolean;
|
|
72
|
-
drawEndArrow: boolean;
|
|
73
|
-
arrowheadLength: number;
|
|
74
|
-
arrowheadAngle: number;
|
|
75
|
-
textPositionVertical: number;
|
|
76
|
-
textJustification: number;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// These five instance variables are all initialized by the constructor via this.setNotes(notes).
|
|
80
|
-
protected notes!: StaveLineNotes;
|
|
81
|
-
protected firstNote!: StaveNote;
|
|
82
|
-
protected firstIndexes!: number[];
|
|
83
|
-
protected lastNote!: StaveNote;
|
|
84
|
-
protected lastIndexes!: number[];
|
|
85
|
-
|
|
86
|
-
// Initialize the StaveLine with the given `notes`.
|
|
87
|
-
//
|
|
88
|
-
// `notes` is a struct that has:
|
|
89
|
-
//
|
|
90
|
-
// ```
|
|
91
|
-
// {
|
|
92
|
-
// firstNote: Note,
|
|
93
|
-
// lastNote: Note,
|
|
94
|
-
// firstIndexes: [n1, n2, n3],
|
|
95
|
-
// lastIndexes: [n1, n2, n3]
|
|
96
|
-
// }
|
|
97
|
-
// ```
|
|
98
|
-
constructor(notes: StaveLineNotes) {
|
|
99
|
-
super();
|
|
100
|
-
|
|
101
|
-
this.setNotes(notes);
|
|
102
|
-
|
|
103
|
-
this.text = '';
|
|
104
|
-
|
|
105
|
-
this.renderOptions = {
|
|
106
|
-
// Space to add to the left or the right
|
|
107
|
-
paddingLeft: 4,
|
|
108
|
-
paddingRight: 3,
|
|
109
|
-
|
|
110
|
-
// The width of the line in pixels
|
|
111
|
-
lineWidth: 1,
|
|
112
|
-
// An array of line/space lengths. (TODO/QUESTION: Is this supported in SVG?).
|
|
113
|
-
lineDash: undefined,
|
|
114
|
-
// Can draw rounded line end, instead of a square. (TODO/QUESTION: Is this supported in SVG?).
|
|
115
|
-
roundedEnd: true,
|
|
116
|
-
// The color of the line and arrowheads
|
|
117
|
-
color: undefined,
|
|
118
|
-
|
|
119
|
-
// Flags to draw arrows on each end of the line
|
|
120
|
-
drawStartArrow: false,
|
|
121
|
-
drawEndArrow: false,
|
|
122
|
-
|
|
123
|
-
// The length of the arrowhead sides
|
|
124
|
-
arrowheadLength: 10,
|
|
125
|
-
// The angle of the arrowhead
|
|
126
|
-
arrowheadAngle: Math.PI / 8,
|
|
127
|
-
|
|
128
|
-
// The position of the text
|
|
129
|
-
textPositionVertical: StaveLine.TextVerticalPosition.TOP,
|
|
130
|
-
textJustification: StaveLine.TextJustification.CENTER,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// The the annotation for the `StaveLine`
|
|
135
|
-
setText(text: string): this {
|
|
136
|
-
this.text = text;
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Set the notes for the `StaveLine`
|
|
141
|
-
setNotes(notes: StaveLineNotes): this {
|
|
142
|
-
if (!notes.firstNote && !notes.lastNote) {
|
|
143
|
-
throw new RuntimeError('BadArguments', 'Notes needs to have either firstNote or lastNote set.');
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (!notes.firstIndexes) notes.firstIndexes = [0];
|
|
147
|
-
if (!notes.lastIndexes) notes.lastIndexes = [0];
|
|
148
|
-
|
|
149
|
-
if (notes.firstIndexes.length !== notes.lastIndexes.length) {
|
|
150
|
-
throw new RuntimeError('BadArguments', 'Connected notes must have same number of indexes.');
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
this.notes = notes;
|
|
154
|
-
this.firstNote = notes.firstNote;
|
|
155
|
-
this.firstIndexes = notes.firstIndexes;
|
|
156
|
-
this.lastNote = notes.lastNote;
|
|
157
|
-
this.lastIndexes = notes.lastIndexes;
|
|
158
|
-
return this;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Apply the style of the `StaveLine` to the context
|
|
162
|
-
applyLineStyle(): void {
|
|
163
|
-
const ctx = this.checkContext();
|
|
164
|
-
const renderOptions = this.renderOptions;
|
|
165
|
-
|
|
166
|
-
if (renderOptions.lineDash) {
|
|
167
|
-
ctx.setLineDash(renderOptions.lineDash);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (renderOptions.lineWidth) {
|
|
171
|
-
ctx.setLineWidth(renderOptions.lineWidth);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (renderOptions.roundedEnd) {
|
|
175
|
-
ctx.setLineCap('round');
|
|
176
|
-
} else {
|
|
177
|
-
ctx.setLineCap('square');
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Helper function to draw a line with arrow heads
|
|
182
|
-
protected drawArrowLine(ctx: RenderContext, pt1: { x: number; y: number }, pt2: { x: number; y: number }): void {
|
|
183
|
-
const bothArrows = this.renderOptions.drawStartArrow && this.renderOptions.drawEndArrow;
|
|
184
|
-
|
|
185
|
-
const x1 = pt1.x;
|
|
186
|
-
const y1 = pt1.y;
|
|
187
|
-
const x2 = pt2.x;
|
|
188
|
-
const y2 = pt2.y;
|
|
189
|
-
|
|
190
|
-
// For ends with arrow we actually want to stop before we get to the arrow
|
|
191
|
-
// so that wide lines won't put a flat end on the arrow.
|
|
192
|
-
const distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
|
193
|
-
const ratio = (distance - this.renderOptions.arrowheadLength / 3) / distance;
|
|
194
|
-
let endX;
|
|
195
|
-
let endY;
|
|
196
|
-
let startX;
|
|
197
|
-
let startY;
|
|
198
|
-
if (this.renderOptions.drawEndArrow || bothArrows) {
|
|
199
|
-
endX = Math.round(x1 + (x2 - x1) * ratio);
|
|
200
|
-
endY = Math.round(y1 + (y2 - y1) * ratio);
|
|
201
|
-
} else {
|
|
202
|
-
endX = x2;
|
|
203
|
-
endY = y2;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (this.renderOptions.drawStartArrow || bothArrows) {
|
|
207
|
-
startX = x1 + (x2 - x1) * (1 - ratio);
|
|
208
|
-
startY = y1 + (y2 - y1) * (1 - ratio);
|
|
209
|
-
} else {
|
|
210
|
-
startX = x1;
|
|
211
|
-
startY = y1;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (this.renderOptions.color) {
|
|
215
|
-
ctx.setStrokeStyle(this.renderOptions.color);
|
|
216
|
-
ctx.setFillStyle(this.renderOptions.color);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Draw the shaft of the arrow
|
|
220
|
-
ctx.beginPath();
|
|
221
|
-
ctx.moveTo(startX, startY);
|
|
222
|
-
ctx.lineTo(endX, endY);
|
|
223
|
-
ctx.stroke();
|
|
224
|
-
ctx.closePath();
|
|
225
|
-
|
|
226
|
-
// calculate the angle of the line
|
|
227
|
-
const lineAngle = Math.atan2(y2 - y1, x2 - x1);
|
|
228
|
-
// h is the line length of a side of the arrow head
|
|
229
|
-
const h = Math.abs(this.renderOptions.arrowheadLength / Math.cos(this.renderOptions.arrowheadAngle));
|
|
230
|
-
|
|
231
|
-
let angle1;
|
|
232
|
-
let angle2;
|
|
233
|
-
let topX;
|
|
234
|
-
let topY;
|
|
235
|
-
let bottomX;
|
|
236
|
-
let bottomY;
|
|
237
|
-
|
|
238
|
-
if (this.renderOptions.drawEndArrow || bothArrows) {
|
|
239
|
-
angle1 = lineAngle + Math.PI + this.renderOptions.arrowheadAngle;
|
|
240
|
-
topX = x2 + Math.cos(angle1) * h;
|
|
241
|
-
topY = y2 + Math.sin(angle1) * h;
|
|
242
|
-
|
|
243
|
-
angle2 = lineAngle + Math.PI - this.renderOptions.arrowheadAngle;
|
|
244
|
-
bottomX = x2 + Math.cos(angle2) * h;
|
|
245
|
-
bottomY = y2 + Math.sin(angle2) * h;
|
|
246
|
-
|
|
247
|
-
drawArrowHead(ctx, topX, topY, x2, y2, bottomX, bottomY);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (this.renderOptions.drawStartArrow || bothArrows) {
|
|
251
|
-
angle1 = lineAngle + this.renderOptions.arrowheadAngle;
|
|
252
|
-
topX = x1 + Math.cos(angle1) * h;
|
|
253
|
-
topY = y1 + Math.sin(angle1) * h;
|
|
254
|
-
|
|
255
|
-
angle2 = lineAngle - this.renderOptions.arrowheadAngle;
|
|
256
|
-
bottomX = x1 + Math.cos(angle2) * h;
|
|
257
|
-
bottomY = y1 + Math.sin(angle2) * h;
|
|
258
|
-
|
|
259
|
-
drawArrowHead(ctx, topX, topY, x1, y1, bottomX, bottomY);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Renders the `StaveLine` on the context
|
|
264
|
-
draw(): this {
|
|
265
|
-
const ctx = this.checkContext();
|
|
266
|
-
this.setRendered();
|
|
267
|
-
|
|
268
|
-
const firstNote = this.firstNote;
|
|
269
|
-
const lastNote = this.lastNote;
|
|
270
|
-
const renderOptions = this.renderOptions;
|
|
271
|
-
|
|
272
|
-
ctx.save();
|
|
273
|
-
this.applyLineStyle();
|
|
274
|
-
|
|
275
|
-
// Cycle through each set of indexes and draw lines
|
|
276
|
-
let startPosition = { x: 0, y: 0 };
|
|
277
|
-
let endPosition = { x: 0, y: 0 };
|
|
278
|
-
this.firstIndexes.forEach((firstIndex, i) => {
|
|
279
|
-
const lastIndex = this.lastIndexes[i];
|
|
280
|
-
|
|
281
|
-
// Get initial coordinates for the start/end of the line
|
|
282
|
-
startPosition = firstNote.getModifierStartXY(2, firstIndex);
|
|
283
|
-
endPosition = lastNote.getModifierStartXY(1, lastIndex);
|
|
284
|
-
const upwardsSlope = startPosition.y > endPosition.y;
|
|
285
|
-
|
|
286
|
-
// Adjust `x` coordinates for modifiers
|
|
287
|
-
startPosition.x += firstNote.getMetrics().modRightPx + renderOptions.paddingLeft;
|
|
288
|
-
endPosition.x -= lastNote.getMetrics().modLeftPx + renderOptions.paddingRight;
|
|
289
|
-
|
|
290
|
-
// Adjust first `x` coordinates for displacements
|
|
291
|
-
const noteheadWidth = firstNote.getGlyphWidth();
|
|
292
|
-
const firstDisplaced = firstNote.getKeyProps()[firstIndex].displaced;
|
|
293
|
-
if (firstDisplaced && firstNote.getStemDirection() === 1) {
|
|
294
|
-
startPosition.x += noteheadWidth + renderOptions.paddingLeft;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// Adjust last `x` coordinates for displacements
|
|
298
|
-
const lastDisplaced = lastNote.getKeyProps()[lastIndex].displaced;
|
|
299
|
-
if (lastDisplaced && lastNote.getStemDirection() === -1) {
|
|
300
|
-
endPosition.x -= noteheadWidth + renderOptions.paddingRight;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Adjust y position better if it's not coming from the center of the note
|
|
304
|
-
startPosition.y += upwardsSlope ? -3 : 1;
|
|
305
|
-
endPosition.y += upwardsSlope ? 2 : 0;
|
|
306
|
-
|
|
307
|
-
this.drawArrowLine(ctx, startPosition, endPosition);
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
ctx.restore();
|
|
311
|
-
|
|
312
|
-
// Determine the x coordinate where to start the text
|
|
313
|
-
const textWidth = this.width;
|
|
314
|
-
const justification = renderOptions.textJustification;
|
|
315
|
-
let x = 0;
|
|
316
|
-
if (justification === StaveLine.TextJustification.LEFT) {
|
|
317
|
-
x = startPosition.x;
|
|
318
|
-
} else if (justification === StaveLine.TextJustification.CENTER) {
|
|
319
|
-
const deltaX = endPosition.x - startPosition.x;
|
|
320
|
-
const centerX = deltaX / 2 + startPosition.x;
|
|
321
|
-
x = centerX - textWidth / 2;
|
|
322
|
-
} else if (justification === StaveLine.TextJustification.RIGHT) {
|
|
323
|
-
x = endPosition.x - textWidth;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// Determine the y value to start the text
|
|
327
|
-
let y = 0;
|
|
328
|
-
const verticalPosition = renderOptions.textPositionVertical;
|
|
329
|
-
if (verticalPosition === StaveLine.TextVerticalPosition.TOP) {
|
|
330
|
-
y = firstNote.checkStave().getYForTopText();
|
|
331
|
-
} else if (verticalPosition === StaveLine.TextVerticalPosition.BOTTOM) {
|
|
332
|
-
y = firstNote.checkStave().getYForBottomText(Tables.TEXT_HEIGHT_OFFSET_HACK);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// Draw the text
|
|
336
|
-
const color = renderOptions.color;
|
|
337
|
-
this.applyStyle(ctx, { fillStyle: color, strokeStyle: color });
|
|
338
|
-
this.renderText(ctx, x, y);
|
|
339
|
-
this.restoreStyle(ctx);
|
|
340
|
-
|
|
341
|
-
return this;
|
|
342
|
-
}
|
|
343
|
-
}
|
package/src/stavemodifier.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
//
|
|
3
|
-
// ## Description
|
|
4
|
-
// A base class for stave modifiers (e.g. clefs, key signatures)
|
|
5
|
-
|
|
6
|
-
import { Element } from './element';
|
|
7
|
-
import { Stave } from './stave';
|
|
8
|
-
import { Category } from './typeguard';
|
|
9
|
-
import { defined } from './util';
|
|
10
|
-
|
|
11
|
-
export interface LayoutMetrics {
|
|
12
|
-
xMin: number;
|
|
13
|
-
xMax: number;
|
|
14
|
-
paddingLeft: number;
|
|
15
|
-
paddingRight: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export enum StaveModifierPosition {
|
|
19
|
-
CENTER = 0,
|
|
20
|
-
LEFT = 1,
|
|
21
|
-
RIGHT = 2,
|
|
22
|
-
ABOVE = 3,
|
|
23
|
-
BELOW = 4,
|
|
24
|
-
BEGIN = 5,
|
|
25
|
-
END = 6,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export class StaveModifier extends Element {
|
|
29
|
-
static get CATEGORY(): string {
|
|
30
|
-
return Category.StaveModifier;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static get Position(): typeof StaveModifierPosition {
|
|
34
|
-
return StaveModifierPosition;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
protected padding: number;
|
|
38
|
-
protected position: StaveModifierPosition;
|
|
39
|
-
protected stave?: Stave;
|
|
40
|
-
protected layoutMetrics?: LayoutMetrics;
|
|
41
|
-
|
|
42
|
-
constructor() {
|
|
43
|
-
super();
|
|
44
|
-
|
|
45
|
-
this.padding = 10;
|
|
46
|
-
this.position = StaveModifierPosition.ABOVE;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
getPosition(): number {
|
|
50
|
-
return this.position;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
setPosition(position: number): this {
|
|
54
|
-
this.position = position;
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
getStave(): Stave | undefined {
|
|
59
|
-
return this.stave;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
checkStave(): Stave {
|
|
63
|
-
return defined(this.stave, 'NoStave', 'No stave attached to instance.');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
setStave(stave: Stave): this {
|
|
67
|
-
this.stave = stave;
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
getPadding(index: number): number {
|
|
72
|
-
return index !== undefined && index < 2 ? 0 : this.padding;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
setPadding(padding: number): this {
|
|
76
|
-
this.padding = padding;
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
setLayoutMetrics(layoutMetrics: LayoutMetrics): this {
|
|
81
|
-
this.layoutMetrics = layoutMetrics;
|
|
82
|
-
return this;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
getLayoutMetrics(): LayoutMetrics | undefined {
|
|
86
|
-
return this.layoutMetrics;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// eslint-disable-next-line
|
|
90
|
-
draw(...args: any[]): void {
|
|
91
|
-
// DO NOTHING.
|
|
92
|
-
}
|
|
93
|
-
}
|