vexflow 5.2.0 → 5.3.0
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 +2759 -1382
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +1814 -1227
- 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 +10 -3
- package/build/esm/src/articulation.js +24 -6
- package/build/esm/src/beam.js +158 -28
- package/build/esm/src/bend.js +24 -19
- package/build/esm/src/curve.js +27 -53
- package/build/esm/src/dot.js +13 -4
- package/build/esm/src/easyscore/composition.js +40 -1
- package/build/esm/src/easyscore/policies.js +34 -6
- package/build/esm/src/element.js +4 -0
- package/build/esm/src/engravinggeometry.js +150 -0
- package/build/esm/src/engravingprofile.js +44 -0
- package/build/esm/src/factory.js +15 -7
- package/build/esm/src/formatter.js +9 -1
- package/build/esm/src/gracenote.js +43 -38
- package/build/esm/src/gracenotegroup.js +53 -56
- package/build/esm/src/index.js +2 -0
- package/build/esm/src/keysignature.js +1 -1
- package/build/esm/src/modifiercontext.js +11 -0
- package/build/esm/src/notehead.js +11 -6
- package/build/esm/src/ornament.js +38 -18
- package/build/esm/src/proportionalformatter.js +54 -6
- package/build/esm/src/stavenote.js +128 -115
- package/build/esm/src/stavetie.js +39 -7
- package/build/esm/src/stem.js +26 -11
- package/build/esm/src/tickcontext.js +19 -0
- package/build/esm/src/timesignature.js +5 -0
- package/build/esm/src/tuplet.js +57 -17
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +4 -0
- package/build/esm/tests/bend_tests.js +14 -1
- package/build/esm/tests/curve_tests.js +14 -4
- package/build/esm/tests/demo_repertoire_tests.js +27 -0
- package/build/esm/tests/demos/drums.js +54 -0
- package/build/esm/tests/demos/electric.js +63 -0
- package/build/esm/tests/demos/greensleeves.js +90 -0
- package/build/esm/tests/demos/joy.js +61 -0
- package/build/esm/tests/demos/kesh.js +80 -0
- package/build/esm/tests/demos/prelude.js +59 -0
- package/build/esm/tests/demos/quartertones.js +50 -0
- package/build/esm/tests/demos/saints.js +65 -0
- package/build/esm/tests/engraving/score-layout.mjs +75 -0
- package/build/esm/tests/engraving/score-persistence.mjs +262 -0
- package/build/esm/tests/engraving/studies.mjs +279 -0
- package/build/esm/tests/formatter_tests.js +10 -1
- package/build/esm/tests/index.js +1 -0
- package/build/esm/tests/node/audit-dependencies-tests.mjs +42 -0
- package/build/esm/tests/node/easyscore-tests.mjs +71 -0
- package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
- package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
- package/build/esm/tests/node/proportional-spacing-tests.mjs +64 -0
- package/build/esm/tests/node/rendering-tests.mjs +6 -2
- package/build/esm/tests/threevoice_tests.js +11 -1
- package/build/esm/tests/vexflow_test_helpers.js +19 -10
- package/build/esm/tools/audit-dependencies.mjs +61 -0
- package/build/esm/tools/score-fixtures.mjs +23 -6
- package/build/types/src/accidental.d.ts +4 -0
- package/build/types/src/articulation.d.ts +6 -1
- package/build/types/src/beam.d.ts +14 -0
- package/build/types/src/curve.d.ts +9 -0
- package/build/types/src/dot.d.ts +5 -0
- package/build/types/src/easyscore/composition.d.ts +19 -0
- package/build/types/src/easyscore/policies.d.ts +1 -1
- package/build/types/src/element.d.ts +2 -0
- package/build/types/src/engravinggeometry.d.ts +31 -0
- package/build/types/src/engravingprofile.d.ts +20 -0
- package/build/types/src/factory.d.ts +6 -1
- package/build/types/src/formatter.d.ts +3 -3
- package/build/types/src/gracenote.d.ts +7 -0
- package/build/types/src/gracenotegroup.d.ts +7 -2
- package/build/types/src/index.d.ts +2 -0
- package/build/types/src/modifiercontext.d.ts +4 -0
- package/build/types/src/notehead.d.ts +5 -0
- package/build/types/src/ornament.d.ts +7 -0
- package/build/types/src/proportionalformatter.d.ts +11 -2
- package/build/types/src/stavenote.d.ts +20 -2
- package/build/types/src/stavetie.d.ts +4 -0
- package/build/types/src/stem.d.ts +10 -1
- package/build/types/src/tickcontext.d.ts +5 -0
- package/build/types/src/timesignature.d.ts +2 -0
- package/build/types/src/tuplet.d.ts +5 -48
- package/build/types/src/vexflow.d.ts +4 -0
- package/changelog/CHANGELOG.md +17 -0
- package/package.json +7 -2
- package/tests/all.html +277 -0
- package/tests/demo_petzold_tests.ts +435 -0
- package/tests/demos/drums.ts +55 -0
- package/tests/demos/drums.webp +0 -0
- package/tests/demos/electric.ts +70 -0
- package/tests/demos/electric.webp +0 -0
- package/tests/demos/greensleeves.ts +97 -0
- package/tests/demos/greensleeves.webp +0 -0
- package/tests/demos/joy.ts +65 -0
- package/tests/demos/joy.webp +0 -0
- package/tests/demos/kesh.ts +86 -0
- package/tests/demos/kesh.webp +0 -0
- package/tests/demos/prelude.ts +65 -0
- package/tests/demos/prelude.webp +0 -0
- package/tests/demos/quartertones.ts +51 -0
- package/tests/demos/quartertones.webp +0 -0
- package/tests/demos/saints.ts +70 -0
- package/tests/demos/saints.webp +0 -0
- package/tests/flow.html +550 -239
- package/tests/fonts.css +493 -0
- package/tests/minuet.webp +0 -0
|
@@ -951,3 +951,74 @@ test('typed grace notes retain explicit stem direction over automatic defaults',
|
|
|
951
951
|
assert.equal(grace.getStemDirection(), -1);
|
|
952
952
|
assert.equal(grace.isAutoStem(), false);
|
|
953
953
|
});
|
|
954
|
+
test('grace order is explicit and simultaneous signs are independent of voice insertion', () => {
|
|
955
|
+
const marks = (note) => note
|
|
956
|
+
.getModifiers()
|
|
957
|
+
.filter((m) => m instanceof VF.Accidental)
|
|
958
|
+
.map((m) => m.type);
|
|
959
|
+
const voice = (side, pitches) => ({
|
|
960
|
+
notes: [
|
|
961
|
+
{
|
|
962
|
+
note: { keys: ['f#/4'], duration: 'h' },
|
|
963
|
+
grace: { side, notes: pitches.map((key) => ({ keys: [key], duration: '16' })) },
|
|
964
|
+
},
|
|
965
|
+
'F4/h',
|
|
966
|
+
],
|
|
967
|
+
});
|
|
968
|
+
function arrays(voices, graceAccidentals) {
|
|
969
|
+
const result = create().compose({
|
|
970
|
+
accidentals: 'key-aware',
|
|
971
|
+
graceAccidentals,
|
|
972
|
+
staves: [{ id: 'a', measures: [{ voices }] }],
|
|
973
|
+
});
|
|
974
|
+
return result.notes[0][0].map(([host, last]) => {
|
|
975
|
+
const grace = host.getModifiers().find((m) => m instanceof VF.GraceNoteGroup);
|
|
976
|
+
return [grace.getGraceNotes().map(marks), marks(host), marks(last)];
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
const early = voice('before', ['f/4', 'f#/4']);
|
|
980
|
+
const conflict = voice('before', ['fb/4']);
|
|
981
|
+
const expected = [
|
|
982
|
+
[[[], ['#']], ['#'], ['n']],
|
|
983
|
+
[[['b']], ['#'], ['n']],
|
|
984
|
+
];
|
|
985
|
+
assert.deepEqual(arrays([early, conflict], 'ordered'), expected);
|
|
986
|
+
assert.deepEqual(arrays([conflict, early], 'ordered'), expected.toReversed());
|
|
987
|
+
assert.deepEqual(arrays([early], 'explicit'), [[[[], []], ['#'], ['n']]]);
|
|
988
|
+
assert.deepEqual(arrays([voice('after', ['f/4', 'f#/4'])], 'ordered'), [[[['n'], ['#']], ['#'], ['n']]]);
|
|
989
|
+
});
|
|
990
|
+
test('explicit grace cautionaries survive ordered generation and suppress redundant host signs', () => {
|
|
991
|
+
const result = create().compose({
|
|
992
|
+
accidentals: 'key-aware',
|
|
993
|
+
graceAccidentals: 'ordered',
|
|
994
|
+
staves: [
|
|
995
|
+
{
|
|
996
|
+
id: 'a',
|
|
997
|
+
measures: [
|
|
998
|
+
{
|
|
999
|
+
voices: [
|
|
1000
|
+
{
|
|
1001
|
+
notes: [
|
|
1002
|
+
{
|
|
1003
|
+
note: { keys: ['f#/4'], duration: 'w' },
|
|
1004
|
+
grace: {
|
|
1005
|
+
side: 'before',
|
|
1006
|
+
notes: [
|
|
1007
|
+
{ keys: ['f#/4'], duration: '8', accidentals: [{ index: 0, type: '#', cautionary: true }] },
|
|
1008
|
+
],
|
|
1009
|
+
},
|
|
1010
|
+
},
|
|
1011
|
+
],
|
|
1012
|
+
},
|
|
1013
|
+
],
|
|
1014
|
+
},
|
|
1015
|
+
],
|
|
1016
|
+
},
|
|
1017
|
+
],
|
|
1018
|
+
});
|
|
1019
|
+
const [host] = result.notes[0][0][0];
|
|
1020
|
+
const [group] = host.getModifiers();
|
|
1021
|
+
assert.equal(host.getModifiers().length, 1);
|
|
1022
|
+
const marks = group.getGraceNotes()[0].getModifiers();
|
|
1023
|
+
assert.deepEqual(marks.map((m) => [m.type, m.isCautionary()]), [['#', true]]);
|
|
1024
|
+
});
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import assert from 'node:assert/strict';
|
|
11
|
+
import { execFileSync } from 'node:child_process';
|
|
12
|
+
import { readFileSync } from 'node:fs';
|
|
13
|
+
import test from 'node:test';
|
|
14
|
+
import { createCanvas, registerFont } from 'canvas';
|
|
15
|
+
import puppeteer from 'puppeteer';
|
|
16
|
+
import { compositionInput, excerpt, loadScore, saveScore } from '../engraving/score-persistence.mjs';
|
|
17
|
+
import { passageView } from '../engraving/score-layout.mjs';
|
|
18
|
+
const VF = await import(new URL('../../build/esm/entry/vexflow-core.js', import.meta.url));
|
|
19
|
+
const passage = JSON.parse(readFileSync(new URL('../engraving/m1-passage.json', import.meta.url)));
|
|
20
|
+
for (const family of ['Bravura', 'Petaluma', 'Academico']) {
|
|
21
|
+
const name = family.toLowerCase();
|
|
22
|
+
registerFont(new URL(`../../node_modules/@vexflow-fonts/${name}/${name}.otf`, import.meta.url).pathname, { family });
|
|
23
|
+
}
|
|
24
|
+
VF.Element.setTextMeasurementCanvas(createCanvas(1, 1));
|
|
25
|
+
function factory(engraving) {
|
|
26
|
+
const canvas = createCanvas(800, 720);
|
|
27
|
+
const f = new VF.Factory({ renderer: { elementId: null }, engraving }).setContext(new VF.CanvasContext(canvas.getContext('2d')));
|
|
28
|
+
return { f, canvas };
|
|
29
|
+
}
|
|
30
|
+
function profile(family, options = {}) {
|
|
31
|
+
const metadata = JSON.parse(readFileSync(new URL(`../../node_modules/@vexflow-fonts/${family.toLowerCase()}/metadata.json`, import.meta.url)));
|
|
32
|
+
return new VF.EngravingProfile(Object.assign({ musicFont: family, metadata }, options));
|
|
33
|
+
}
|
|
34
|
+
function measured(element) {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const result = VF.measureEngraving(element);
|
|
37
|
+
assert.deepEqual(result.diagnostics, [], element.getCategory());
|
|
38
|
+
assert.ok(((_a = result.ink) === null || _a === void 0 ? void 0 : _a.w) > 0 && ((_b = result.ink) === null || _b === void 0 ? void 0 : _b.h) > 0, element.getCategory());
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
function engravingScene(policy) {
|
|
42
|
+
const { f, canvas } = factory(policy);
|
|
43
|
+
const es = f.EasyScore();
|
|
44
|
+
const notes = es.notes('G4/16, B4/16, (D5 E5)/8, E4/q', { stem: 'up' });
|
|
45
|
+
const beam = f.Beam({ notes: notes.slice(0, 2) });
|
|
46
|
+
const group = f
|
|
47
|
+
.GraceNoteGroup({
|
|
48
|
+
notes: ['c/5', 'a/4'].map((key) => f.GraceNote({ keys: [key], duration: '16', slash: true })),
|
|
49
|
+
slur: true,
|
|
50
|
+
})
|
|
51
|
+
.beamNotes();
|
|
52
|
+
notes[2].addModifier(group, 0);
|
|
53
|
+
for (const type of ['a.', 'a>'])
|
|
54
|
+
notes[3].addModifier(f.Articulation({ type, position: 'below' }), 0);
|
|
55
|
+
const curve = f.Curve({ from: notes[0], to: notes[2], options: { openingDirection: 'down' } });
|
|
56
|
+
const system = f.System({ width: 450, y: 65 });
|
|
57
|
+
system.addStave({ voices: [es.voice(notes, { mode: 'soft' })] });
|
|
58
|
+
const snapshot = () => [beam, ...notes, curve].map(measured);
|
|
59
|
+
return { f, canvas, notes, system, beam, snapshot };
|
|
60
|
+
}
|
|
61
|
+
test('geometry is available before draw and repeats across measure, draw and wide/narrow/wide', () => {
|
|
62
|
+
const policy = profile('Bravura');
|
|
63
|
+
const scene = engravingScene(policy);
|
|
64
|
+
scene.system.format();
|
|
65
|
+
const baseline = scene.snapshot();
|
|
66
|
+
assert.ok(!scene.notes[0].isRendered());
|
|
67
|
+
assert.deepEqual(scene.snapshot(), baseline);
|
|
68
|
+
scene.f.draw({ retain: true });
|
|
69
|
+
assert.deepEqual(scene.snapshot(), baseline);
|
|
70
|
+
scene.system.setWidth(255).format();
|
|
71
|
+
assert.notDeepEqual(scene.snapshot(), baseline);
|
|
72
|
+
scene.system.setWidth(450).format();
|
|
73
|
+
const fresh = engravingScene(policy);
|
|
74
|
+
fresh.system.format();
|
|
75
|
+
assert.deepEqual(scene.snapshot(), fresh.snapshot());
|
|
76
|
+
assert.deepEqual(scene.snapshot(), baseline);
|
|
77
|
+
});
|
|
78
|
+
test('two live scores independently consume glyph metrics, anchors and beam policy', () => {
|
|
79
|
+
const a = engravingScene(profile('Bravura'));
|
|
80
|
+
const b = engravingScene(profile('Petaluma', { beamThickness: 0.7, clearance: 0.5 }));
|
|
81
|
+
a.system.format();
|
|
82
|
+
const original = a.snapshot();
|
|
83
|
+
b.system.format();
|
|
84
|
+
b.f.draw({ retain: true });
|
|
85
|
+
assert.deepEqual(a.snapshot(), original);
|
|
86
|
+
assert.equal(a.notes[0].noteHeads[0].fontInfo.family, 'Bravura');
|
|
87
|
+
assert.equal(b.notes[0].noteHeads[0].fontInfo.family, 'Petaluma');
|
|
88
|
+
assert.equal(a.beam.renderOptions.beamWidth, 5);
|
|
89
|
+
assert.equal(b.beam.renderOptions.beamWidth, 7);
|
|
90
|
+
assert.notEqual(b.notes[0].getHeadInk()[0].w, a.notes[0].getHeadInk()[0].w);
|
|
91
|
+
const glyph = VF.VexFlow.Glyphs.noteheadBlack;
|
|
92
|
+
assert.deepEqual(profile('Petaluma').stemAnchor(glyph, 'up'), [1.336, 0.288]);
|
|
93
|
+
for (const metadata of [
|
|
94
|
+
undefined,
|
|
95
|
+
{},
|
|
96
|
+
{
|
|
97
|
+
fontName: 'Petaluma',
|
|
98
|
+
engravingDefaults: { beamThickness: Infinity },
|
|
99
|
+
glyphsWithAnchors: { noteheadBlack: { stemUpSE: [0, NaN] } },
|
|
100
|
+
},
|
|
101
|
+
]) {
|
|
102
|
+
const fallback = new VF.EngravingProfile({ musicFont: 'Petaluma', metadata });
|
|
103
|
+
assert.equal(fallback.stemAnchor(glyph, 'up'), undefined);
|
|
104
|
+
assert.equal(fallback.beamThickness, 0.5);
|
|
105
|
+
const scene = engravingScene(fallback);
|
|
106
|
+
scene.system.format();
|
|
107
|
+
scene.snapshot();
|
|
108
|
+
}
|
|
109
|
+
assert.throws(() => profile('Bravura', { beamThickness: NaN }), RangeError);
|
|
110
|
+
});
|
|
111
|
+
test('beam clears a head whose attack falls strictly between its stems', () => {
|
|
112
|
+
const build = (peerKey) => {
|
|
113
|
+
const { f } = factory();
|
|
114
|
+
const es = f.EasyScore(), notes = es.notes('C4/8, C4/8', { stem: 'up' });
|
|
115
|
+
const others = ['b/4', peerKey, 'b/4'].map((key, i) => f.StaveNote({ keys: [key], duration: ['16r', '16', '8r'][i], stemDirection: -1 }));
|
|
116
|
+
const beam = f.Beam({ notes });
|
|
117
|
+
const system = f.System({ width: 360, y: 50 });
|
|
118
|
+
system.addStave({ voices: [es.voice(notes, { mode: 'soft' }), es.voice(others, { mode: 'soft' })] });
|
|
119
|
+
system.format();
|
|
120
|
+
return { strip: measured(beam).ink, obstacle: others[1].getHeadInk()[0] };
|
|
121
|
+
};
|
|
122
|
+
const control = build('g/5'), actual = build('c/5');
|
|
123
|
+
assert.ok(actual.obstacle.x > actual.strip.x && actual.obstacle.x + actual.obstacle.w < actual.strip.x + actual.strip.w);
|
|
124
|
+
assert.ok(control.strip.y < actual.obstacle.y + actual.obstacle.h && control.strip.y + control.strip.h > actual.obstacle.y);
|
|
125
|
+
assert.ok(actual.strip.y >= actual.obstacle.y + actual.obstacle.h);
|
|
126
|
+
});
|
|
127
|
+
test('lyrics and cross-staff stems consume the pre-draw coordinates', () => {
|
|
128
|
+
const { f } = factory(), es = f.EasyScore();
|
|
129
|
+
const notes = es.notes('G4/8, C5/8', { stem: 'down' });
|
|
130
|
+
const system = f.System({ width: 330, y: 10 });
|
|
131
|
+
const top = system.addStave({ voices: [es.voice(notes, { mode: 'soft' })] });
|
|
132
|
+
const bottom = system.addStave({ voices: [] });
|
|
133
|
+
notes[1].setStave(bottom);
|
|
134
|
+
const beam = f.Beam({ notes });
|
|
135
|
+
const lyrics = notes.map((n, i) => {
|
|
136
|
+
const mark = f.Annotation({ text: ['sum', 'mer'][i], vJustify: 'bottom' });
|
|
137
|
+
n.addModifier(mark, 0);
|
|
138
|
+
return mark;
|
|
139
|
+
});
|
|
140
|
+
system.format();
|
|
141
|
+
const obstacle = measured(beam);
|
|
142
|
+
assert.equal(notes[0].getStave(), top);
|
|
143
|
+
assert.equal(notes[1].getStave(), bottom);
|
|
144
|
+
for (const [i, n] of notes.entries())
|
|
145
|
+
assert.equal(obstacle.anchors['stem' + i].y, measured(n).anchors.stemTip.y + VF.Stem.WIDTH / 2);
|
|
146
|
+
function placeLyricRow() {
|
|
147
|
+
const extension = (element) => (lyrics.includes(element) ? { parts: [], anchors: {} } : undefined);
|
|
148
|
+
const obstacles = [beam, ...notes].map((element) => VF.measureEngraving(element, { extension }).layout);
|
|
149
|
+
const baseline = Math.max(...obstacles.map((box) => box.y + box.h)) +
|
|
150
|
+
top.getSpacingBetweenLines() +
|
|
151
|
+
Math.max(...lyrics.map((mark) => mark.getTextMetrics().actualBoundingBoxAscent));
|
|
152
|
+
lyrics.forEach((mark) => mark.setTextBaseline(baseline));
|
|
153
|
+
return baseline;
|
|
154
|
+
}
|
|
155
|
+
const baseline = placeLyricRow();
|
|
156
|
+
assert.equal(placeLyricRow(), baseline);
|
|
157
|
+
assert.deepEqual(lyrics.map((mark) => measured(mark).anchors.baseline.y), [baseline, baseline]);
|
|
158
|
+
});
|
|
159
|
+
test('unsupported children and overflow are attributed to their source', () => {
|
|
160
|
+
const scene = engravingScene();
|
|
161
|
+
scene.system.format();
|
|
162
|
+
const n = scene.notes[0], extra = new VF.Modifier().setAttribute('id', 'extension');
|
|
163
|
+
n.addModifier(extra, 0);
|
|
164
|
+
const d = VF.measureEngraving(n, { viewport: { x: 0, y: 0, w: 1, h: 1 } });
|
|
165
|
+
assert.deepEqual(d.diagnostics.map(({ code, sourceId }) => [code, sourceId]), [
|
|
166
|
+
['UnsupportedGeometry', 'extension'],
|
|
167
|
+
['LayoutOverflow', n.getAttribute('id')],
|
|
168
|
+
]);
|
|
169
|
+
const custom = VF.measureEngraving(extra, {
|
|
170
|
+
extension: () => ({ parts: [{ x: 3, y: 5, w: 8, h: 6 }], anchors: {} }),
|
|
171
|
+
paddingPx: 2,
|
|
172
|
+
});
|
|
173
|
+
assert.deepEqual(Object.assign({}, custom.layout), { x: 1, y: 3, w: 12, h: 10 });
|
|
174
|
+
const invalid = VF.measureEngraving(extra, {
|
|
175
|
+
extension: () => ({ parts: [], anchors: { tip: { x: Infinity, y: 0 } } }),
|
|
176
|
+
});
|
|
177
|
+
assert.deepEqual(invalid.diagnostics, [
|
|
178
|
+
{ code: 'InvalidGeometry', phase: 'measure', severity: 'error', sourceId: 'extension' },
|
|
179
|
+
]);
|
|
180
|
+
assert.equal(VF.measureEngraving(new VF.StaveNote({ keys: ['c/4'], duration: 'q' })).diagnostics[0].code, 'UnformattedGeometry');
|
|
181
|
+
});
|
|
182
|
+
for (const format of ['logical', 'easyscore']) {
|
|
183
|
+
test(format + ' full passage and excerpt reload in a fresh process, render and reflow', () => {
|
|
184
|
+
for (const source of [passage, excerpt(passage, 'm3')]) {
|
|
185
|
+
const wire = saveScore(source, format);
|
|
186
|
+
const moduleURL = new URL('../engraving/score-persistence.mjs', import.meta.url);
|
|
187
|
+
const loaded = JSON.parse(execFileSync(process.execPath, [
|
|
188
|
+
'--input-type=module',
|
|
189
|
+
'-e',
|
|
190
|
+
`import {loadScore} from ${JSON.stringify(moduleURL.href)}; import {readFileSync} from 'node:fs'; console.log(JSON.stringify(loadScore(readFileSync(0,'utf8'))));`,
|
|
191
|
+
], { input: wire }));
|
|
192
|
+
assert.deepEqual(loaded, source);
|
|
193
|
+
const { f, canvas } = factory(), view = passageView(VF, f, loaded);
|
|
194
|
+
const { composition, dynamics } = view;
|
|
195
|
+
const wide = view.draw(720), pixels = canvas.toBuffer('image/png');
|
|
196
|
+
assert.equal(wide.rows.length, 1);
|
|
197
|
+
assert.equal(wide.fragments.length, 1);
|
|
198
|
+
const narrow = view.draw(250);
|
|
199
|
+
if (loaded.measures.length === 3) {
|
|
200
|
+
assert.deepEqual(narrow.rows.at(-1), [2]);
|
|
201
|
+
assert.equal(narrow.fragments.length, 2);
|
|
202
|
+
assert.equal(narrow.fragments[0].release, false);
|
|
203
|
+
assert.equal(narrow.fragments[1].depress, false);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
assert.deepEqual(loaded.staves.map((s) => [s.key, s.time]), [
|
|
207
|
+
['G', '4/4'],
|
|
208
|
+
['G', '4/4'],
|
|
209
|
+
]);
|
|
210
|
+
assert.equal(narrow.fragments[0].depress, false);
|
|
211
|
+
}
|
|
212
|
+
assert.equal(narrow.fragments.at(-1).x2, composition.getNote('u3b').getAbsoluteX());
|
|
213
|
+
assert.equal(narrow.fragments.at(-1).release, true);
|
|
214
|
+
assert.equal(dynamics[0].owner, composition.getNote('u3b'));
|
|
215
|
+
assert.equal(dynamics[0].glyph.getYShift(), dynamics[0].owner.checkStave().getSpacingBetweenLines());
|
|
216
|
+
for (const [i, bar] of loaded.measures.entries())
|
|
217
|
+
for (const [j, staff] of loaded.staves.entries()) {
|
|
218
|
+
const native = composition.voices[i][j][0];
|
|
219
|
+
let elapsed = 0;
|
|
220
|
+
native.getTickables().forEach((note, k) => {
|
|
221
|
+
const event = bar.voices[staff.voice][k];
|
|
222
|
+
assert.equal(note, composition.getNote(event.id));
|
|
223
|
+
assert.deepEqual(note.getKeys(), [event.pitch]);
|
|
224
|
+
const frac = (s) => s.split('/').reduce((a, b) => a / b);
|
|
225
|
+
assert.equal(elapsed, frac(event.at));
|
|
226
|
+
const duration = note.getTicks().value() / VF.VexFlow.RESOLUTION;
|
|
227
|
+
assert.equal(duration, frac(event.duration));
|
|
228
|
+
elapsed += duration;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
assert.deepEqual(view.draw(720), wide);
|
|
232
|
+
assert.deepEqual(canvas.toBuffer('image/png'), pixels);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
test('refs follow a bar insertion and incomplete files report the offending object', () => {
|
|
237
|
+
const edited = structuredClone(passage), bar = structuredClone(passage.measures[0]);
|
|
238
|
+
bar.id = 'insert';
|
|
239
|
+
bar.voices.soprano[0].id = 'new-u';
|
|
240
|
+
bar.voices.bass[0].id = 'new-l';
|
|
241
|
+
edited.measures.splice(2, 0, bar);
|
|
242
|
+
for (const format of ['logical', 'easyscore']) {
|
|
243
|
+
const loaded = loadScore(saveScore(edited, format));
|
|
244
|
+
assert.deepEqual(excerpt(loaded, 'm3'), excerpt(passage, 'm3'));
|
|
245
|
+
const view = passageView(VF, factory().f, loaded);
|
|
246
|
+
const rendered = view.draw(720);
|
|
247
|
+
assert.equal(rendered.fragments.at(-1).x2, view.composition.getNote('u3b').getAbsoluteX());
|
|
248
|
+
const bad = structuredClone(passage);
|
|
249
|
+
bad.marks[0].end.measure = 'missing';
|
|
250
|
+
assert.throws(() => saveScore(bad, format), (e) => e.diagnostic.code === 'DanglingAnchor' && e.diagnostic.sourceId === 'p1');
|
|
251
|
+
const native = structuredClone(passage);
|
|
252
|
+
class CustomBeat extends VF.GhostNote {
|
|
253
|
+
}
|
|
254
|
+
native.measures[0].voices.bass[0] = new CustomBeat('w').setAttribute('id', 'live');
|
|
255
|
+
assert.throws(() => saveScore(native, format), (e) => e.diagnostic.code === 'UnsupportedInput' && e.diagnostic.sourceId === 'live');
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
test('measured ink encloses the drawn parts for both stem directions and fonts', () => {
|
|
259
|
+
for (const family of ['Bravura', 'Petaluma'])
|
|
260
|
+
for (const direction of [VF.Stem.UP, VF.Stem.DOWN]) {
|
|
261
|
+
const { f, canvas } = factory(profile(family));
|
|
262
|
+
const notes = [['d/6', 'e/6'], ['f/4']].map((keys) => f.StaveNote({ keys, duration: '16', stemDirection: direction }));
|
|
263
|
+
const system = f.System({ width: 400, y: 120 });
|
|
264
|
+
notes[0].addModifier(f.Articulation({ type: 'a.', position: direction === 1 ? 'above' : 'below' }), 0);
|
|
265
|
+
system.addStave({ voices: [f.EasyScore().voice(notes, { mode: 'soft' })] });
|
|
266
|
+
system.format();
|
|
267
|
+
for (const element of [
|
|
268
|
+
...notes,
|
|
269
|
+
f.Curve({ from: notes[0], to: notes[1], options: { openingDirection: 'up' } }),
|
|
270
|
+
]) {
|
|
271
|
+
const { ink } = measured(element), ctx = canvas.getContext('2d');
|
|
272
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
273
|
+
element.drawWithStyle();
|
|
274
|
+
const { data } = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
275
|
+
let count = 0;
|
|
276
|
+
for (let i = 3; i < data.length; i += 4)
|
|
277
|
+
if (data[i] > 100) {
|
|
278
|
+
const x = ((i - 3) / 4) % canvas.width, y = Math.floor((i - 3) / 4 / canvas.width);
|
|
279
|
+
assert.ok(x >= Math.floor(ink.x) - 1 &&
|
|
280
|
+
y >= Math.floor(ink.y) - 1 &&
|
|
281
|
+
x <= Math.ceil(ink.x + ink.w) + 1 &&
|
|
282
|
+
y <= Math.ceil(ink.y + ink.h) + 1, `${family} ${element.getCategory()} pixel ${x},${y} outside ${JSON.stringify(ink)}`);
|
|
283
|
+
count++;
|
|
284
|
+
}
|
|
285
|
+
assert.ok(count > 10);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
test('browser SVG keeps one rehearsal mark, the dynamic and the pedal through reflow', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
290
|
+
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
291
|
+
try {
|
|
292
|
+
const page = yield browser.newPage();
|
|
293
|
+
yield page.setContent('<style>body {background:white}</style><div id="score"></div>');
|
|
294
|
+
yield page.addScriptTag({ path: new URL('../../build/cjs/vexflow-debug.js', import.meta.url).pathname });
|
|
295
|
+
yield page.addScriptTag({
|
|
296
|
+
content: `const durations = new Map([['1/1','w'],['1/2','h']]); const compositionInput = ${compositionInput}; const passageView = ${passageView};`,
|
|
297
|
+
});
|
|
298
|
+
const snapshots = yield page.evaluate((score) => __awaiter(void 0, void 0, void 0, function* () {
|
|
299
|
+
yield document.fonts.ready;
|
|
300
|
+
const f = new VexFlow.Factory({
|
|
301
|
+
renderer: { elementId: 'score', width: 800, height: 700 },
|
|
302
|
+
engraving: new VexFlow.EngravingProfile({ musicFont: 'Petaluma' }),
|
|
303
|
+
});
|
|
304
|
+
const view = passageView({ VexFlow }, f, score);
|
|
305
|
+
return [720, 250, 720].map((width) => {
|
|
306
|
+
const rendering = view.draw(width);
|
|
307
|
+
const nodes = [...document.querySelectorAll('#score svg text')];
|
|
308
|
+
const boxes = nodes.map((node) => {
|
|
309
|
+
const b = node.getBBox();
|
|
310
|
+
return [node.textContent, b.x, b.y, b.width, b.height];
|
|
311
|
+
});
|
|
312
|
+
const head = view.composition.getNote('u3b');
|
|
313
|
+
const mark = view.dynamics[0].glyph;
|
|
314
|
+
return {
|
|
315
|
+
rendering,
|
|
316
|
+
boxes,
|
|
317
|
+
owner: head.getAttribute('id'),
|
|
318
|
+
baseline: VexFlow.measureEngraving(mark).anchors.baseline.y,
|
|
319
|
+
dynamic: boxes.filter((b) => b[0] === VexFlow.Glyphs.dynamicPiano),
|
|
320
|
+
rehearsal: boxes.filter((b) => b[0] === 'B'),
|
|
321
|
+
};
|
|
322
|
+
});
|
|
323
|
+
}), passage);
|
|
324
|
+
const [wide, narrow, restored] = snapshots;
|
|
325
|
+
assert.deepEqual(restored, wide);
|
|
326
|
+
assert.equal(narrow.rendering.fragments.length, 2);
|
|
327
|
+
for (const s of snapshots) {
|
|
328
|
+
assert.equal(s.owner, 'u3b');
|
|
329
|
+
assert.equal(s.rehearsal.length, 1);
|
|
330
|
+
assert.equal(s.dynamic.length, 1);
|
|
331
|
+
assert.ok(s.dynamic[0][3] > 0 && s.rehearsal[0][3] > 0);
|
|
332
|
+
assert.ok(s.dynamic[0][2] < s.baseline && s.dynamic[0][2] + s.dynamic[0][4] >= s.baseline);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
finally {
|
|
336
|
+
yield browser.close();
|
|
337
|
+
}
|
|
338
|
+
}));
|
|
339
|
+
test('contour beams preserve membership, minimum stems, beamlet overrides and endpoints across widths', () => {
|
|
340
|
+
for (const width of [190, 340, 790]) {
|
|
341
|
+
for (const stem of ['up', 'down']) {
|
|
342
|
+
const { f } = factory(), es = f.EasyScore();
|
|
343
|
+
const notes = es.notes('G4/8, A4/16, B4/8, C4/8', { stem });
|
|
344
|
+
const beam = f.Beam({ notes });
|
|
345
|
+
beam.renderOptions.contourSlope = true;
|
|
346
|
+
beam.setPartialBeamSideAt(1, 'R');
|
|
347
|
+
const sys = f.System({ width, y: 60 });
|
|
348
|
+
sys.addStave({ voices: [es.voice(notes, { mode: 'soft' })] });
|
|
349
|
+
sys.format();
|
|
350
|
+
measured(beam);
|
|
351
|
+
assert.deepEqual(beam.getNotes(), notes);
|
|
352
|
+
const first = notes[0], last = notes.at(-1);
|
|
353
|
+
assert.ok(beam.slope * (last.getYs()[0] - first.getYs()[0]) >= -1e-7);
|
|
354
|
+
for (const n of notes) {
|
|
355
|
+
const tip = n.getStemExtents().topY;
|
|
356
|
+
const expected = beam.getBeamYToDraw() + beam.slope * (n.getStemX() - first.getStemX());
|
|
357
|
+
assert.ok(Math.abs(tip - expected) < 1e-6);
|
|
358
|
+
assert.ok(Math.abs(tip - n.getYs()[0]) >= n.getStemMinimumLength() - 1);
|
|
359
|
+
}
|
|
360
|
+
const [beamlet] = beam.getBeamLines('8');
|
|
361
|
+
assert.equal(beamlet.end - beamlet.start, beam.renderOptions.partialBeamLength);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
test('before and after grace groups on two staves clear their hosts at the start of a system', () => {
|
|
366
|
+
const { f } = factory(), es = f.EasyScore();
|
|
367
|
+
const sys = f.System({ width: 650 });
|
|
368
|
+
const groups = [];
|
|
369
|
+
for (const key of ['c/5', 'e/4']) {
|
|
370
|
+
const host = f.StaveNote({ keys: [key], duration: 'w' });
|
|
371
|
+
const sides = [VF.Modifier.Position.LEFT, VF.Modifier.Position.RIGHT].map((side, i) => {
|
|
372
|
+
const grace = f
|
|
373
|
+
.GraceNoteGroup({
|
|
374
|
+
notes: Array.from({ length: i + 1 }, () => f.GraceNote({ keys: [key], duration: '16', slash: true })),
|
|
375
|
+
slur: true,
|
|
376
|
+
})
|
|
377
|
+
.setPosition(side);
|
|
378
|
+
if (i)
|
|
379
|
+
grace.beamNotes();
|
|
380
|
+
host.addModifier(grace, 0);
|
|
381
|
+
return grace;
|
|
382
|
+
});
|
|
383
|
+
sys.addStave({ voices: [es.voice([host])] });
|
|
384
|
+
groups.push({ host, sides });
|
|
385
|
+
}
|
|
386
|
+
sys.format();
|
|
387
|
+
for (const { host, sides: [before, after], } of groups) {
|
|
388
|
+
measured(before);
|
|
389
|
+
measured(after);
|
|
390
|
+
const [head] = host.getHeadInk();
|
|
391
|
+
const pre = before.getGraceNotes().at(-1).getHeadInk()[0];
|
|
392
|
+
const post = after.getGraceNotes()[0].getHeadInk()[0];
|
|
393
|
+
assert.ok(pre.x + pre.w < head.x);
|
|
394
|
+
assert.ok(post.x > head.x + head.w);
|
|
395
|
+
assert.ok(pre.x >= host.checkStave().getX());
|
|
396
|
+
for (const [group, offset] of [
|
|
397
|
+
[before, 0],
|
|
398
|
+
[after, host.getGlyphWidth()],
|
|
399
|
+
]) {
|
|
400
|
+
const slur = group.getLayoutElements().at(-1);
|
|
401
|
+
const start = slur.getFirstX() + slur.renderOptions.firstXShift - slur.renderOptions.tieSpacing;
|
|
402
|
+
assert.ok(Math.abs(start - host.getNoteHeadBeginX() - offset) < 1e-7);
|
|
403
|
+
}
|
|
404
|
+
assert.equal(after.getGraceNotes()[0].getStave(), host.getStave());
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
test('four voice columns avoid heads and rests, preserve distinct attacks and repeat for reversed voice input', () => {
|
|
408
|
+
function passage(reverse) {
|
|
409
|
+
const { f } = factory(), es = f.EasyScore();
|
|
410
|
+
const entries = ['F5/q, G5/q', 'E5/8, C5/8, D5/q', 'D5/q, E5/q', 'B4/q/r, B4/q'].map((input, i) => {
|
|
411
|
+
const notes = es.notes(input, { stem: i % 2 ? 'down' : 'up' });
|
|
412
|
+
if (i === 0)
|
|
413
|
+
VF.Dot.buildAndAttach([notes[0]]);
|
|
414
|
+
if (i === 2)
|
|
415
|
+
notes[0].addModifier(new VF.Accidental('#'), 0);
|
|
416
|
+
return { notes, voice: es.voice(notes, { mode: 'soft' }) };
|
|
417
|
+
});
|
|
418
|
+
const sys = f.System({ width: 490 });
|
|
419
|
+
const voices = entries.map((e) => e.voice);
|
|
420
|
+
sys.addStave({ voices: reverse ? voices.reverse() : voices });
|
|
421
|
+
sys.format();
|
|
422
|
+
const boxes = entries.flatMap((e) => e.notes.flatMap((n) => [...n.getHeadInk(), ...n.getModifiers().map((m) => m.getInkBounds())]));
|
|
423
|
+
for (const [i, a] of boxes.entries())
|
|
424
|
+
for (const b of boxes.slice(i + 1))
|
|
425
|
+
assert.ok(a.x + a.w <= b.x + 1 || b.x + b.w <= a.x + 1 || a.y + a.h <= b.y + 1 || b.y + b.h <= a.y + 1, 'voice head, rest, dot or sign overlapped');
|
|
426
|
+
return entries.map((e) => e.notes.map((n) => [n.getNoteHeadBeginX(), n.getYs()[0]]));
|
|
427
|
+
}
|
|
428
|
+
assert.deepEqual(passage(true), passage(false));
|
|
429
|
+
});
|
|
430
|
+
test('bracket and label clear upper and lower ornament signs before drawing and after resize', () => {
|
|
431
|
+
for (const [position, location] of [
|
|
432
|
+
[VF.Modifier.Position.ABOVE, 1],
|
|
433
|
+
[VF.Modifier.Position.BELOW, -1],
|
|
434
|
+
]) {
|
|
435
|
+
const { f } = factory(), es = f.EasyScore();
|
|
436
|
+
const notes = es.notes('G4/8, A4/8, B4/8');
|
|
437
|
+
const mark = new VF.Ornament('turn').setPosition(position).setUpperAccidental('#').setLowerAccidental('b');
|
|
438
|
+
notes[1].addModifier(mark, 0);
|
|
439
|
+
const tuplet = f.Tuplet({ notes, options: { bracketed: true, location } });
|
|
440
|
+
const system = f.System({ width: 430, y: 80 });
|
|
441
|
+
system.addStave({ voices: [es.voice(notes, { mode: 'soft' })] });
|
|
442
|
+
for (const width of [430, 260, 430]) {
|
|
443
|
+
system.setWidth(width).format();
|
|
444
|
+
const bracket = measured(tuplet).ink, sign = measured(mark).ink;
|
|
445
|
+
const gap = location === 1 ? sign.y - bracket.y - bracket.h : bracket.y - sign.y - sign.h;
|
|
446
|
+
assert.ok(gap >= 2, 'Bracket clears nearest auxiliary accidental by at least two pixels');
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import assert from 'node:assert/strict';
|
|
11
|
+
import { readFile } from 'node:fs/promises';
|
|
12
|
+
import test from 'node:test';
|
|
13
|
+
import puppeteer from 'puppeteer';
|
|
14
|
+
function renderMatrix({ family, textFamily, backend, metadata }) {
|
|
15
|
+
var _a;
|
|
16
|
+
const VF = window.VexFlow;
|
|
17
|
+
VF.setFonts(family, textFamily);
|
|
18
|
+
const target = document.createElement(backend === 'SVG' ? 'div' : 'canvas');
|
|
19
|
+
target.id = 'matrix';
|
|
20
|
+
document.body.replaceChildren(target);
|
|
21
|
+
const factory = new VF.Factory({
|
|
22
|
+
renderer: { elementId: target.id, width: 850, height: 500 },
|
|
23
|
+
engraving: new VF.EngravingProfile({ musicFont: family, metadata }),
|
|
24
|
+
});
|
|
25
|
+
const score = factory.EasyScore();
|
|
26
|
+
const notes = ['w', 'h', 'q', '8'].flatMap((duration) => [1, -1].map((stemDirection) => factory.StaveNote({ keys: ['c#/6', 'c/6', 'cb/6'], duration, stemDirection })));
|
|
27
|
+
for (const note of notes) {
|
|
28
|
+
['#', 'n', 'b'].forEach((type, index) => note.addModifier(new VF.Accidental(type), index));
|
|
29
|
+
VF.Dot.buildAndAttach([note]);
|
|
30
|
+
}
|
|
31
|
+
const cue = factory.StaveNote({ keys: ['e/4'], duration: '8', stemDirection: -1 });
|
|
32
|
+
cue.setFontSize(cue.fontSizeInPoints * 0.75).reset();
|
|
33
|
+
const host = factory.StaveNote({ keys: ['e/4'], duration: 'q' });
|
|
34
|
+
const grace = factory.GraceNote({ keys: ['f/4'], duration: '16', slash: true });
|
|
35
|
+
host.addModifier(factory.GraceNoteGroup({ notes: [grace], slur: true }), 0);
|
|
36
|
+
const ornament = new VF.Ornament('turn').setUpperAccidental('#').setLowerAccidental('b').setDelayed(true);
|
|
37
|
+
cue.addModifier(ornament, 0);
|
|
38
|
+
const articulation = new VF.Articulation('a.').setPosition(VF.Modifier.Position.BELOW);
|
|
39
|
+
host.addModifier(articulation, 0);
|
|
40
|
+
const lyric = new VF.Annotation('dolce').setFont(textFamily, 12);
|
|
41
|
+
notes[0].addModifier(lyric, 0);
|
|
42
|
+
const tuplet = factory.Tuplet({
|
|
43
|
+
notes: [cue, host],
|
|
44
|
+
options: { numNotes: 3, notesOccupied: 2, ratioed: true, displayRatio: [6, 4], bracketed: true },
|
|
45
|
+
});
|
|
46
|
+
const systems = [];
|
|
47
|
+
for (const [i, passage] of [notes.slice(0, 4), notes.slice(4), [cue, host, score.notes('A4/q')[0]]].entries()) {
|
|
48
|
+
const system = factory.System({ width: 800, y: 30 + i * 145 });
|
|
49
|
+
system.addStave({ voices: [score.voice(passage, { mode: 'soft' })] });
|
|
50
|
+
systems.push(system);
|
|
51
|
+
}
|
|
52
|
+
systems.forEach((s) => s.format());
|
|
53
|
+
const snapshot = () => {
|
|
54
|
+
const measured = [...notes, cue, host, grace, ornament, tuplet].map((el) => VF.measureEngraving(el));
|
|
55
|
+
return { boxes: measured.map((m) => m.ink), diagnostics: measured.flatMap((m) => m.diagnostics) };
|
|
56
|
+
};
|
|
57
|
+
const before = snapshot();
|
|
58
|
+
factory.draw({ retain: true });
|
|
59
|
+
const after = snapshot();
|
|
60
|
+
const rows = notes.map((note) => {
|
|
61
|
+
const heads = note.getHeadInk();
|
|
62
|
+
const ledger = note.getLedgerLines().at(-1);
|
|
63
|
+
const signs = note
|
|
64
|
+
.getModifiers()
|
|
65
|
+
.filter((m) => m instanceof VF.Accidental)
|
|
66
|
+
.map((m) => m.getInkBounds());
|
|
67
|
+
const dot = note
|
|
68
|
+
.getModifiers()
|
|
69
|
+
.find((m) => m instanceof VF.Dot)
|
|
70
|
+
.getInkBounds();
|
|
71
|
+
return { heads, ledger, signs, dot, stem: note.getStemSegment(), family: note.noteHeads[0].fontInfo.family };
|
|
72
|
+
});
|
|
73
|
+
const sizes = [notes[0], cue, grace].map((note) => note.noteHeads[0].fontSizeInPoints);
|
|
74
|
+
const drawnLabel = backend === 'SVG' ? (_a = target.querySelector('.vf-tuplet text')) === null || _a === void 0 ? void 0 : _a.textContent : undefined;
|
|
75
|
+
const pixels = backend === 'SVG'
|
|
76
|
+
? target.querySelectorAll('svg text').length
|
|
77
|
+
: target
|
|
78
|
+
.getContext('2d')
|
|
79
|
+
.getImageData(0, 0, target.width, target.height)
|
|
80
|
+
.data.some((v, i, data) => i % 4 === 3 && v > 128 && data[i - 1] < 64);
|
|
81
|
+
return { before, after, rows, sizes, pixels, drawnLabel };
|
|
82
|
+
}
|
|
83
|
+
test('Bravura, Petaluma and metadata-free Leland render local parts at normal, cue and grace sizes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
const browser = yield puppeteer.launch({ headless: true, args: process.env.CI ? ['--no-sandbox'] : [] });
|
|
85
|
+
try {
|
|
86
|
+
const page = yield browser.newPage();
|
|
87
|
+
yield page.setContent('<body></body>');
|
|
88
|
+
yield page.addScriptTag({ path: new URL('../../build/cjs/vexflow-debug.js', import.meta.url).pathname });
|
|
89
|
+
const file = (name, suffix) => new URL('../../node_modules/@vexflow-fonts/' + name + '/' + suffix, import.meta.url);
|
|
90
|
+
for (const family of ['Bravura', 'Petaluma', 'Leland', 'Academico', 'Petaluma Script']) {
|
|
91
|
+
const name = family.toLowerCase().replaceAll(' ', '');
|
|
92
|
+
const bytes = yield readFile(file(name, name + '.woff2'));
|
|
93
|
+
yield page.evaluate((family, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
+
const face = new FontFace(family, 'url(data:font/woff2;base64,' + data + ')');
|
|
95
|
+
document.fonts.add(yield face.load());
|
|
96
|
+
}), family, bytes.toString('base64'));
|
|
97
|
+
}
|
|
98
|
+
for (const [family, textFamily] of [
|
|
99
|
+
['Bravura', 'Academico'],
|
|
100
|
+
['Petaluma', 'Petaluma Script'],
|
|
101
|
+
['Leland', 'Academico'],
|
|
102
|
+
]) {
|
|
103
|
+
const metadata = family === 'Leland' ? undefined : JSON.parse(yield readFile(file(family.toLowerCase(), 'metadata.json')));
|
|
104
|
+
for (const backend of ['SVG', 'Canvas']) {
|
|
105
|
+
const scene = yield page.evaluate(renderMatrix, { family, textFamily, metadata, backend });
|
|
106
|
+
assert.deepEqual(scene.before.diagnostics, [], family + ' ' + backend);
|
|
107
|
+
assert.deepEqual(scene.after, scene.before);
|
|
108
|
+
assert.ok(scene.pixels);
|
|
109
|
+
if (backend === 'SVG')
|
|
110
|
+
assert.equal(scene.drawnLabel, String.fromCharCode(0xe886, 0xe88a, 0xe884));
|
|
111
|
+
assert.ok(scene.sizes[0] > scene.sizes[1] && scene.sizes[0] > scene.sizes[2]);
|
|
112
|
+
for (const { heads, ledger, signs, dot, stem, family: used } of scene.rows) {
|
|
113
|
+
assert.equal(used, family);
|
|
114
|
+
assert.equal(new Set(heads.map((h) => h.x)).size, 3);
|
|
115
|
+
const left = Math.min(...heads.map((h) => h.x)), right = Math.max(...heads.map((h) => h.x + h.w));
|
|
116
|
+
assert.ok(ledger.x <= left && ledger.x + ledger.width >= right - 0.5, 'ledger encloses heads');
|
|
117
|
+
assert.ok(signs.every((s) => s.x + s.w <= left + 1), 'accidentals clear heads');
|
|
118
|
+
assert.ok(dot.x >= right - 1, 'dot clears heads');
|
|
119
|
+
if (stem)
|
|
120
|
+
assert.ok(heads.some((h) => h.x - 1 <= stem.x && stem.x <= h.x + h.w + 1), 'stem joins a head');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
yield browser.close();
|
|
127
|
+
}
|
|
128
|
+
}));
|