Skip to content

Commit 3e13629

Browse files
authored
Merge pull request #1487 from rvilarl/refactor/metricsStep
Refactor FontMetrics: stringnumber
2 parents b97e75b + 63998d2 commit 3e13629

File tree

6 files changed

+46
-27
lines changed

6 files changed

+46
-27
lines changed

src/font.ts

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

34
export interface FontInfo {
@@ -42,6 +43,7 @@ export interface FontMetrics extends Record<string, any> {
4243
tremolo?: Record<string, Record<string, number>>;
4344
// Not specified in bravura_metrics.ts or gonville_metrics.ts.
4445
noteHead?: Record<string, Record<string, number>>;
46+
stringNumber?: StringNumberMetrics;
4547
// eslint-disable-next-line
4648
glyphs: Record<string, Record<string, any>>;
4749
}

src/fonts/bravura_metrics.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ export const BravuraMetrics = {
203203
},
204204
},
205205

206+
stringNumber: {
207+
verticalPadding: 8,
208+
stemPadding: 2,
209+
leftPadding: 5,
210+
rightPadding: 6,
211+
},
212+
206213
// Values under here are used by the Glyph class to reposition and rescale
207214
// glyphs based on their category. This should be the first stop for
208215
// custom font glyph repositioning.
@@ -244,12 +251,6 @@ export const BravuraMetrics = {
244251
scale: 1.2,
245252
},
246253
},
247-
stringNumber: {
248-
verticalPadding: 8,
249-
stemPadding: 2,
250-
leftPadding: 5,
251-
rightPadding: 6,
252-
},
253254
stroke: {
254255
arrowheadBlackDown: {
255256
straight: {

src/fonts/gonville_metrics.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ export const GonvilleMetrics = {
193193
},
194194
},
195195

196+
stringNumber: {
197+
verticalPadding: 8,
198+
stemPadding: 2,
199+
leftPadding: 5,
200+
rightPadding: 6,
201+
},
202+
196203
glyphs: {
197204
flag: {
198205
shiftX: -0.08,
@@ -224,12 +231,6 @@ export const GonvilleMetrics = {
224231
shiftY: -22,
225232
},
226233
},
227-
stringNumber: {
228-
verticalPadding: 8,
229-
stemPadding: 2,
230-
leftPadding: 5,
231-
rightPadding: 6,
232-
},
233234
textNote: {
234235
point: 40,
235236
default: {},

src/fonts/leland_metrics.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ export const LelandMetrics = {
199199
},
200200
},
201201

202+
stringNumber: {
203+
verticalPadding: 8,
204+
stemPadding: 2,
205+
leftPadding: 5,
206+
rightPadding: 6,
207+
},
208+
202209
// Values under here are used by the Glyph class to reposition and rescale
203210
// glyphs based on their category. This should be the first stop for
204211
// custom font glyph repositioning.
@@ -240,12 +247,6 @@ export const LelandMetrics = {
240247
scale: 1.2,
241248
},
242249
},
243-
stringNumber: {
244-
verticalPadding: 8,
245-
stemPadding: 2,
246-
leftPadding: 5,
247-
rightPadding: 6,
248-
},
249250
stroke: {
250251
arrowheadBlackDown: {
251252
straight: {

src/fonts/petaluma_metrics.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ export const PetalumaMetrics = {
207207
},
208208
},
209209

210+
stringNumber: {
211+
verticalPadding: 8,
212+
stemPadding: 2,
213+
leftPadding: 5,
214+
rightPadding: 6,
215+
},
216+
210217
// Values under here are used by the Glyph class to reposition and rescale
211218
// glyphs based on their category. This should be the first stop for
212219
// custom font glyph repositioning.
@@ -272,12 +279,6 @@ export const PetalumaMetrics = {
272279
scale: 1.2,
273280
},
274281
},
275-
stringNumber: {
276-
verticalPadding: 8,
277-
stemPadding: 2,
278-
leftPadding: 5,
279-
rightPadding: 6,
280-
},
281282
stroke: {
282283
arrowheadBlackDown: {
283284
straight: {

src/stringnumber.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ import { Tables } from './tables';
1515
import { Category, isStaveNote, isStemmableNote } from './typeguard';
1616
import { RuntimeError } from './util';
1717

18+
export interface StringNumberMetrics {
19+
verticalPadding: number;
20+
stemPadding: number;
21+
leftPadding: number;
22+
rightPadding: number;
23+
}
24+
1825
export class StringNumber extends Modifier {
1926
static get CATEGORY(): string {
2027
return Category.StringNumber;
@@ -27,9 +34,15 @@ export class StringNumber extends Modifier {
2734
style: FontStyle.NORMAL,
2835
};
2936

30-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
31-
static get metrics(): any {
32-
return Tables.currentMusicFont().getMetrics().glyphs.stringNumber;
37+
static get metrics(): StringNumberMetrics {
38+
return (
39+
Tables.currentMusicFont().getMetrics().stringNumber ?? {
40+
verticalPadding: 0,
41+
stemPadding: 0,
42+
leftPadding: 0,
43+
rightPadding: 0,
44+
}
45+
);
3346
}
3447

3548
// ## Static Methods

0 commit comments

Comments
 (0)