vexflow 5.1.1 → 5.2.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.
Files changed (96) hide show
  1. package/README.md +8 -6
  2. package/build/cjs/vexflow-bravura.js +2 -2
  3. package/build/cjs/vexflow-bravura.js.map +1 -1
  4. package/build/cjs/vexflow-core.js +2 -2
  5. package/build/cjs/vexflow-core.js.map +1 -1
  6. package/build/cjs/vexflow-debug-with-tests.js +2916 -484
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +2761 -451
  9. package/build/cjs/vexflow-debug.js.map +1 -1
  10. package/build/cjs/vexflow.js +2 -2
  11. package/build/cjs/vexflow.js.map +1 -1
  12. package/build/esm/src/accidental.js +3 -0
  13. package/build/esm/src/articulation.js +27 -14
  14. package/build/esm/src/beam.js +12 -2
  15. package/build/esm/src/chordkerning.js +98 -0
  16. package/build/esm/src/chordsymbol.js +108 -27
  17. package/build/esm/src/clef.js +3 -0
  18. package/build/esm/src/clefnote.js +5 -1
  19. package/build/esm/src/dot.js +1 -1
  20. package/build/esm/src/easyscore/composition.js +297 -0
  21. package/build/esm/src/easyscore/elementindex.js +81 -0
  22. package/build/esm/src/easyscore/elements.js +324 -0
  23. package/build/esm/src/easyscore/policies.js +69 -0
  24. package/build/esm/src/easyscore/rhythm.js +42 -0
  25. package/build/esm/src/easyscore.js +448 -26
  26. package/build/esm/src/element.js +13 -2
  27. package/build/esm/src/factory.js +256 -60
  28. package/build/esm/src/formatter.js +32 -4
  29. package/build/esm/src/keysignature.js +9 -1
  30. package/build/esm/src/keysignote.js +2 -2
  31. package/build/esm/src/note.js +5 -0
  32. package/build/esm/src/parenthesis.js +1 -1
  33. package/build/esm/src/parser.js +6 -1
  34. package/build/esm/src/proportionalformatter.js +186 -0
  35. package/build/esm/src/registry.js +27 -0
  36. package/build/esm/src/sheet.js +20 -3
  37. package/build/esm/src/stave.js +9 -2
  38. package/build/esm/src/stavenote.js +12 -12
  39. package/build/esm/src/stemmablenote.js +6 -1
  40. package/build/esm/src/tickable.js +5 -0
  41. package/build/esm/src/tuplet.js +3 -2
  42. package/build/esm/src/version.js +3 -3
  43. package/build/esm/src/vexflow.js +2 -1
  44. package/build/esm/tests/beam_tests.js +35 -0
  45. package/build/esm/tests/easyscore_tests.js +40 -0
  46. package/build/esm/tests/easyscore_types.js +65 -0
  47. package/build/esm/tests/formatter_tests.js +41 -0
  48. package/build/esm/tests/node/chord-kerning-tests.mjs +173 -0
  49. package/build/esm/tests/node/easyscore-rendering-tests.mjs +332 -0
  50. package/build/esm/tests/node/easyscore-tests.mjs +953 -0
  51. package/build/esm/tests/node/proportional-spacing-tests.mjs +214 -0
  52. package/build/esm/tests/node/tool-security-tests.mjs +85 -0
  53. package/build/esm/tools/easyscore-api-audit.mjs +58 -0
  54. package/build/esm/tools/easyscore-composition.mjs +62 -0
  55. package/build/esm/tools/easyscore-example.mjs +16 -0
  56. package/build/esm/tools/easyscore-families.mjs +61 -0
  57. package/build/esm/tools/easyscore-references-example.mjs +26 -0
  58. package/build/esm/tools/easyscore-rhythm.mjs +58 -0
  59. package/build/esm/tools/easyscore-structure.mjs +88 -0
  60. package/build/esm/tools/explorer/catalog/entries.mjs +6 -0
  61. package/build/esm/tools/explorer/catalog/expression.mjs +68 -0
  62. package/build/esm/tools/explorer/catalog/helpers.mjs +29 -0
  63. package/build/esm/tools/explorer/catalog/layout.mjs +109 -0
  64. package/build/esm/tools/explorer/catalog/notes.mjs +61 -0
  65. package/build/esm/tools/explorer/catalog/staves.mjs +85 -0
  66. package/build/esm/tools/explorer/catalog/strings.mjs +25 -0
  67. package/build/esm/tools/explorer/catalog.mjs +14 -0
  68. package/build/types/src/accidental.d.ts +2 -0
  69. package/build/types/src/articulation.d.ts +6 -0
  70. package/build/types/src/beam.d.ts +2 -0
  71. package/build/types/src/chordkerning.d.ts +42 -0
  72. package/build/types/src/chordsymbol.d.ts +19 -0
  73. package/build/types/src/clef.d.ts +2 -0
  74. package/build/types/src/easyscore/composition.d.ts +107 -0
  75. package/build/types/src/easyscore/elementindex.d.ts +30 -0
  76. package/build/types/src/easyscore/elements.d.ts +156 -0
  77. package/build/types/src/easyscore/policies.d.ts +12 -0
  78. package/build/types/src/easyscore/rhythm.d.ts +9 -0
  79. package/build/types/src/easyscore.d.ts +153 -11
  80. package/build/types/src/element.d.ts +5 -1
  81. package/build/types/src/factory.d.ts +91 -8
  82. package/build/types/src/formatter.d.ts +7 -1
  83. package/build/types/src/keysignature.d.ts +3 -0
  84. package/build/types/src/keysignote.d.ts +1 -1
  85. package/build/types/src/note.d.ts +2 -0
  86. package/build/types/src/parser.d.ts +5 -0
  87. package/build/types/src/proportionalformatter.d.ts +30 -0
  88. package/build/types/src/registry.d.ts +4 -0
  89. package/build/types/src/stave.d.ts +2 -0
  90. package/build/types/src/stavenote.d.ts +1 -1
  91. package/build/types/src/stemmablenote.d.ts +6 -1
  92. package/build/types/src/tickable.d.ts +2 -0
  93. package/build/types/src/vexflow.d.ts +2 -1
  94. package/changelog/CHANGELOG.md +57 -0
  95. package/package.json +19 -7
  96. package/tests/flow.html +10 -3
