Skip to content

Commit ca390da

Browse files
committed
chordsymbol metrics
1 parent 3e13629 commit ca390da

File tree

6 files changed

+364
-212
lines changed

6 files changed

+364
-212
lines changed

src/chordsymbol.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { StemmableNote } from './stemmablenote';
1818
import { Tables } from './tables';
1919
import { TextFormatter } from './textformatter';
2020
import { Category, isStemmableNote } from './typeguard';
21-
import { log } from './util';
21+
import { log, RuntimeError } from './util';
2222

2323
// To enable logging for this class. Set `Vex.Flow.ChordSymbol.DEBUG` to `true`.
2424
// eslint-disable-next-line
@@ -37,6 +37,25 @@ export interface ChordSymbolBlock {
3737
glyph?: Glyph;
3838
}
3939

40+
export interface ChordSymbolGlyphMetrics {
41+
leftSideBearing: number;
42+
advanceWidth: number;
43+
yOffset: number;
44+
}
45+
46+
export interface ChordSymbolMetrics {
47+
global: {
48+
superscriptOffset: number;
49+
subscriptOffset: number;
50+
kerningOffset: number;
51+
lowerKerningText: string[];
52+
upperKerningText: string[];
53+
spacing: number;
54+
superSubRatio: number;
55+
};
56+
glyphs: Record<string, ChordSymbolGlyphMetrics>;
57+
}
58+
4059
export enum ChordSymbolHorizontalJustify {
4160
LEFT = 1,
4261
CENTER = 2,
@@ -104,10 +123,9 @@ export class ChordSymbol extends Modifier {
104123
return ChordSymbol.noFormat;
105124
}
106125

107-
// eslint-disable-next-line
108-
static getMetricForGlyph(glyphCode: string): any {
109-
if (ChordSymbol.metrics[glyphCode]) {
110-
return ChordSymbol.metrics[glyphCode];
126+
static getMetricForGlyph(glyphCode: string): ChordSymbolGlyphMetrics | undefined {
127+
if (ChordSymbol.metrics.glyphs[glyphCode]) {
128+
return ChordSymbol.metrics.glyphs[glyphCode];
111129
}
112130
return undefined;
113131
}
@@ -224,9 +242,11 @@ export class ChordSymbol extends Modifier {
224242

225243
static readonly symbolModifiers = SymbolModifiers;
226244

227-
// eslint-disable-next-line
228-
static get metrics(): any {
229-
return Tables.currentMusicFont().getMetrics().glyphs.chordSymbol;
245+
static get metrics(): ChordSymbolMetrics {
246+
const chordSymbol = Tables.currentMusicFont().getMetrics().chordSymbol;
247+
248+
if (!chordSymbol) throw new RuntimeError('BadMetrics', `chordSymbol missing`);
249+
return chordSymbol;
230250
}
231251

232252
static get lowerKerningText(): string[] {

src/font.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ChordSymbolMetrics } from './chordsymbol';
12
import { StringNumberMetrics } from './stringnumber';
23
import { defined } from './util';
34

@@ -43,6 +44,7 @@ export interface FontMetrics extends Record<string, any> {
4344
tremolo?: Record<string, Record<string, number>>;
4445
// Not specified in bravura_metrics.ts or gonville_metrics.ts.
4546
noteHead?: Record<string, Record<string, number>>;
47+
chordSymbol?: ChordSymbolMetrics;
4648
stringNumber?: StringNumberMetrics;
4749
// eslint-disable-next-line
4850
glyphs: Record<string, Record<string, any>>;

src/fonts/bravura_metrics.ts

Lines changed: 83 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,89 @@ export const BravuraMetrics = {
1919
accidentalSpacing: 3,
2020
},
2121

22+
chordSymbol: {
23+
global: {
24+
superscriptOffset: -400,
25+
subscriptOffset: 300,
26+
kerningOffset: -250,
27+
lowerKerningText: ['D', 'F', 'P', 'T', 'V', 'Y'],
28+
upperKerningText: ['A', 'L'],
29+
spacing: 100,
30+
superSubRatio: 0.66,
31+
},
32+
glyphs: {
33+
csymDiminished: {
34+
leftSideBearing: -32,
35+
advanceWidth: 506,
36+
yOffset: 0,
37+
},
38+
csymHalfDiminished: {
39+
leftSideBearing: -32,
40+
advanceWidth: 506,
41+
yOffset: 0,
42+
},
43+
csymAugmented: {
44+
leftSideBearing: 0,
45+
advanceWidth: 530,
46+
yOffset: 0,
47+
},
48+
csymParensLeftTall: {
49+
leftSideBearing: -20,
50+
advanceWidth: 184,
51+
yOffset: 250,
52+
},
53+
csymParensRightTall: {
54+
leftSideBearing: 0,
55+
advanceWidth: 189,
56+
yOffset: 250,
57+
},
58+
csymBracketLeftTall: {
59+
leftSideBearing: 0,
60+
advanceWidth: 328,
61+
yOffset: 0,
62+
},
63+
csymBracketRightTall: {
64+
leftSideBearing: 1,
65+
advanceWidth: 600,
66+
yOffset: 0,
67+
},
68+
csymParensLeftVeryTall: {
69+
leftSideBearing: 50,
70+
advanceWidth: 121,
71+
yOffset: 350,
72+
},
73+
csymParensRightVeryTall: {
74+
leftSideBearing: 0,
75+
advanceWidth: 111,
76+
yOffset: 350,
77+
},
78+
csymDiagonalArrangementSlash: {
79+
leftSideBearing: -1,
80+
advanceWidth: 990,
81+
yOffset: 0,
82+
},
83+
csymMinor: {
84+
leftSideBearing: 0,
85+
advanceWidth: 482,
86+
yOffset: 0,
87+
},
88+
csymMajorSeventh: {
89+
leftSideBearing: 200,
90+
yOffset: 0,
91+
advanceWidth: 600,
92+
},
93+
accidentalSharp: {
94+
leftSideBearing: 20,
95+
advanceWidth: 250,
96+
yOffset: -302,
97+
},
98+
accidentalFlat: {
99+
leftSideBearing: -20,
100+
advanceWidth: 226,
101+
yOffset: -184,
102+
},
103+
},
104+
},
22105
clef: {
23106
default: {
24107
point: 32,
@@ -319,98 +402,47 @@ export const BravuraMetrics = {
319402
},
320403
},
321404
chordSymbol: {
322-
global: {
323-
superscriptOffset: -400,
324-
subscriptOffset: 300,
325-
kerningOffset: -250,
326-
lowerKerningText: ['D', 'F', 'P', 'T', 'V', 'Y'],
327-
upperKerningText: ['A', 'L'],
328-
spacing: 100,
329-
superSubRatio: 0.66,
330-
},
331405
csymDiminished: {
332406
scale: 0.8,
333-
leftSideBearing: -32,
334-
advanceWidth: 506,
335-
yOffset: 0,
336407
},
337408
csymHalfDiminished: {
338409
scale: 0.8,
339-
leftSideBearing: -32,
340-
advanceWidth: 506,
341-
yOffset: 0,
342410
},
343411
csymAugmented: {
344412
scale: 1,
345-
leftSideBearing: 0,
346-
advanceWidth: 530,
347-
yOffset: 0,
348413
},
349414
csymParensLeftTall: {
350415
scale: 0.8,
351-
leftSideBearing: -20,
352-
advanceWidth: 184,
353-
yOffset: 250,
354416
},
355417
csymParensRightTall: {
356418
scale: 0.8,
357-
leftSideBearing: 0,
358-
advanceWidth: 189,
359-
yOffset: 250,
360419
},
361420
csymBracketLeftTall: {
362421
scale: 0.8,
363-
leftSideBearing: 0,
364-
advanceWidth: 328,
365-
yOffset: 0,
366422
},
367423
csymBracketRightTall: {
368424
scale: 0.8,
369-
leftSideBearing: 1,
370-
advanceWidth: 600,
371-
yOffset: 0,
372425
},
373426
csymParensLeftVeryTall: {
374427
scale: 0.9,
375-
leftSideBearing: 50,
376-
advanceWidth: 121,
377-
yOffset: 350,
378428
},
379429
csymParensRightVeryTall: {
380430
scale: 0.9,
381-
leftSideBearing: 0,
382-
advanceWidth: 111,
383-
yOffset: 350,
384431
},
385432
csymDiagonalArrangementSlash: {
386433
scale: 0.6,
387-
leftSideBearing: -1,
388-
advanceWidth: 990,
389-
yOffset: 0,
390434
},
391435
csymMinor: {
392436
scale: 0.8,
393-
leftSideBearing: 0,
394-
advanceWidth: 482,
395-
yOffset: 0,
396437
},
397438
csymMajorSeventh: {
398439
scale: 0.9,
399-
leftSideBearing: 200,
400-
yOffset: 0,
401-
advanceWidth: 600,
402440
},
403441
accidentalSharp: {
404442
scale: 0.75,
405-
leftSideBearing: 20,
406-
advanceWidth: 250,
407-
yOffset: -302,
408443
},
409444
accidentalFlat: {
410445
scale: 0.9,
411-
leftSideBearing: -20,
412-
advanceWidth: 226,
413-
yOffset: -184,
414446
},
415447
},
416448
jazzOrnaments: {

0 commit comments

Comments
 (0)