vexflow 4.0.1-beta.0 → 4.0.1-beta.1
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 +126 -26
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +94 -26
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow-gonville.js +2 -2
- package/build/cjs/vexflow-gonville.js.map +1 -1
- package/build/cjs/vexflow-petaluma.js +2 -2
- package/build/cjs/vexflow-petaluma.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/src/version.js +3 -3
- package/package.json +1 -1
- package/src/note.ts +2 -2
- package/src/stavenote.ts +80 -16
- package/build/esm/entry/vexflow-bravura.js +0 -11
- package/build/esm/entry/vexflow-core.js +0 -54
- package/build/esm/entry/vexflow-debug-with-tests.js +0 -4
- package/build/esm/entry/vexflow-debug.js +0 -3
- package/build/esm/entry/vexflow-font-bravura.js +0 -7
- package/build/esm/entry/vexflow-font-custom.js +0 -7
- package/build/esm/entry/vexflow-font-gonville.js +0 -7
- package/build/esm/entry/vexflow-font-petaluma.js +0 -7
- package/build/esm/entry/vexflow-gonville.js +0 -11
- package/build/esm/entry/vexflow-petaluma.js +0 -11
- package/build/esm/entry/vexflow.js +0 -9
- package/build/esm/src/accidental.js +0 -348
- package/build/esm/src/annotation.js +0 -213
- package/build/esm/src/articulation.js +0 -264
- package/build/esm/src/barnote.js +0 -58
- package/build/esm/src/beam.js +0 -632
- package/build/esm/src/bend.js +0 -202
- package/build/esm/src/boundingbox.js +0 -59
- package/build/esm/src/boundingboxcomputation.js +0 -107
- package/build/esm/src/canvascontext.js +0 -202
- package/build/esm/src/chordsymbol.js +0 -578
- package/build/esm/src/clef.js +0 -153
- package/build/esm/src/clefnote.js +0 -65
- package/build/esm/src/crescendo.js +0 -77
- package/build/esm/src/curve.js +0 -118
- package/build/esm/src/dot.js +0 -137
- package/build/esm/src/easyscore.js +0 -374
- package/build/esm/src/element.js +0 -216
- package/build/esm/src/factory.js +0 -440
- package/build/esm/src/flow.js +0 -275
- package/build/esm/src/font.js +0 -264
- package/build/esm/src/fonts/bravura_glyphs.js +0 -3239
- package/build/esm/src/fonts/bravura_metrics.js +0 -507
- package/build/esm/src/fonts/custom_glyphs.js +0 -78
- package/build/esm/src/fonts/custom_metrics.js +0 -5
- package/build/esm/src/fonts/gonville_glyphs.js +0 -828
- package/build/esm/src/fonts/gonville_metrics.js +0 -421
- package/build/esm/src/fonts/load_all.js +0 -10
- package/build/esm/src/fonts/load_bravura.js +0 -6
- package/build/esm/src/fonts/load_custom.js +0 -6
- package/build/esm/src/fonts/load_gonville.js +0 -6
- package/build/esm/src/fonts/load_petaluma.js +0 -6
- package/build/esm/src/fonts/petaluma_glyphs.js +0 -1335
- package/build/esm/src/fonts/petaluma_metrics.js +0 -536
- package/build/esm/src/fonts/petalumascript_glyphs.js +0 -863
- package/build/esm/src/fonts/robotoslab_glyphs.js +0 -863
- package/build/esm/src/fonts/textfonts.js +0 -44
- package/build/esm/src/formatter.js +0 -568
- package/build/esm/src/fraction.js +0 -171
- package/build/esm/src/frethandfinger.js +0 -156
- package/build/esm/src/ghostnote.js +0 -50
- package/build/esm/src/glyph.js +0 -331
- package/build/esm/src/glyphnote.js +0 -55
- package/build/esm/src/gracenote.js +0 -133
- package/build/esm/src/gracenotegroup.js +0 -128
- package/build/esm/src/gracetabnote.js +0 -12
- package/build/esm/src/index.js +0 -91
- package/build/esm/src/keymanager.js +0 -99
- package/build/esm/src/keysignature.js +0 -250
- package/build/esm/src/keysignote.js +0 -28
- package/build/esm/src/modifier.js +0 -128
- package/build/esm/src/modifiercontext.js +0 -110
- package/build/esm/src/multimeasurerest.js +0 -173
- package/build/esm/src/music.js +0 -322
- package/build/esm/src/note.js +0 -371
- package/build/esm/src/notehead.js +0 -169
- package/build/esm/src/notesubgroup.js +0 -59
- package/build/esm/src/ornament.js +0 -206
- package/build/esm/src/parenthesis.js +0 -76
- package/build/esm/src/parser.js +0 -164
- package/build/esm/src/pedalmarking.js +0 -192
- package/build/esm/src/registry.js +0 -81
- package/build/esm/src/rendercontext.js +0 -24
- package/build/esm/src/renderer.js +0 -112
- package/build/esm/src/repeatnote.js +0 -22
- package/build/esm/src/stave.js +0 -547
- package/build/esm/src/stavebarline.js +0 -182
- package/build/esm/src/staveconnector.js +0 -196
- package/build/esm/src/stavehairpin.js +0 -120
- package/build/esm/src/staveline.js +0 -218
- package/build/esm/src/stavemodifier.js +0 -77
- package/build/esm/src/stavenote.js +0 -799
- package/build/esm/src/staverepetition.js +0 -155
- package/build/esm/src/stavesection.js +0 -58
- package/build/esm/src/stavetempo.js +0 -91
- package/build/esm/src/stavetext.js +0 -82
- package/build/esm/src/stavetie.js +0 -141
- package/build/esm/src/stavevolta.js +0 -67
- package/build/esm/src/stem.js +0 -131
- package/build/esm/src/stemmablenote.js +0 -193
- package/build/esm/src/stringnumber.js +0 -231
- package/build/esm/src/strokes.js +0 -200
- package/build/esm/src/svgcontext.js +0 -414
- package/build/esm/src/system.js +0 -116
- package/build/esm/src/tables.js +0 -1102
- package/build/esm/src/tabnote.js +0 -299
- package/build/esm/src/tabslide.js +0 -76
- package/build/esm/src/tabstave.js +0 -17
- package/build/esm/src/tabtie.js +0 -19
- package/build/esm/src/textbracket.js +0 -144
- package/build/esm/src/textdynamics.js +0 -81
- package/build/esm/src/textformatter.js +0 -177
- package/build/esm/src/textnote.js +0 -176
- package/build/esm/src/tickable.js +0 -214
- package/build/esm/src/tickcontext.js +0 -170
- package/build/esm/src/timesigglyph.js +0 -85
- package/build/esm/src/timesignature.js +0 -89
- package/build/esm/src/timesignote.js +0 -32
- package/build/esm/src/tremolo.js +0 -47
- package/build/esm/src/tuning.js +0 -54
- package/build/esm/src/tuplet.js +0 -240
- package/build/esm/src/typeguard.js +0 -30
- package/build/esm/src/util.js +0 -58
- package/build/esm/src/vex.js +0 -51
- package/build/esm/src/vibrato.js +0 -100
- package/build/esm/src/vibratobracket.js +0 -50
- package/build/esm/src/voice.js +0 -187
- package/build/esm/src/web.js +0 -15
- package/build/esm/tests/accidental_tests.js +0 -974
- package/build/esm/tests/annotation_tests.js +0 -377
- package/build/esm/tests/articulation_tests.js +0 -365
- package/build/esm/tests/auto_beam_formatting_tests.js +0 -548
- package/build/esm/tests/bach_tests.js +0 -335
- package/build/esm/tests/barline_tests.js +0 -52
- package/build/esm/tests/beam_tests.js +0 -595
- package/build/esm/tests/bend_tests.js +0 -215
- package/build/esm/tests/boundingbox_tests.js +0 -53
- package/build/esm/tests/boundingboxcomputation_tests.js +0 -183
- package/build/esm/tests/chordsymbol_tests.js +0 -320
- package/build/esm/tests/clef_tests.js +0 -131
- package/build/esm/tests/curve_tests.js +0 -118
- package/build/esm/tests/dot_tests.js +0 -123
- package/build/esm/tests/easyscore_tests.js +0 -459
- package/build/esm/tests/factory_tests.js +0 -44
- package/build/esm/tests/font_tests.js +0 -135
- package/build/esm/tests/formatter/framestack.js +0 -61
- package/build/esm/tests/formatter/tests.js +0 -203
- package/build/esm/tests/formatter_tests.js +0 -669
- package/build/esm/tests/fraction_tests.js +0 -72
- package/build/esm/tests/ghostnote_tests.js +0 -77
- package/build/esm/tests/glyphnote_tests.js +0 -113
- package/build/esm/tests/gracenote_tests.js +0 -370
- package/build/esm/tests/gracetabnote_tests.js +0 -79
- package/build/esm/tests/index.js +0 -68
- package/build/esm/tests/key_clef_tests.js +0 -103
- package/build/esm/tests/keymanager_tests.js +0 -68
- package/build/esm/tests/keysignature_tests.js +0 -308
- package/build/esm/tests/mocks.js +0 -71
- package/build/esm/tests/modifier_tests.js +0 -24
- package/build/esm/tests/multimeasurerest_tests.js +0 -141
- package/build/esm/tests/music_tests.js +0 -161
- package/build/esm/tests/notehead_tests.js +0 -137
- package/build/esm/tests/notesubgroup_tests.js +0 -149
- package/build/esm/tests/offscreencanvas_tests.js +0 -47
- package/build/esm/tests/ornament_tests.js +0 -298
- package/build/esm/tests/parser_tests.js +0 -122
- package/build/esm/tests/pedalmarking_tests.js +0 -64
- package/build/esm/tests/percussion_tests.js +0 -180
- package/build/esm/tests/registry_tests.js +0 -64
- package/build/esm/tests/renderer_tests.js +0 -113
- package/build/esm/tests/rests_tests.js +0 -248
- package/build/esm/tests/rhythm_tests.js +0 -357
- package/build/esm/tests/stave_tests.js +0 -560
- package/build/esm/tests/staveconnector_tests.js +0 -402
- package/build/esm/tests/stavehairpin_tests.js +0 -90
- package/build/esm/tests/staveline_tests.js +0 -122
- package/build/esm/tests/stavemodifier_tests.js +0 -51
- package/build/esm/tests/stavenote_tests.js +0 -835
- package/build/esm/tests/stavetie_tests.js +0 -108
- package/build/esm/tests/stringnumber_tests.js +0 -259
- package/build/esm/tests/strokes_tests.js +0 -275
- package/build/esm/tests/style_tests.js +0 -98
- package/build/esm/tests/support/qunit.js +0 -2765
- package/build/esm/tests/tabnote_tests.js +0 -474
- package/build/esm/tests/tabslide_tests.js +0 -135
- package/build/esm/tests/tabstave_tests.js +0 -23
- package/build/esm/tests/tabtie_tests.js +0 -173
- package/build/esm/tests/textbracket_tests.js +0 -100
- package/build/esm/tests/textformatter_tests.js +0 -24
- package/build/esm/tests/textnote_tests.js +0 -215
- package/build/esm/tests/threevoice_tests.js +0 -132
- package/build/esm/tests/tickcontext_tests.js +0 -36
- package/build/esm/tests/timesignature_tests.js +0 -134
- package/build/esm/tests/tremolo_tests.js +0 -75
- package/build/esm/tests/tuning_tests.js +0 -56
- package/build/esm/tests/tuplet_tests.js +0 -450
- package/build/esm/tests/typeguard_tests.js +0 -82
- package/build/esm/tests/vexflow_test_helpers.js +0 -266
- package/build/esm/tests/vf_prefix_tests.js +0 -115
- package/build/esm/tests/vibrato_tests.js +0 -92
- package/build/esm/tests/vibratobracket_tests.js +0 -45
- package/build/esm/tests/voice_tests.js +0 -69
- package/build/types/entry/vexflow-bravura.d.ts +0 -3
- package/build/types/entry/vexflow-core.d.ts +0 -3
- package/build/types/entry/vexflow-debug.d.ts +0 -3
- package/build/types/entry/vexflow-font-bravura.d.ts +0 -3771
- package/build/types/entry/vexflow-font-custom.d.ts +0 -86
- package/build/types/entry/vexflow-font-gonville.d.ts +0 -1267
- package/build/types/entry/vexflow-font-petaluma.d.ts +0 -1896
- package/build/types/entry/vexflow-gonville.d.ts +0 -3
- package/build/types/entry/vexflow-petaluma.d.ts +0 -3
- package/build/types/entry/vexflow.d.ts +0 -3
- package/build/types/src/accidental.d.ts +0 -66
- package/build/types/src/annotation.d.ts +0 -60
- package/build/types/src/articulation.d.ts +0 -62
- package/build/types/src/barnote.d.ts +0 -29
- package/build/types/src/beam.d.ts +0 -124
- package/build/types/src/bend.d.ts +0 -73
- package/build/types/src/boundingbox.d.ts +0 -42
- package/build/types/src/boundingboxcomputation.d.ts +0 -33
- package/build/types/src/canvascontext.d.ts +0 -89
- package/build/types/src/chordsymbol.d.ts +0 -149
- package/build/types/src/clef.d.ts +0 -48
- package/build/types/src/clefnote.d.ts +0 -25
- package/build/types/src/crescendo.d.ts +0 -27
- package/build/types/src/curve.d.ts +0 -41
- package/build/types/src/dot.d.ts +0 -20
- package/build/types/src/easyscore.d.ts +0 -148
- package/build/types/src/element.d.ts +0 -202
- package/build/types/src/factory.d.ts +0 -271
- package/build/types/src/flow.d.ts +0 -245
- package/build/types/src/font.d.ts +0 -181
- package/build/types/src/fonts/bravura_glyphs.d.ts +0 -3239
- package/build/types/src/fonts/bravura_metrics.d.ts +0 -533
- package/build/types/src/fonts/custom_glyphs.d.ts +0 -78
- package/build/types/src/fonts/custom_metrics.d.ts +0 -5
- package/build/types/src/fonts/gonville_glyphs.d.ts +0 -828
- package/build/types/src/fonts/gonville_metrics.d.ts +0 -440
- package/build/types/src/fonts/load_all.d.ts +0 -1
- package/build/types/src/fonts/load_bravura.d.ts +0 -1
- package/build/types/src/fonts/load_custom.d.ts +0 -1
- package/build/types/src/fonts/load_gonville.d.ts +0 -1
- package/build/types/src/fonts/load_petaluma.d.ts +0 -1
- package/build/types/src/fonts/petaluma_glyphs.d.ts +0 -1335
- package/build/types/src/fonts/petaluma_metrics.d.ts +0 -562
- package/build/types/src/fonts/petalumascript_glyphs.d.ts +0 -863
- package/build/types/src/fonts/robotoslab_glyphs.d.ts +0 -863
- package/build/types/src/fonts/textfonts.d.ts +0 -1
- package/build/types/src/formatter.d.ts +0 -203
- package/build/types/src/fraction.d.ts +0 -62
- package/build/types/src/frethandfinger.d.ts +0 -22
- package/build/types/src/ghostnote.d.ts +0 -16
- package/build/types/src/glyph.d.ts +0 -139
- package/build/types/src/glyphnote.d.ts +0 -17
- package/build/types/src/gracenote.d.ts +0 -19
- package/build/types/src/gracenotegroup.d.ts +0 -33
- package/build/types/src/gracetabnote.d.ts +0 -5
- package/build/types/src/index.d.ts +0 -91
- package/build/types/src/keymanager.d.ts +0 -25
- package/build/types/src/keysignature.d.ts +0 -50
- package/build/types/src/keysignote.d.ts +0 -11
- package/build/types/src/modifier.d.ts +0 -97
- package/build/types/src/modifiercontext.d.ts +0 -45
- package/build/types/src/multimeasurerest.d.ts +0 -61
- package/build/types/src/music.d.ts +0 -91
- package/build/types/src/note.d.ts +0 -230
- package/build/types/src/notehead.d.ts +0 -70
- package/build/types/src/notesubgroup.d.ts +0 -18
- package/build/types/src/ornament.d.ts +0 -76
- package/build/types/src/parenthesis.d.ts +0 -22
- package/build/types/src/parser.d.ts +0 -45
- package/build/types/src/pedalmarking.d.ts +0 -69
- package/build/types/src/registry.d.ts +0 -40
- package/build/types/src/rendercontext.d.ts +0 -64
- package/build/types/src/renderer.d.ts +0 -35
- package/build/types/src/repeatnote.d.ts +0 -6
- package/build/types/src/stave.d.ts +0 -186
- package/build/types/src/stavebarline.d.ts +0 -28
- package/build/types/src/staveconnector.d.ts +0 -67
- package/build/types/src/stavehairpin.d.ts +0 -56
- package/build/types/src/staveline.d.ts +0 -57
- package/build/types/src/stavemodifier.d.ts +0 -44
- package/build/types/src/stavenote.d.ts +0 -154
- package/build/types/src/staverepetition.d.ts +0 -32
- package/build/types/src/stavesection.d.ts +0 -15
- package/build/types/src/stavetempo.d.ts +0 -25
- package/build/types/src/stavetext.d.ts +0 -25
- package/build/types/src/stavetie.d.ts +0 -59
- package/build/types/src/stavevolta.d.ts +0 -21
- package/build/types/src/stem.d.ts +0 -58
- package/build/types/src/stemmablenote.d.ts +0 -39
- package/build/types/src/stringnumber.d.ts +0 -27
- package/build/types/src/strokes.d.ts +0 -33
- package/build/types/src/svgcontext.d.ts +0 -131
- package/build/types/src/system.d.ts +0 -92
- package/build/types/src/tables.d.ts +0 -96
- package/build/types/src/tabnote.d.ts +0 -44
- package/build/types/src/tabslide.d.ts +0 -34
- package/build/types/src/tabstave.d.ts +0 -7
- package/build/types/src/tabtie.d.ts +0 -18
- package/build/types/src/textbracket.d.ts +0 -55
- package/build/types/src/textdynamics.d.ts +0 -39
- package/build/types/src/textformatter.d.ts +0 -109
- package/build/types/src/textnote.d.ts +0 -49
- package/build/types/src/tickable.d.ts +0 -140
- package/build/types/src/tickcontext.d.ts +0 -82
- package/build/types/src/timesigglyph.d.ts +0 -14
- package/build/types/src/timesignature.d.ts +0 -26
- package/build/types/src/timesignote.d.ts +0 -11
- package/build/types/src/tremolo.d.ts +0 -17
- package/build/types/src/tuning.d.ts +0 -23
- package/build/types/src/tuplet.d.ts +0 -105
- package/build/types/src/typeguard.d.ts +0 -99
- package/build/types/src/util.d.ts +0 -27
- package/build/types/src/version.d.ts +0 -3
- package/build/types/src/vex.d.ts +0 -18
- package/build/types/src/vibrato.d.ts +0 -29
- package/build/types/src/vibratobracket.d.ts +0 -33
- package/build/types/src/voice.d.ts +0 -108
- package/build/types/src/web.d.ts +0 -2
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { RuntimeError } from './util.js';
|
|
2
|
-
export class Fraction {
|
|
3
|
-
constructor(numerator, denominator) {
|
|
4
|
-
this.numerator = 1;
|
|
5
|
-
this.denominator = 1;
|
|
6
|
-
this.set(numerator, denominator);
|
|
7
|
-
}
|
|
8
|
-
static get CATEGORY() {
|
|
9
|
-
return "Fraction";
|
|
10
|
-
}
|
|
11
|
-
static GCD(a, b) {
|
|
12
|
-
if (typeof a !== 'number' || Number.isNaN(a) || typeof b !== 'number' || Number.isNaN(b)) {
|
|
13
|
-
throw new RuntimeError('BadArgument', `Invalid numbers: ${a}, ${b}`);
|
|
14
|
-
}
|
|
15
|
-
let t;
|
|
16
|
-
while (b !== 0) {
|
|
17
|
-
t = b;
|
|
18
|
-
b = a % b;
|
|
19
|
-
a = t;
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
}
|
|
23
|
-
static LCM(a, b) {
|
|
24
|
-
return (a * b) / Fraction.GCD(a, b);
|
|
25
|
-
}
|
|
26
|
-
static LCMM(args) {
|
|
27
|
-
if (args.length === 0) {
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
else if (args.length === 1) {
|
|
31
|
-
return args[0];
|
|
32
|
-
}
|
|
33
|
-
else if (args.length === 2) {
|
|
34
|
-
return Fraction.LCM(args[0], args[1]);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return Fraction.LCM(args.shift(), Fraction.LCMM(args));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
set(numerator = 1, denominator = 1) {
|
|
41
|
-
this.numerator = numerator;
|
|
42
|
-
this.denominator = denominator;
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
value() {
|
|
46
|
-
return this.numerator / this.denominator;
|
|
47
|
-
}
|
|
48
|
-
simplify() {
|
|
49
|
-
let u = this.numerator;
|
|
50
|
-
let d = this.denominator;
|
|
51
|
-
const gcd = Fraction.GCD(u, d);
|
|
52
|
-
u /= gcd;
|
|
53
|
-
d /= gcd;
|
|
54
|
-
if (d < 0) {
|
|
55
|
-
d = -d;
|
|
56
|
-
u = -u;
|
|
57
|
-
}
|
|
58
|
-
return this.set(u, d);
|
|
59
|
-
}
|
|
60
|
-
add(param1 = 0, param2 = 1) {
|
|
61
|
-
const [otherNumerator, otherDenominator] = getNumeratorAndDenominator(param1, param2);
|
|
62
|
-
const lcm = Fraction.LCM(this.denominator, otherDenominator);
|
|
63
|
-
const a = lcm / this.denominator;
|
|
64
|
-
const b = lcm / otherDenominator;
|
|
65
|
-
const u = this.numerator * a + otherNumerator * b;
|
|
66
|
-
return this.set(u, lcm);
|
|
67
|
-
}
|
|
68
|
-
subtract(param1 = 0, param2 = 1) {
|
|
69
|
-
const [otherNumerator, otherDenominator] = getNumeratorAndDenominator(param1, param2);
|
|
70
|
-
const lcm = Fraction.LCM(this.denominator, otherDenominator);
|
|
71
|
-
const a = lcm / this.denominator;
|
|
72
|
-
const b = lcm / otherDenominator;
|
|
73
|
-
const u = this.numerator * a - otherNumerator * b;
|
|
74
|
-
return this.set(u, lcm);
|
|
75
|
-
}
|
|
76
|
-
multiply(param1 = 1, param2 = 1) {
|
|
77
|
-
const [otherNumerator, otherDenominator] = getNumeratorAndDenominator(param1, param2);
|
|
78
|
-
return this.set(this.numerator * otherNumerator, this.denominator * otherDenominator);
|
|
79
|
-
}
|
|
80
|
-
divide(param1 = 1, param2 = 1) {
|
|
81
|
-
const [otherNumerator, otherDenominator] = getNumeratorAndDenominator(param1, param2);
|
|
82
|
-
return this.set(this.numerator * otherDenominator, this.denominator * otherNumerator);
|
|
83
|
-
}
|
|
84
|
-
equals(compare) {
|
|
85
|
-
const a = Fraction.__staticFractionA.copy(compare).simplify();
|
|
86
|
-
const b = Fraction.__staticFractionB.copy(this).simplify();
|
|
87
|
-
return a.numerator === b.numerator && a.denominator === b.denominator;
|
|
88
|
-
}
|
|
89
|
-
greaterThan(compare) {
|
|
90
|
-
const a = Fraction.__staticFractionB.copy(this);
|
|
91
|
-
a.subtract(compare);
|
|
92
|
-
return a.numerator > 0;
|
|
93
|
-
}
|
|
94
|
-
greaterThanEquals(compare) {
|
|
95
|
-
const a = Fraction.__staticFractionB.copy(this);
|
|
96
|
-
a.subtract(compare);
|
|
97
|
-
return a.numerator >= 0;
|
|
98
|
-
}
|
|
99
|
-
lessThan(compare) {
|
|
100
|
-
return !this.greaterThanEquals(compare);
|
|
101
|
-
}
|
|
102
|
-
lessThanEquals(compare) {
|
|
103
|
-
return !this.greaterThan(compare);
|
|
104
|
-
}
|
|
105
|
-
clone() {
|
|
106
|
-
return new Fraction(this.numerator, this.denominator);
|
|
107
|
-
}
|
|
108
|
-
copy(other) {
|
|
109
|
-
if (typeof other === 'number') {
|
|
110
|
-
return this.set(other, 1);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
return this.set(other.numerator, other.denominator);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
quotient() {
|
|
117
|
-
return Math.floor(this.numerator / this.denominator);
|
|
118
|
-
}
|
|
119
|
-
remainder() {
|
|
120
|
-
return this.numerator % this.denominator;
|
|
121
|
-
}
|
|
122
|
-
makeAbs() {
|
|
123
|
-
this.denominator = Math.abs(this.denominator);
|
|
124
|
-
this.numerator = Math.abs(this.numerator);
|
|
125
|
-
return this;
|
|
126
|
-
}
|
|
127
|
-
toString() {
|
|
128
|
-
return `${this.numerator}/${this.denominator}`;
|
|
129
|
-
}
|
|
130
|
-
toSimplifiedString() {
|
|
131
|
-
return Fraction.__staticFractionTmp.copy(this).simplify().toString();
|
|
132
|
-
}
|
|
133
|
-
toMixedString() {
|
|
134
|
-
let s = '';
|
|
135
|
-
const q = this.quotient();
|
|
136
|
-
const f = Fraction.__staticFractionTmp.copy(this);
|
|
137
|
-
if (q < 0) {
|
|
138
|
-
f.makeAbs();
|
|
139
|
-
}
|
|
140
|
-
if (q !== 0) {
|
|
141
|
-
s += q;
|
|
142
|
-
if (f.numerator !== 0) {
|
|
143
|
-
s += ` ${f.toSimplifiedString()}`;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
else if (f.numerator === 0) {
|
|
147
|
-
s = '0';
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
s = f.toSimplifiedString();
|
|
151
|
-
}
|
|
152
|
-
return s;
|
|
153
|
-
}
|
|
154
|
-
parse(str) {
|
|
155
|
-
const i = str.split('/');
|
|
156
|
-
const n = parseInt(i[0], 10);
|
|
157
|
-
const d = i[1] ? parseInt(i[1], 10) : 1;
|
|
158
|
-
return this.set(n, d);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
Fraction.__staticFractionA = new Fraction();
|
|
162
|
-
Fraction.__staticFractionB = new Fraction();
|
|
163
|
-
Fraction.__staticFractionTmp = new Fraction();
|
|
164
|
-
function getNumeratorAndDenominator(n, d = 1) {
|
|
165
|
-
if (typeof n === 'number') {
|
|
166
|
-
return [n, d];
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
return [n.numerator, n.denominator];
|
|
170
|
-
}
|
|
171
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { Font, FontStyle, FontWeight } from './font.js';
|
|
2
|
-
import { Modifier, ModifierPosition } from './modifier.js';
|
|
3
|
-
import { Tables } from './tables.js';
|
|
4
|
-
import { TextFormatter } from './textformatter.js';
|
|
5
|
-
import { RuntimeError } from './util.js';
|
|
6
|
-
export class FretHandFinger extends Modifier {
|
|
7
|
-
constructor(finger) {
|
|
8
|
-
super();
|
|
9
|
-
this.finger = finger;
|
|
10
|
-
this.width = 7;
|
|
11
|
-
this.position = Modifier.Position.LEFT;
|
|
12
|
-
this.x_shift = 0;
|
|
13
|
-
this.y_shift = 0;
|
|
14
|
-
this.x_offset = 0;
|
|
15
|
-
this.y_offset = 0;
|
|
16
|
-
this.resetFont();
|
|
17
|
-
}
|
|
18
|
-
static get CATEGORY() {
|
|
19
|
-
return "FretHandFinger";
|
|
20
|
-
}
|
|
21
|
-
static format(nums, state) {
|
|
22
|
-
const { left_shift, right_shift } = state;
|
|
23
|
-
const num_spacing = 1;
|
|
24
|
-
if (!nums || nums.length === 0)
|
|
25
|
-
return false;
|
|
26
|
-
const nums_list = [];
|
|
27
|
-
let prev_note = null;
|
|
28
|
-
let shiftLeft = 0;
|
|
29
|
-
let shiftRight = 0;
|
|
30
|
-
for (let i = 0; i < nums.length; ++i) {
|
|
31
|
-
const num = nums[i];
|
|
32
|
-
const note = num.getNote();
|
|
33
|
-
const pos = num.getPosition();
|
|
34
|
-
const index = num.checkIndex();
|
|
35
|
-
const props = note.getKeyProps()[index];
|
|
36
|
-
const textFormatter = TextFormatter.create(num.textFont);
|
|
37
|
-
const textHeight = textFormatter.maxHeight;
|
|
38
|
-
if (num.position === ModifierPosition.ABOVE) {
|
|
39
|
-
state.top_text_line += textHeight / Tables.STAVE_LINE_DISTANCE + 0.5;
|
|
40
|
-
}
|
|
41
|
-
if (num.position === ModifierPosition.BELOW) {
|
|
42
|
-
state.text_line += textHeight / Tables.STAVE_LINE_DISTANCE + 0.5;
|
|
43
|
-
}
|
|
44
|
-
if (note !== prev_note) {
|
|
45
|
-
for (let n = 0; n < note.keys.length; ++n) {
|
|
46
|
-
if (left_shift === 0) {
|
|
47
|
-
shiftLeft = Math.max(note.getLeftDisplacedHeadPx(), shiftLeft);
|
|
48
|
-
}
|
|
49
|
-
if (right_shift === 0) {
|
|
50
|
-
shiftRight = Math.max(note.getRightDisplacedHeadPx(), shiftRight);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
prev_note = note;
|
|
54
|
-
}
|
|
55
|
-
nums_list.push({
|
|
56
|
-
note,
|
|
57
|
-
num,
|
|
58
|
-
pos,
|
|
59
|
-
line: props.line,
|
|
60
|
-
shiftL: shiftLeft,
|
|
61
|
-
shiftR: shiftRight,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
nums_list.sort((a, b) => b.line - a.line);
|
|
65
|
-
let numShiftL = 0;
|
|
66
|
-
let numShiftR = 0;
|
|
67
|
-
let xWidthL = 0;
|
|
68
|
-
let xWidthR = 0;
|
|
69
|
-
let lastLine = null;
|
|
70
|
-
let lastNote = null;
|
|
71
|
-
for (let i = 0; i < nums_list.length; ++i) {
|
|
72
|
-
let num_shift = 0;
|
|
73
|
-
const { note, pos, num, line, shiftL, shiftR } = nums_list[i];
|
|
74
|
-
if (line !== lastLine || note !== lastNote) {
|
|
75
|
-
numShiftL = left_shift + shiftL;
|
|
76
|
-
numShiftR = right_shift + shiftR;
|
|
77
|
-
}
|
|
78
|
-
const numWidth = num.getWidth() + num_spacing;
|
|
79
|
-
if (pos === Modifier.Position.LEFT) {
|
|
80
|
-
num.setXShift(left_shift + numShiftL);
|
|
81
|
-
num_shift = left_shift + numWidth;
|
|
82
|
-
xWidthL = num_shift > xWidthL ? num_shift : xWidthL;
|
|
83
|
-
}
|
|
84
|
-
else if (pos === Modifier.Position.RIGHT) {
|
|
85
|
-
num.setXShift(numShiftR);
|
|
86
|
-
num_shift = shiftRight + numWidth;
|
|
87
|
-
xWidthR = num_shift > xWidthR ? num_shift : xWidthR;
|
|
88
|
-
}
|
|
89
|
-
lastLine = line;
|
|
90
|
-
lastNote = note;
|
|
91
|
-
}
|
|
92
|
-
state.left_shift += xWidthL;
|
|
93
|
-
state.right_shift += xWidthR;
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
static easyScoreHook({ fingerings } = {}, note, builder) {
|
|
97
|
-
fingerings === null || fingerings === void 0 ? void 0 : fingerings.split(',').map((fingeringString) => {
|
|
98
|
-
const split = fingeringString.trim().split('.');
|
|
99
|
-
const params = { number: split[0] };
|
|
100
|
-
if (split[1])
|
|
101
|
-
params.position = split[1];
|
|
102
|
-
return builder.getFactory().Fingering(params);
|
|
103
|
-
}).map((fingering, index) => note.addModifier(fingering, index));
|
|
104
|
-
}
|
|
105
|
-
setFretHandFinger(finger) {
|
|
106
|
-
this.finger = finger;
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
getFretHandFinger() {
|
|
110
|
-
return this.finger;
|
|
111
|
-
}
|
|
112
|
-
setOffsetX(x) {
|
|
113
|
-
this.x_offset = x;
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
|
-
setOffsetY(y) {
|
|
117
|
-
this.y_offset = y;
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
draw() {
|
|
121
|
-
const ctx = this.checkContext();
|
|
122
|
-
const note = this.checkAttachedNote();
|
|
123
|
-
this.setRendered();
|
|
124
|
-
const start = note.getModifierStartXY(this.position, this.index);
|
|
125
|
-
let dot_x = start.x + this.x_shift + this.x_offset;
|
|
126
|
-
let dot_y = start.y + this.y_shift + this.y_offset + 5;
|
|
127
|
-
switch (this.position) {
|
|
128
|
-
case Modifier.Position.ABOVE:
|
|
129
|
-
dot_x -= 4;
|
|
130
|
-
dot_y -= 12;
|
|
131
|
-
break;
|
|
132
|
-
case Modifier.Position.BELOW:
|
|
133
|
-
dot_x -= 2;
|
|
134
|
-
dot_y += 10;
|
|
135
|
-
break;
|
|
136
|
-
case Modifier.Position.LEFT:
|
|
137
|
-
dot_x -= this.width;
|
|
138
|
-
break;
|
|
139
|
-
case Modifier.Position.RIGHT:
|
|
140
|
-
dot_x += 1;
|
|
141
|
-
break;
|
|
142
|
-
default:
|
|
143
|
-
throw new RuntimeError('InvalidPosition', `The position ${this.position} does not exist`);
|
|
144
|
-
}
|
|
145
|
-
ctx.save();
|
|
146
|
-
ctx.setFont(this.textFont);
|
|
147
|
-
ctx.fillText('' + this.finger, dot_x, dot_y);
|
|
148
|
-
ctx.restore();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
FretHandFinger.TEXT_FONT = {
|
|
152
|
-
family: Font.SANS_SERIF,
|
|
153
|
-
size: 9,
|
|
154
|
-
weight: FontWeight.BOLD,
|
|
155
|
-
style: FontStyle.NORMAL,
|
|
156
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { StemmableNote } from './stemmablenote.js';
|
|
2
|
-
import { isAnnotation } from './typeguard.js';
|
|
3
|
-
import { RuntimeError } from './util.js';
|
|
4
|
-
const ERROR_MSG = 'Ghost note must have valid initialization data to identify duration.';
|
|
5
|
-
export class GhostNote extends StemmableNote {
|
|
6
|
-
static get CATEGORY() {
|
|
7
|
-
return "GhostNote";
|
|
8
|
-
}
|
|
9
|
-
constructor(parameter) {
|
|
10
|
-
if (!parameter) {
|
|
11
|
-
throw new RuntimeError('BadArguments', ERROR_MSG);
|
|
12
|
-
}
|
|
13
|
-
let noteStruct;
|
|
14
|
-
if (typeof parameter === 'string') {
|
|
15
|
-
noteStruct = { duration: parameter };
|
|
16
|
-
}
|
|
17
|
-
else if (typeof parameter === 'object') {
|
|
18
|
-
noteStruct = parameter;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
throw new RuntimeError('BadArguments', ERROR_MSG);
|
|
22
|
-
}
|
|
23
|
-
super(noteStruct);
|
|
24
|
-
this.setWidth(0);
|
|
25
|
-
}
|
|
26
|
-
isRest() {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
setStave(stave) {
|
|
30
|
-
super.setStave(stave);
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
addToModifierContext(mc) {
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
preFormat() {
|
|
37
|
-
this.preFormatted = true;
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
draw() {
|
|
41
|
-
this.setRendered();
|
|
42
|
-
for (let i = 0; i < this.modifiers.length; ++i) {
|
|
43
|
-
const modifier = this.modifiers[i];
|
|
44
|
-
if (isAnnotation(modifier)) {
|
|
45
|
-
modifier.setContext(this.getContext());
|
|
46
|
-
modifier.drawWithStyle();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
package/build/esm/src/glyph.js
DELETED
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import { BoundingBox } from './boundingbox.js';
|
|
2
|
-
import { BoundingBoxComputation } from './boundingboxcomputation.js';
|
|
3
|
-
import { Element } from './element.js';
|
|
4
|
-
import { defined, RuntimeError } from './util.js';
|
|
5
|
-
class GlyphCacheEntry {
|
|
6
|
-
constructor(fontStack, code, category) {
|
|
7
|
-
this.point = -1;
|
|
8
|
-
this.metrics = Glyph.loadMetrics(fontStack, code, category);
|
|
9
|
-
this.bbox = Glyph.getOutlineBoundingBox(this.metrics.outline, this.metrics.scale, this.metrics.x_shift, this.metrics.y_shift);
|
|
10
|
-
if (category) {
|
|
11
|
-
this.point = Glyph.lookupFontMetric(this.metrics.font, category, code, 'point', -1);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
class GlyphCache {
|
|
16
|
-
constructor() {
|
|
17
|
-
this.cache = new Map();
|
|
18
|
-
}
|
|
19
|
-
lookup(code, category) {
|
|
20
|
-
let entries = this.cache.get(Glyph.CURRENT_CACHE_KEY);
|
|
21
|
-
if (entries === undefined) {
|
|
22
|
-
entries = {};
|
|
23
|
-
this.cache.set(Glyph.CURRENT_CACHE_KEY, entries);
|
|
24
|
-
}
|
|
25
|
-
const key = category ? `${code}%${category}` : code;
|
|
26
|
-
let entry = entries[key];
|
|
27
|
-
if (entry === undefined) {
|
|
28
|
-
entry = new GlyphCacheEntry(Glyph.MUSIC_FONT_STACK, code, category);
|
|
29
|
-
entries[key] = entry;
|
|
30
|
-
}
|
|
31
|
-
return entry;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
class GlyphOutline {
|
|
35
|
-
constructor(outline, originX, originY, scale) {
|
|
36
|
-
this.outline = outline;
|
|
37
|
-
this.originX = originX;
|
|
38
|
-
this.originY = originY;
|
|
39
|
-
this.scale = scale;
|
|
40
|
-
this.i = 0;
|
|
41
|
-
}
|
|
42
|
-
done() {
|
|
43
|
-
return this.i >= this.outline.length;
|
|
44
|
-
}
|
|
45
|
-
next() {
|
|
46
|
-
return this.outline[this.i++];
|
|
47
|
-
}
|
|
48
|
-
nextX() {
|
|
49
|
-
return this.originX + this.outline[this.i++] * this.scale;
|
|
50
|
-
}
|
|
51
|
-
nextY() {
|
|
52
|
-
return this.originY - this.outline[this.i++] * this.scale;
|
|
53
|
-
}
|
|
54
|
-
static parse(str) {
|
|
55
|
-
const result = [];
|
|
56
|
-
const parts = str.split(' ');
|
|
57
|
-
let i = 0;
|
|
58
|
-
while (i < parts.length) {
|
|
59
|
-
switch (parts[i++]) {
|
|
60
|
-
case 'm':
|
|
61
|
-
result.push(0, parseInt(parts[i++]), parseInt(parts[i++]));
|
|
62
|
-
break;
|
|
63
|
-
case 'l':
|
|
64
|
-
result.push(1, parseInt(parts[i++]), parseInt(parts[i++]));
|
|
65
|
-
break;
|
|
66
|
-
case 'q':
|
|
67
|
-
result.push(2, parseInt(parts[i++]), parseInt(parts[i++]), parseInt(parts[i++]), parseInt(parts[i++]));
|
|
68
|
-
break;
|
|
69
|
-
case 'b':
|
|
70
|
-
result.push(3, parseInt(parts[i++]), parseInt(parts[i++]), parseInt(parts[i++]), parseInt(parts[i++]), parseInt(parts[i++]), parseInt(parts[i++]));
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
export class Glyph extends Element {
|
|
78
|
-
constructor(code, point, options) {
|
|
79
|
-
super();
|
|
80
|
-
this.bbox = new BoundingBox(0, 0, 0, 0);
|
|
81
|
-
this.topGlyphs = [];
|
|
82
|
-
this.botGlyphs = [];
|
|
83
|
-
this.options = {};
|
|
84
|
-
this.scale = 1;
|
|
85
|
-
this.code = code;
|
|
86
|
-
this.point = point;
|
|
87
|
-
this.originShift = { x: 0, y: 0 };
|
|
88
|
-
this.x_shift = 0;
|
|
89
|
-
this.y_shift = 0;
|
|
90
|
-
if (options) {
|
|
91
|
-
this.setOptions(options);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
this.reset();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
static get CATEGORY() {
|
|
98
|
-
return "Glyph";
|
|
99
|
-
}
|
|
100
|
-
static lookupFontMetric(font, category, code, key, defaultValue) {
|
|
101
|
-
let value = font.lookupMetric(`glyphs.${category}.${code}.${key}`, undefined);
|
|
102
|
-
if (value === undefined) {
|
|
103
|
-
value = font.lookupMetric(`glyphs.${category}.${key}`, defaultValue);
|
|
104
|
-
}
|
|
105
|
-
return value;
|
|
106
|
-
}
|
|
107
|
-
static lookupGlyph(fontStack, code) {
|
|
108
|
-
defined(fontStack, 'BadFontStack', 'Font stack is misconfigured');
|
|
109
|
-
let glyph;
|
|
110
|
-
let font;
|
|
111
|
-
for (let i = 0; i < fontStack.length; i++) {
|
|
112
|
-
font = fontStack[i];
|
|
113
|
-
glyph = font.getGlyphs()[code];
|
|
114
|
-
if (glyph)
|
|
115
|
-
return { glyph, font };
|
|
116
|
-
}
|
|
117
|
-
throw new RuntimeError('BadGlyph', `Glyph ${code} does not exist in font.`);
|
|
118
|
-
}
|
|
119
|
-
static loadMetrics(fontStack, code, category) {
|
|
120
|
-
const { glyph, font } = Glyph.lookupGlyph(fontStack, code);
|
|
121
|
-
if (!glyph.o)
|
|
122
|
-
throw new RuntimeError('BadGlyph', `Glyph ${code} has no outline defined.`);
|
|
123
|
-
let x_shift = 0;
|
|
124
|
-
let y_shift = 0;
|
|
125
|
-
let scale = 1;
|
|
126
|
-
if (category && font) {
|
|
127
|
-
x_shift = Glyph.lookupFontMetric(font, category, code, 'shiftX', 0);
|
|
128
|
-
y_shift = Glyph.lookupFontMetric(font, category, code, 'shiftY', 0);
|
|
129
|
-
scale = Glyph.lookupFontMetric(font, category, code, 'scale', 1);
|
|
130
|
-
}
|
|
131
|
-
const x_min = glyph.x_min;
|
|
132
|
-
const x_max = glyph.x_max;
|
|
133
|
-
const ha = glyph.ha;
|
|
134
|
-
if (!glyph.cached_outline) {
|
|
135
|
-
glyph.cached_outline = GlyphOutline.parse(glyph.o);
|
|
136
|
-
}
|
|
137
|
-
return {
|
|
138
|
-
x_min,
|
|
139
|
-
x_max,
|
|
140
|
-
x_shift,
|
|
141
|
-
y_shift,
|
|
142
|
-
scale,
|
|
143
|
-
ha,
|
|
144
|
-
outline: glyph.cached_outline,
|
|
145
|
-
font,
|
|
146
|
-
width: x_max - x_min,
|
|
147
|
-
height: ha,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
static renderGlyph(ctx, x_pos, y_pos, point, code, options) {
|
|
151
|
-
var _a;
|
|
152
|
-
const data = Glyph.cache.lookup(code, options === null || options === void 0 ? void 0 : options.category);
|
|
153
|
-
const metrics = data.metrics;
|
|
154
|
-
if (data.point != -1) {
|
|
155
|
-
point = data.point;
|
|
156
|
-
}
|
|
157
|
-
const customScale = (_a = options === null || options === void 0 ? void 0 : options.scale) !== null && _a !== void 0 ? _a : 1;
|
|
158
|
-
const scale = ((point * 72.0) / (metrics.font.getResolution() * 100.0)) * metrics.scale * customScale;
|
|
159
|
-
Glyph.renderOutline(ctx, metrics.outline, scale, x_pos + metrics.x_shift * customScale, y_pos + metrics.y_shift * customScale);
|
|
160
|
-
return metrics;
|
|
161
|
-
}
|
|
162
|
-
static renderOutline(ctx, outline, scale, x_pos, y_pos) {
|
|
163
|
-
const go = new GlyphOutline(outline, x_pos, y_pos, scale);
|
|
164
|
-
ctx.beginPath();
|
|
165
|
-
let x, y;
|
|
166
|
-
while (!go.done()) {
|
|
167
|
-
switch (go.next()) {
|
|
168
|
-
case 0:
|
|
169
|
-
ctx.moveTo(go.nextX(), go.nextY());
|
|
170
|
-
break;
|
|
171
|
-
case 1:
|
|
172
|
-
ctx.lineTo(go.nextX(), go.nextY());
|
|
173
|
-
break;
|
|
174
|
-
case 2:
|
|
175
|
-
x = go.nextX();
|
|
176
|
-
y = go.nextY();
|
|
177
|
-
ctx.quadraticCurveTo(go.nextX(), go.nextY(), x, y);
|
|
178
|
-
break;
|
|
179
|
-
case 3:
|
|
180
|
-
x = go.nextX();
|
|
181
|
-
y = go.nextY();
|
|
182
|
-
ctx.bezierCurveTo(go.nextX(), go.nextY(), go.nextX(), go.nextY(), x, y);
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
ctx.fill();
|
|
187
|
-
}
|
|
188
|
-
static getOutlineBoundingBox(outline, scale, x_pos, y_pos) {
|
|
189
|
-
const go = new GlyphOutline(outline, x_pos, y_pos, scale);
|
|
190
|
-
const bboxComp = new BoundingBoxComputation();
|
|
191
|
-
let penX = x_pos;
|
|
192
|
-
let penY = y_pos;
|
|
193
|
-
let x, y;
|
|
194
|
-
while (!go.done()) {
|
|
195
|
-
switch (go.next()) {
|
|
196
|
-
case 0:
|
|
197
|
-
penX = go.nextX();
|
|
198
|
-
penY = go.nextY();
|
|
199
|
-
break;
|
|
200
|
-
case 1:
|
|
201
|
-
bboxComp.addPoint(penX, penY);
|
|
202
|
-
penX = go.nextX();
|
|
203
|
-
penY = go.nextY();
|
|
204
|
-
bboxComp.addPoint(penX, penY);
|
|
205
|
-
break;
|
|
206
|
-
case 2:
|
|
207
|
-
x = go.nextX();
|
|
208
|
-
y = go.nextY();
|
|
209
|
-
bboxComp.addQuadraticCurve(penX, penY, go.nextX(), go.nextY(), x, y);
|
|
210
|
-
penX = x;
|
|
211
|
-
penY = y;
|
|
212
|
-
break;
|
|
213
|
-
case 3:
|
|
214
|
-
x = go.nextX();
|
|
215
|
-
y = go.nextY();
|
|
216
|
-
bboxComp.addBezierCurve(penX, penY, go.nextX(), go.nextY(), go.nextX(), go.nextY(), x, y);
|
|
217
|
-
penX = x;
|
|
218
|
-
penY = y;
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return new BoundingBox(bboxComp.getX1(), bboxComp.getY1(), bboxComp.width(), bboxComp.height());
|
|
223
|
-
}
|
|
224
|
-
static getWidth(code, point, category) {
|
|
225
|
-
const data = Glyph.cache.lookup(code, category);
|
|
226
|
-
if (data.point != -1) {
|
|
227
|
-
point = data.point;
|
|
228
|
-
}
|
|
229
|
-
const scale = (point * 72) / (data.metrics.font.getResolution() * 100);
|
|
230
|
-
return data.bbox.getW() * scale;
|
|
231
|
-
}
|
|
232
|
-
draw(...args) {
|
|
233
|
-
}
|
|
234
|
-
getCode() {
|
|
235
|
-
return this.code;
|
|
236
|
-
}
|
|
237
|
-
setOptions(options) {
|
|
238
|
-
this.options = Object.assign(Object.assign({}, this.options), options);
|
|
239
|
-
this.reset();
|
|
240
|
-
}
|
|
241
|
-
setPoint(point) {
|
|
242
|
-
this.point = point;
|
|
243
|
-
return this;
|
|
244
|
-
}
|
|
245
|
-
setStave(stave) {
|
|
246
|
-
this.stave = stave;
|
|
247
|
-
return this;
|
|
248
|
-
}
|
|
249
|
-
setXShift(x_shift) {
|
|
250
|
-
this.x_shift = x_shift;
|
|
251
|
-
return this;
|
|
252
|
-
}
|
|
253
|
-
setYShift(y_shift) {
|
|
254
|
-
this.y_shift = y_shift;
|
|
255
|
-
return this;
|
|
256
|
-
}
|
|
257
|
-
reset() {
|
|
258
|
-
const data = Glyph.cache.lookup(this.code, this.options.category);
|
|
259
|
-
this.metrics = data.metrics;
|
|
260
|
-
if (data.point != -1) {
|
|
261
|
-
this.point = data.point;
|
|
262
|
-
}
|
|
263
|
-
this.scale = (this.point * 72) / (this.metrics.font.getResolution() * 100);
|
|
264
|
-
this.bbox = new BoundingBox(data.bbox.getX() * this.scale, data.bbox.getY() * this.scale, data.bbox.getW() * this.scale, data.bbox.getH() * this.scale);
|
|
265
|
-
}
|
|
266
|
-
checkMetrics() {
|
|
267
|
-
return defined(this.metrics, 'BadGlyph', `Glyph ${this.code} is not initialized.`);
|
|
268
|
-
}
|
|
269
|
-
getMetrics() {
|
|
270
|
-
const metrics = this.checkMetrics();
|
|
271
|
-
const metricsScale = metrics.scale;
|
|
272
|
-
return {
|
|
273
|
-
x_min: metrics.x_min * this.scale * metricsScale,
|
|
274
|
-
x_max: metrics.x_max * this.scale * metricsScale,
|
|
275
|
-
width: this.bbox.getW(),
|
|
276
|
-
height: this.bbox.getH(),
|
|
277
|
-
scale: this.scale * metricsScale,
|
|
278
|
-
x_shift: metrics.x_shift,
|
|
279
|
-
y_shift: metrics.y_shift,
|
|
280
|
-
outline: metrics.outline,
|
|
281
|
-
font: metrics.font,
|
|
282
|
-
ha: metrics.ha,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
setOriginX(x) {
|
|
286
|
-
const { bbox } = this;
|
|
287
|
-
const originX = Math.abs(bbox.getX() / bbox.getW());
|
|
288
|
-
const xShift = (x - originX) * bbox.getW();
|
|
289
|
-
this.originShift.x = -xShift;
|
|
290
|
-
}
|
|
291
|
-
setOriginY(y) {
|
|
292
|
-
const { bbox } = this;
|
|
293
|
-
const originY = Math.abs(bbox.getY() / bbox.getH());
|
|
294
|
-
const yShift = (y - originY) * bbox.getH();
|
|
295
|
-
this.originShift.y = -yShift;
|
|
296
|
-
}
|
|
297
|
-
setOrigin(x, y) {
|
|
298
|
-
this.setOriginX(x);
|
|
299
|
-
this.setOriginY(y);
|
|
300
|
-
}
|
|
301
|
-
render(ctx, x, y) {
|
|
302
|
-
const metrics = this.checkMetrics();
|
|
303
|
-
const outline = metrics.outline;
|
|
304
|
-
const scale = this.scale * metrics.scale;
|
|
305
|
-
this.setRendered();
|
|
306
|
-
this.applyStyle(ctx);
|
|
307
|
-
const xPos = x + this.originShift.x + metrics.x_shift;
|
|
308
|
-
const yPos = y + this.originShift.y + metrics.y_shift;
|
|
309
|
-
Glyph.renderOutline(ctx, outline, scale, xPos, yPos);
|
|
310
|
-
this.restoreStyle(ctx);
|
|
311
|
-
}
|
|
312
|
-
checkStave() {
|
|
313
|
-
return defined(this.stave, 'NoStave', 'No stave attached to instance.');
|
|
314
|
-
}
|
|
315
|
-
renderToStave(x) {
|
|
316
|
-
const context = this.checkContext();
|
|
317
|
-
const metrics = this.checkMetrics();
|
|
318
|
-
const stave = this.checkStave();
|
|
319
|
-
const outline = metrics.outline;
|
|
320
|
-
const scale = this.scale * metrics.scale;
|
|
321
|
-
this.setRendered();
|
|
322
|
-
this.applyStyle();
|
|
323
|
-
const xPos = x + this.x_shift + metrics.x_shift;
|
|
324
|
-
const yPos = stave.getYForGlyphs() + this.y_shift + metrics.y_shift;
|
|
325
|
-
Glyph.renderOutline(context, outline, scale, xPos, yPos);
|
|
326
|
-
this.restoreStyle();
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
Glyph.cache = new GlyphCache();
|
|
330
|
-
Glyph.CURRENT_CACHE_KEY = '';
|
|
331
|
-
Glyph.MUSIC_FONT_STACK = [];
|