@@ -316,6 +316,9 @@ export class Accidental extends Modifier {
316
316
  this.reset();
317
317
  return this;
318
318
  }
319
+ isCautionary() {
320
+ return this.cautionary;
321
+ }
319
322
  draw() {
320
323
  const { type, position, index } = this;
321
324
  const ctx = this.checkContext();
@@ -9,6 +9,7 @@ function L(...args) {
9
9
  log('VexFlow.Articulation', args);
10
10
  }
11
11
  const { ABOVE, BELOW } = Modifier.Position;
12
+ const easyScoreGlyphs = new Set(Object.values(Glyphs));
12
13
  function roundToNearestHalf(mathFn, value) {
13
14
  return mathFn(value / 0.5) * 0.5;
14
15
  }
@@ -190,24 +191,36 @@ export class Articulation extends Modifier {
190
191
  state.rightShift += overlap / 2;
191
192
  return true;
192
193
  }
193
- static easyScoreHook({ articulations }, note, builder) {
194
- if (!articulations)
195
- return;
196
- const articNameToCode = {
194
+ static parseEasyScore(articulations) {
195
+ const aliases = {
197
196
  staccato: 'a.',
198
197
  tenuto: 'a-',
199
198
  accent: 'a>',
199
+ fermata: 'a@',
200
+ marcato: 'a^',
201
+ staccatissimo: 'av',
200
202
  };
201
- articulations
202
- .split(',')
203
- .map((articString) => articString.trim().split('.'))
204
- .map(([name, position]) => {
205
- const artic = { type: articNameToCode[name] };
206
- if (position)
207
- artic.position = Modifier.PositionString[position];
208
- return builder.getFactory().Articulation(artic);
209
- })
210
- .map((artic) => note.addModifier(artic, 0));
203
+ const singleCode = articulations.trim().replace(/\.(above|below|left|right)$/, '');
204
+ const items = Tables.articulationCodes(singleCode) ? [articulations] : articulations.split(',');
205
+ return items.map((value) => {
206
+ var _a;
207
+ const match = /^(.*)\.(above|below|left|right)$/.exec(value.trim());
208
+ const name = match ? match[1] : value.trim();
209
+ const type = Object.hasOwnProperty.call(aliases, name) ? aliases[name] : name;
210
+ const glyph = Object.hasOwnProperty.call(Glyphs, type) ? Glyphs[type] : type;
211
+ if (!Object.hasOwnProperty.call((_a = Tables.articulationCodes(type)) !== null && _a !== void 0 ? _a : {}, 'betweenLines') &&
212
+ !easyScoreGlyphs.has(glyph)) {
213
+ throw new RuntimeError('BadArguments', `Unknown EasyScore articulation: ${name}`);
214
+ }
215
+ return { type: glyph, position: match ? Modifier.PositionString[match[2]] : undefined };
216
+ });
217
+ }
218
+ static easyScoreHook({ articulations }, note, builder) {
219
+ if (!articulations)
220
+ return;
221
+ Articulation.parseEasyScore(articulations).forEach((params) => {
222
+ note.addModifier(builder.getFactory().Articulation(params), 0);
223
+ });
211
224
  }
212
225
  constructor(type) {
213
226
  var _a;
@@ -195,6 +195,16 @@ export class Beam extends Element {
195
195
  }
196
196
  function formatStems() {
197
197
  noteGroups.forEach((group) => {
198
+ if (config.stemPolicy === 'preserve')
199
+ return;
200
+ if (config.stemPolicy === 'explicit') {
201
+ const explicit = new Set(group.filter((note) => !note.isRest() && !note.isAutoStem()).map((note) => note.getStemDirection()));
202
+ if (explicit.size > 1)
203
+ return;
204
+ const direction = explicit.size ? [...explicit][0] : calculateStemDirection(group);
205
+ group.filter((note) => note.isAutoStem()).forEach((note) => note.setStemDirection(direction, true));
206
+ return;
207
+ }
198
208
  let stemDirection;
199
209
  if (config.maintainStemDirections) {
200
210
  const note = findFirstNote(group);
@@ -222,7 +232,7 @@ export class Beam extends Element {
222
232
  }
223
233
  function applyStemDirection(group, direction) {
224
234
  group.forEach((note) => {
225
- note.setStemDirection(direction);
235
+ note.setStemDirection(direction, config.stemDirection === undefined && note.isAutoStem());
226
236
  });
227
237
  }
228
238
  function getTuplets() {
@@ -303,7 +313,7 @@ export class Beam extends Element {
303
313
  for (i = 0; i < notes.length; ++i) {
304
314
  note = notes[i];
305
315
  if (autoStem) {
306
- note.setStemDirection(stemDirection);
316
+ note.setStemDirection(stemDirection, true);
307
317
  this._stemDirection = stemDirection;
308
318
  }
309
319
  note.setBeam(this);
@@ -0,0 +1,98 @@
1
+ import { Font } from './font.js';
2
+ import { Glyphs } from './glyphs.js';
3
+ function scriptPairs(a, f) {
4
+ const symbols = [Glyphs.csymDiminished, Glyphs.csymHalfDiminished, Glyphs.csymMajorSeventh];
5
+ return symbols.flatMap((right) => [
6
+ { left: 'A', right, position: 'superscript', adjustmentEm: a },
7
+ { left: 'F', right, position: 'subscript', adjustmentEm: f },
8
+ ]);
9
+ }
10
+ const profiles = [
11
+ { textFont: 'Academico', musicFont: 'Bravura', pairs: scriptPairs(-0.18, -0.12) },
12
+ { textFont: 'Petaluma Script', musicFont: 'Petaluma', pairs: scriptPairs(-0.12, -0.08) },
13
+ ];
14
+ function normalWeight(weight) {
15
+ return weight === undefined || weight === '' || weight === 'normal' ? '400' : String(weight);
16
+ }
17
+ export function chordKerningProfile(font, custom) {
18
+ var _a;
19
+ const families = ((_a = font.family) !== null && _a !== void 0 ? _a : '').split(',').map((family) => family.trim().replace(/^['"]|['"]$/g, ''));
20
+ return (custom ? [custom] : profiles).find((profile) => families[0] === profile.textFont &&
21
+ families[1] === profile.musicFont &&
22
+ normalWeight(font.weight) === normalWeight(profile.weight) &&
23
+ (font.style || 'normal') === (profile.style || 'normal'));
24
+ }
25
+ function musicCharacter(character) {
26
+ return /[\uE870-\uE87F\uED60-\uED67\uE260-\uE26F]/u.test(character);
27
+ }
28
+ function groups(blocks) {
29
+ const result = [];
30
+ for (const block of blocks) {
31
+ if (!block.text)
32
+ continue;
33
+ const previous = result[result.length - 1];
34
+ if ((previous === null || previous === void 0 ? void 0 : previous.position) === block.position)
35
+ previous.text += block.text;
36
+ else
37
+ result.push(Object.assign({}, block));
38
+ }
39
+ return result;
40
+ }
41
+ function spans(text) {
42
+ const result = [];
43
+ for (const character of text) {
44
+ const music = musicCharacter(character);
45
+ const previous = result[result.length - 1];
46
+ if ((previous === null || previous === void 0 ? void 0 : previous.music) === music)
47
+ previous.text += character;
48
+ else
49
+ result.push({ text: character, music });
50
+ }
51
+ return result;
52
+ }
53
+ function adjustment(profile, left, right, position) {
54
+ var _a, _b;
55
+ const last = Array.from(left).slice(-1)[0];
56
+ const first = Array.from(right)[0];
57
+ return ((_b = (_a = profile.pairs.find((pair) => pair.left === last && pair.right === first && pair.position === position)) === null || _a === void 0 ? void 0 : _a.adjustmentEm) !== null && _b !== void 0 ? _b : 0);
58
+ }
59
+ export function layoutChordRuns(blocks, font, profile, options, measure) {
60
+ var _a, _b;
61
+ const em = Font.convertSizeToPixelValue((_a = font.size) !== null && _a !== void 0 ? _a : 12);
62
+ const runs = [];
63
+ let cursor = 0;
64
+ let previousText = '';
65
+ let stack;
66
+ for (const group of groups(blocks)) {
67
+ const script = group.position !== 'baseline';
68
+ const stacked = script && stack && stack.position !== group.position;
69
+ let x = stacked ? stack.x : cursor;
70
+ if (!stacked && runs.length) {
71
+ x += options.spacing * em + adjustment(profile, previousText, group.text, group.position) * em;
72
+ }
73
+ const anchor = x;
74
+ const y = group.position === 'superscript'
75
+ ? options.superscript * em
76
+ : group.position === 'subscript'
77
+ ? options.subscript * em
78
+ : 0;
79
+ let previousSpan = '';
80
+ for (const span of spans(group.text)) {
81
+ if (previousSpan)
82
+ x += adjustment(profile, previousSpan, span.text, group.position) * em;
83
+ const runFont = Object.assign(Object.assign({}, font), { family: span.music ? profile.musicFont : profile.textFont, size: script ? Font.scaleSize((_b = font.size) !== null && _b !== void 0 ? _b : 12, options.ratio) : font.size });
84
+ const metrics = measure(span.text, runFont);
85
+ runs.push({ text: span.text, position: group.position, font: runFont, x, y, metrics });
86
+ x += metrics.width;
87
+ previousSpan = span.text;
88
+ }
89
+ cursor = stacked ? Math.max(stack.end, x) : x;
90
+ stack = script && !stacked ? { position: group.position, x: anchor, end: cursor } : undefined;
91
+ previousText = group.text;
92
+ }
93
+ const left = Math.min(0, ...runs.map((run) => run.x - run.metrics.actualBoundingBoxLeft));
94
+ const right = Math.max(cursor, ...runs.map((run) => run.x + run.metrics.actualBoundingBoxRight));
95
+ for (const run of runs)
96
+ run.x -= left;
97
+ return { runs, width: right - left };
98
+ }
@@ -1,3 +1,5 @@
1
+ import { BoundingBox } from './boundingbox.js';
2
+ import { chordKerningProfile, layoutChordRuns } from './chordkerning.js';
1
3
  import { Element } from './element.js';
2
4
  import { Font } from './font.js';
3
5
  import { Glyphs } from './glyphs.js';
@@ -5,7 +7,7 @@ import { Metrics } from './metrics.js';
5
7
  import { Modifier } from './modifier.js';
6
8
  import { Tables } from './tables.js';
7
9
  import { isStemmableNote } from './typeguard.js';
8
- import { log } from './util.js';
10
+ import { log, RuntimeError } from './util.js';
9
11
  function L(...args) {
10
12
  if (ChordSymbol.DEBUG)
11
13
  log('VexFlow.ChordSymbol', args);
@@ -74,26 +76,34 @@ export class ChordSymbol extends Modifier {
74
76
  for (const symbol of symbols) {
75
77
  const note = symbol.checkAttachedNote();
76
78
  let lineSpaces = 1;
77
- for (let j = 0; j < symbol.symbolBlocks.length; ++j) {
78
- const block = symbol.symbolBlocks[j];
79
- const sup = block.isSuperscript();
80
- const sub = block.isSubscript();
81
- block.setXShift(width);
82
- if (sup || sub) {
79
+ const kernedWidth = symbol.formatKerning();
80
+ if (kernedWidth !== undefined) {
81
+ width = kernedWidth;
82
+ if (symbol.symbolBlocks.some((block) => block.isSuperscript() || block.isSubscript()))
83
83
  lineSpaces = 2;
84
- }
85
- if (sub && j > 0) {
86
- const prev = symbol.symbolBlocks[j - 1];
87
- if (prev.isSuperscript()) {
88
- block.setXShift(width - prev.getWidth() - ChordSymbol.minPadding);
89
- block.vAlign = true;
90
- width +=
91
- -prev.getWidth() -
92
- ChordSymbol.minPadding +
93
- (prev.getWidth() > block.getWidth() ? prev.getWidth() - block.getWidth() : 0);
84
+ }
85
+ else {
86
+ for (let j = 0; j < symbol.symbolBlocks.length; ++j) {
87
+ const block = symbol.symbolBlocks[j];
88
+ const sup = block.isSuperscript();
89
+ const sub = block.isSubscript();
90
+ block.setXShift(width);
91
+ if (sup || sub) {
92
+ lineSpaces = 2;
94
93
  }
94
+ if (sub && j > 0) {
95
+ const prev = symbol.symbolBlocks[j - 1];
96
+ if (prev.isSuperscript()) {
97
+ block.setXShift(width - prev.getWidth() - ChordSymbol.minPadding);
98
+ block.vAlign = true;
99
+ width +=
100
+ -prev.getWidth() -
101
+ ChordSymbol.minPadding +
102
+ (prev.getWidth() > block.getWidth() ? prev.getWidth() - block.getWidth() : 0);
103
+ }
104
+ }
105
+ width += block.getWidth() + ChordSymbol.minPadding;
95
106
  }
96
- width += block.getWidth() + ChordSymbol.minPadding;
97
107
  }
98
108
  if (symbol.getVertical() === ChordSymbolVerticalJustify.TOP) {
99
109
  symbol.setTextLine(state.topTextLine);
@@ -121,8 +131,9 @@ export class ChordSymbol extends Modifier {
121
131
  maxRightGlyphWidth = Math.max(glyphWidth / 2, maxRightGlyphWidth);
122
132
  }
123
133
  }
124
- symbol.width = width;
125
134
  }
135
+ if (symbol.getReportWidth() || symbol.kernedRuns)
136
+ symbol.width = width;
126
137
  width = 0;
127
138
  }
128
139
  const rightOverlap = Math.min(Math.max(rightWidth - maxRightGlyphWidth, 0), Math.max(rightWidth - state.rightShift, 0));
@@ -131,12 +142,58 @@ export class ChordSymbol extends Modifier {
131
142
  state.rightShift += rightOverlap;
132
143
  return true;
133
144
  }
145
+ setKerning(mode) {
146
+ if (mode !== 'auto' && mode !== 'none')
147
+ throw new RuntimeError('BadArgument', 'Kerning must be auto or none.');
148
+ this.kerning = mode;
149
+ this.kernedRuns = undefined;
150
+ return this;
151
+ }
152
+ getKerning() {
153
+ return this.kerning;
154
+ }
155
+ setKerningProfile(profile) {
156
+ if (profile &&
157
+ (!profile.textFont.trim() ||
158
+ !profile.musicFont.trim() ||
159
+ profile.pairs.some((pair) => Array.from(pair.left).length !== 1 ||
160
+ Array.from(pair.right).length !== 1 ||
161
+ !['baseline', 'superscript', 'subscript'].includes(pair.position) ||
162
+ !Number.isFinite(pair.adjustmentEm))))
163
+ throw new RuntimeError('BadArgument', 'Invalid chord kerning profile.');
164
+ this.kerningProfile = profile && Object.assign(Object.assign({}, profile), { pairs: profile.pairs.map((pair) => (Object.assign({}, pair))) });
165
+ this.kernedRuns = undefined;
166
+ return this;
167
+ }
168
+ formatKerning() {
169
+ var _a;
170
+ this.kernedRuns = undefined;
171
+ if (this.kerning === 'none')
172
+ return undefined;
173
+ const profile = chordKerningProfile(this.fontInfo, this.kerningProfile);
174
+ if (!profile)
175
+ return undefined;
176
+ const measurement = (_a = this.kerningMeasurement) !== null && _a !== void 0 ? _a : (this.kerningMeasurement = new Element());
177
+ const layout = layoutChordRuns(this.symbolBlocks.map((block) => ({
178
+ text: block.getText(),
179
+ position: block.isSuperscript() ? 'superscript' : block.isSubscript() ? 'subscript' : 'baseline',
180
+ })), this.fontInfo, profile, {
181
+ spacing: ChordSymbol.spacingBetweenBlocks,
182
+ ratio: ChordSymbol.superSubRatio,
183
+ superscript: ChordSymbol.superscriptOffset,
184
+ subscript: ChordSymbol.subscriptOffset,
185
+ }, (text, font) => measurement.setText(text).setFont(font).measureText());
186
+ this.kernedRuns = layout.runs;
187
+ return layout.width;
188
+ }
134
189
  constructor() {
135
190
  super();
136
191
  this.symbolBlocks = [];
137
192
  this.horizontal = ChordSymbolHorizontalJustify.LEFT;
138
193
  this.vertical = ChordSymbolVerticalJustify.TOP;
139
194
  this.reportWidth = true;
195
+ this.kerning = 'none';
196
+ this.kerningOrigin = { x: 0, y: 0 };
140
197
  }
141
198
  get superscriptOffset() {
142
199
  return ChordSymbol.superscriptOffset * Font.convertSizeToPixelValue(this.fontInfo.size);
@@ -259,7 +316,7 @@ export class ChordSymbol extends Modifier {
259
316
  x = start.x;
260
317
  }
261
318
  else if (this.horizontal === ChordSymbolHorizontalJustify.RIGHT) {
262
- x = start.x + this.getWidth();
319
+ x = this.kernedRuns ? start.x - this.getWidth() : start.x + this.getWidth();
263
320
  }
264
321
  else if (this.horizontal === ChordSymbolHorizontalJustify.CENTER) {
265
322
  x = start.x - this.getWidth() / 2;
@@ -268,17 +325,41 @@ export class ChordSymbol extends Modifier {
268
325
  x = note.getStemX() - this.getWidth() / 2;
269
326
  }
270
327
  L('Rendering ChordSymbol: ', x, y);
271
- this.symbolBlocks.forEach((symbol) => {
272
- L('Rendering Text: ', symbol.getText(), x + symbol.getXShift(), y + symbol.getYShift());
273
- symbol.setX(x);
274
- symbol.setY(y);
275
- symbol.renderText(ctx, 0, 0);
276
- });
328
+ if (this.kernedRuns) {
329
+ this.kerningOrigin = { x, y };
330
+ for (const run of this.kernedRuns) {
331
+ ctx.setFont(run.font);
332
+ ctx.fillText(run.text, x + run.x, y + run.y);
333
+ }
334
+ }
335
+ else {
336
+ this.symbolBlocks.forEach((symbol) => {
337
+ L('Rendering Text: ', symbol.getText(), x + symbol.getXShift(), y + symbol.getYShift());
338
+ symbol.setX(x);
339
+ symbol.setY(y);
340
+ symbol.renderText(ctx, 0, 0);
341
+ });
342
+ }
277
343
  this.drawPointerRect();
278
344
  ctx.closeGroup();
279
345
  }
280
346
  getBoundingBox() {
281
- const boundingBox = this.symbolBlocks[0].getBoundingBox();
347
+ if (this.kernedRuns) {
348
+ const { x, y } = this.kerningOrigin;
349
+ let box;
350
+ for (const run of this.kernedRuns) {
351
+ const m = run.metrics;
352
+ const ink = new BoundingBox(x + run.x - m.actualBoundingBoxLeft, y + run.y - m.actualBoundingBoxAscent, m.actualBoundingBoxLeft + m.actualBoundingBoxRight, m.actualBoundingBoxAscent + m.actualBoundingBoxDescent);
353
+ if (box)
354
+ box.mergeWith(ink);
355
+ else
356
+ box = ink;
357
+ }
358
+ return box !== null && box !== void 0 ? box : new BoundingBox(x, y, 0, 0);
359
+ }
360
+ if (!this.symbolBlocks.length)
361
+ return new BoundingBox(0, 0, 0, 0);
362
+ const boundingBox = BoundingBox.copy(this.symbolBlocks[0].getBoundingBox());
282
363
  for (let i = 1; i < this.symbolBlocks.length; i++) {
283
364
  boundingBox.mergeWith(this.symbolBlocks[i].getBoundingBox());
284
365
  }
@@ -73,6 +73,9 @@ export class Clef extends StaveModifier {
73
73
  this.setType(type, size, annotation);
74
74
  L('Creating clef:', type);
75
75
  }
76
+ getType() {
77
+ return this.type;
78
+ }
76
79
  setType(type, size = 'default', annotation) {
77
80
  this.type = type;
78
81
  this.code = Clef.types[type].code;
@@ -30,6 +30,10 @@ export class ClefNote extends Note {
30
30
  this.clef.renderText(ctx, 0, 0);
31
31
  }
32
32
  getBoundingBox() {
33
- return this.clef.getBoundingBox();
33
+ const box = this.clef.getBoundingBox();
34
+ const stave = this.getStave();
35
+ if (stave)
36
+ box.setY(stave.getYForLine(this.clef.line) + this.clef.getYShift() - this.clef.getTextMetrics().actualBoundingBoxAscent);
37
+ return box;
34
38
  }
35
39
  }
@@ -105,7 +105,7 @@ export class Dot extends Modifier {
105
105
  }
106
106
  setNote(note) {
107
107
  this.note = note;
108
- this.font = note.font;
108
+ this.setFont(note.fontInfo);
109
109
  return this;
110
110
  }
111
111
  setDotShiftY(y) {