From e9037174d6a511355e060be9b55a392cad76537f Mon Sep 17 00:00:00 2001 From: Rodrigo Vilar Date: Sun, 12 Feb 2023 13:50:34 +0100 Subject: [PATCH 1/2] unify metrics --- entry/vexflow-font-bravura.ts | 4 +- entry/vexflow-font-leland.ts | 4 +- entry/vexflow-font-petaluma.ts | 4 +- src/font.ts | 1 - src/fonts/bravura_metrics.ts | 556 ----------------- .../{leland_metrics.ts => common_metrics.ts} | 5 +- src/fonts/load_bravura.ts | 4 +- src/fonts/load_leland.ts | 4 +- src/fonts/load_petaluma.ts | 4 +- src/fonts/petaluma_metrics.ts | 575 ------------------ src/timesigglyph.ts | 10 +- 11 files changed, 22 insertions(+), 1149 deletions(-) delete mode 100644 src/fonts/bravura_metrics.ts rename src/fonts/{leland_metrics.ts => common_metrics.ts} (99%) delete mode 100644 src/fonts/petaluma_metrics.ts diff --git a/entry/vexflow-font-bravura.ts b/entry/vexflow-font-bravura.ts index 7a7a691fb3..9d07d956dd 100644 --- a/entry/vexflow-font-bravura.ts +++ b/entry/vexflow-font-bravura.ts @@ -9,11 +9,11 @@ // Then you will need to import the xxx_glyphs.ts and xxx_metrics.ts files. import { BravuraFont } from '../src/fonts/bravura_glyphs'; -import { BravuraMetrics } from '../src/fonts/bravura_metrics'; +import { CommonMetrics } from '../src/fonts/common_metrics'; export const Font = { data: BravuraFont, - metrics: BravuraMetrics, + metrics: CommonMetrics, }; export default Font; diff --git a/entry/vexflow-font-leland.ts b/entry/vexflow-font-leland.ts index b6f442d154..aa05fea723 100644 --- a/entry/vexflow-font-leland.ts +++ b/entry/vexflow-font-leland.ts @@ -1,11 +1,11 @@ // [VexFlow](https://vexflow.com) - Copyright (c) Mohit Muthanna 2010. // MIT License +import { CommonMetrics } from '../src/fonts/common_metrics'; import { LelandFont } from '../src/fonts/leland_glyphs'; -import { LelandMetrics } from '../src/fonts/leland_metrics'; export const Font = { data: LelandFont, - metrics: LelandMetrics, + metrics: CommonMetrics, }; export default Font; diff --git a/entry/vexflow-font-petaluma.ts b/entry/vexflow-font-petaluma.ts index ebf92233a9..4b322d0cc1 100644 --- a/entry/vexflow-font-petaluma.ts +++ b/entry/vexflow-font-petaluma.ts @@ -1,11 +1,11 @@ // [VexFlow](https://vexflow.com) - Copyright (c) Mohit Muthanna 2010. // MIT License +import { CommonMetrics } from '../src/fonts/common_metrics'; import { PetalumaFont } from '../src/fonts/petaluma_glyphs'; -import { PetalumaMetrics } from '../src/fonts/petaluma_metrics'; export const Font = { data: PetalumaFont, - metrics: PetalumaMetrics, + metrics: CommonMetrics, }; export default Font; diff --git a/src/font.ts b/src/font.ts index 03cbe0a58b..2cbe067049 100644 --- a/src/font.ts +++ b/src/font.ts @@ -35,7 +35,6 @@ export interface FontData { /** Specified in the `xxx_metrics.ts` files. */ // eslint-disable-next-line export interface FontMetrics extends Record { - name: string; smufl: boolean; stave?: Record; accidental?: Record; diff --git a/src/fonts/bravura_metrics.ts b/src/fonts/bravura_metrics.ts deleted file mode 100644 index 815072fdf6..0000000000 --- a/src/fonts/bravura_metrics.ts +++ /dev/null @@ -1,556 +0,0 @@ -/** - * The Bravura font was created by Daniel Spreadbury @ Steinberg. - * https://github.com/steinbergmedia/bravura/ - */ -export const BravuraMetrics = { - name: 'Bravura', - smufl: true, - - stave: { - padding: 12, - endPaddingMax: 10, - endPaddingMin: 5, - unalignedNotePadding: 10, - }, - - accidental: { - noteheadAccidentalPadding: 1, - leftPadding: 2, - accidentalSpacing: 3, - }, - - chordSymbol: { - global: { - superscriptOffset: -400, - subscriptOffset: 300, - kerningOffset: -250, - lowerKerningText: ['D', 'F', 'P', 'T', 'V', 'Y'], - upperKerningText: ['A', 'L'], - spacing: 100, - superSubRatio: 0.66, - }, - glyphs: { - csymDiminished: { - leftSideBearing: -32, - advanceWidth: 506, - yOffset: 0, - }, - csymHalfDiminished: { - leftSideBearing: -32, - advanceWidth: 506, - yOffset: 0, - }, - csymAugmented: { - leftSideBearing: 0, - advanceWidth: 530, - yOffset: 0, - }, - csymParensLeftTall: { - leftSideBearing: -20, - advanceWidth: 184, - yOffset: 250, - }, - csymParensRightTall: { - leftSideBearing: 0, - advanceWidth: 189, - yOffset: 250, - }, - csymBracketLeftTall: { - leftSideBearing: 0, - advanceWidth: 328, - yOffset: 0, - }, - csymBracketRightTall: { - leftSideBearing: 1, - advanceWidth: 600, - yOffset: 0, - }, - csymParensLeftVeryTall: { - leftSideBearing: 50, - advanceWidth: 121, - yOffset: 350, - }, - csymParensRightVeryTall: { - leftSideBearing: 0, - advanceWidth: 111, - yOffset: 350, - }, - csymDiagonalArrangementSlash: { - leftSideBearing: -1, - advanceWidth: 990, - yOffset: 0, - }, - csymMinor: { - leftSideBearing: 0, - advanceWidth: 482, - yOffset: 0, - }, - csymMajorSeventh: { - leftSideBearing: 200, - yOffset: 0, - advanceWidth: 600, - }, - accidentalSharp: { - leftSideBearing: 20, - advanceWidth: 250, - yOffset: -302, - }, - accidentalFlat: { - leftSideBearing: -20, - advanceWidth: 226, - yOffset: -184, - }, - }, - }, - clef_default: { - width: 26, - - annotations: { - '8va': { - point: 18, - treble: { - line: -1.4, - shiftX: 12, - }, - }, - '8vb': { - point: 18, - treble: { - line: 6, - shiftX: 10, - }, - bass: { - line: 3.5, - shiftX: 1, - }, - }, - }, - }, - - clef_small: { - width: 20, - annotations: { - '8va': { - point: 16, - treble: { - line: -0.2, - shiftX: 8, - }, - }, - '8vb': { - point: 16, - treble: { - line: 5.3, - shiftX: 6, - }, - bass: { - line: 3.1, - shiftX: 0.5, - }, - }, - }, - }, - - ornament: { - brassScoop: { - xOffset: -12, - yOffset: 0, - stemUpYOffset: 0, - reportedWidth: 20, - }, - brassDoitMedium: { - xOffset: 16, - yOffset: 0, - stemUpYOffset: 0, - reportedWidth: 22, - }, - brassFallLipShort: { - xOffset: 16, - yOffset: 0, - stemUpYOffset: 0, - reportedWidth: 15, - }, - brassLiftMedium: { - xOffset: 16, - yOffset: 5, - stemUpYOffset: 0, - reportedWidth: 5, - }, - brassFallRoughMedium: { - xOffset: 16, - yOffset: 28, - stemUpYOffset: 0, - reportedWidth: 5, - }, - brassBend: { - xOffset: 2, - yOffset: -8, - stemUpYOffset: 25, - reportedWidth: 5, - }, - brassMuteClosed: { - xOffset: 3, - yOffset: -8, - stemUpYOffset: 25, - reportedWidth: 5, - }, - brassMuteOpen: { - xOffset: 3, - yOffset: -7, - stemUpYOffset: 25, - reportedWidth: 5, - }, - brassFlip: { - xOffset: 10, - yOffset: 0, - stemUpYOffset: 7, - reportedWidth: 10, - }, - brassJazzTurn: { - xOffset: 0, - yOffset: 0, - stemUpYOffset: 8, - reportedWidth: 31, - }, - brassSmear: { - xOffset: 10, - yOffset: 0, - stemUpYOffset: 8, - reportedWidth: 5, - }, - }, - - parenthesis: { - default: { - point: 39, - width: 7, - }, - gracenote: { - point: (39 * 3) / 5, - width: 3, - }, - }, - - pedalMarking: { - up: { - point: 40, - }, - down: { - point: 34, - }, - }, - - // These are for numeric digits, such as in time signatures - digits: { - // used by TimeSignature object - shiftLine: -1, - point: 34, - - // used by tuplets - tupletPoint: 22, - shiftY: -6, - }, - - articulation: { - articStaccatissimoAbove: { - padding: 2, - }, - articStaccatissimoBelow: { - padding: 2, - }, - }, - - tremolo: { - default: { - point: 25, - spacing: 5, - offsetYStemUp: -5, - offsetYStemDown: 5, - offsetXStemUp: 11, - offsetXStemDown: 1, - }, - grace: { - point: 18, - spacing: 4, - offsetYStemUp: -5, - offsetYStemDown: 5, - offsetXStemUp: 7, - offsetXStemDown: 1, - }, - }, - - staveRepetition: { - symbolText: { - offsetX: 12, - offsetY: 25, - spacing: 5, - }, - coda: { - offsetY: 25, - }, - segno: { - offsetY: 10, - }, - }, - - noteHead: { - minPadding: 2, - }, - - stem: { - heightAdjustmentForFlag: -3, - // These are stem (Y) offsets to the note heads. To shift the - // noteheads (x-position) themselves, see glyphs.notehead.custom. - noteHead: { - noteheadTriangleUpHalf: { - offsetYBaseStemUp: 5, - offsetYBaseStemDown: 4, - }, - noteheadTriangleUpBlack: { - offsetYBaseStemUp: 5, - offsetYBaseStemDown: 4, - }, - noteheadTriangleUpWhole: { - offsetYBaseStemUp: 5, - offsetYBaseStemDown: 4, - }, - noteheadXHalf: { - offsetYBaseStemUp: -4, - offsetYBaseStemDown: 4, - }, - noteheadXBlack: { - offsetYBaseStemUp: -4, - offsetYBaseStemDown: 4, - }, - noteheadXWhole: { - offsetYBaseStemUp: -4, - offsetYBaseStemDown: 4, - }, - noteheadHalf: { - offsetYBaseStemUp: -2.55, - offsetYBaseStemDown: 2.65, - }, - noteheadBlack: { - offsetYBaseStemUp: -2, - offsetYBaseStemDown: 2, - }, - noteheadSquareWhite: { - offsetYBaseStemDown: -5, - offsetYBaseStemUp: 5, - }, - }, - }, - - stringNumber: { - verticalPadding: 8, - stemPadding: 2, - leftPadding: 5, - rightPadding: 6, - }, - - tuplet: { - noteHeadOffset: 20, - stemOffset: 10, - bottomLine: 4, - topModifierOffset: 15, - }, - - // Values under here are used by the Glyph class to reposition and rescale - // glyphs based on their category. This should be the first stop for - // custom font glyph repositioning. - // - // The glyph loader first looks up a specific set of settings based on the - // glyph code, and if not found, uses the defaults from the category. See - // glyphs.textNote for an example of this. - // - // Details in Glyph.lookupFontMetrics. - glyphs: { - coda: { - point: 20, - shiftX: -7, - shiftY: 8, - }, - segno: { - shiftX: -7, - }, - flag: { - shiftX: -0.75, - staveTempo: { - shiftX: -1, - }, - }, - clef_default: { - point: 32, - gClef: { - scale: 1.1, - shiftY: 1, - }, - fClef: { - shiftY: -0.5, - }, - '6stringTabClef': { - point: 32, - shiftY: -5.5, - }, - }, - clef_small: { - point: 26, - gClef: { - shiftY: 1.5, - }, - }, - clefNote_default: { - point: 32, - }, - clefNote_small: { - point: 26, - }, - ornament: { - ornamentTurn: { - scale: 1.2, - }, - ornamentTurnSlash: { - scale: 1.2, - }, - brassScoop: { - scale: 1.0, - }, - brassDoitMedium: { - scale: 1.0, - }, - brassFallLipShort: { - scale: 1.0, - }, - brassLiftMedium: { - scale: 1.0, - }, - brassFallRoughMedium: { - scale: 1.0, - }, - brassBend: { - scale: 1.0, - }, - brassMuteClosed: { - scale: 1.0, - }, - brassMuteOpen: { - scale: 1.0, - }, - brassFlip: { - scale: 1.0, - }, - brassJazzTurn: { - scale: 1.0, - }, - brassSmear: { - scale: 1.0, - }, - }, - stroke_straight: { - arrowheadBlackDown: { - shiftX: -4.5, - }, - arrowheadBlackUp: { - shiftX: -0.85, - }, - }, - stroke_wiggly: { - arrowheadBlackDown: { - shiftX: -1, - shiftY: 1, - }, - arrowheadBlackUp: { - shiftX: -1, - shiftY: 1, - }, - }, - textNote: { - point: 34, - breathMarkTick: { - point: 36, - shiftY: 9, - }, - breathMarkComma: { - point: 36, - }, - segno: { - point: 30, - shiftX: -7, - shiftY: 8, - }, - coda: { - point: 20, - shiftX: -7, - shiftY: 8, - }, - ornamentTrill: { - shiftX: -8, - shiftY: 8, - }, - ornamentTurn: { - point: 42, - }, - ornamentTurnSlash: { - point: 42, - }, - ornamentMordent: { - shiftX: -8, - }, - ornamentShortTrill: { - shiftX: -8, - }, - }, - noteHead: { - restQuarterStemUp: { - point: 35, - }, - restQuarterStemDown: { - point: 35, - }, - }, - chordSymbol: { - csymDiminished: { - scale: 0.8, - }, - csymHalfDiminished: { - scale: 0.8, - }, - csymAugmented: { - scale: 1, - }, - csymParensLeftTall: { - scale: 0.8, - }, - csymParensRightTall: { - scale: 0.8, - }, - csymBracketLeftTall: { - scale: 0.8, - }, - csymBracketRightTall: { - scale: 0.8, - }, - csymParensLeftVeryTall: { - scale: 0.9, - }, - csymParensRightVeryTall: { - scale: 0.9, - }, - csymDiagonalArrangementSlash: { - scale: 0.6, - }, - csymMinor: { - scale: 0.8, - }, - csymMajorSeventh: { - scale: 0.9, - }, - accidentalSharp: { - scale: 0.75, - }, - accidentalFlat: { - scale: 0.9, - }, - }, - }, -}; diff --git a/src/fonts/leland_metrics.ts b/src/fonts/common_metrics.ts similarity index 99% rename from src/fonts/leland_metrics.ts rename to src/fonts/common_metrics.ts index 35f945a9f2..06ef54dbe3 100644 --- a/src/fonts/leland_metrics.ts +++ b/src/fonts/common_metrics.ts @@ -1,5 +1,4 @@ -export const LelandMetrics = { - name: 'Leland', +export const CommonMetrics = { smufl: true, stave: { @@ -215,6 +214,7 @@ export const LelandMetrics = { reportedWidth: 5, }, }, + parenthesis: { default: { point: 39, @@ -400,7 +400,6 @@ export const LelandMetrics = { clefNote_small: { point: 26, }, - ornament: { ornamentTurn: { scale: 1.2, diff --git a/src/fonts/load_bravura.ts b/src/fonts/load_bravura.ts index 17eb124cd3..878b4d71a2 100644 --- a/src/fonts/load_bravura.ts +++ b/src/fonts/load_bravura.ts @@ -13,8 +13,8 @@ import { Font } from '../font'; import { BravuraFont } from './bravura_glyphs'; -import { BravuraMetrics } from './bravura_metrics'; +import { CommonMetrics } from './common_metrics'; export function loadBravura() { - Font.load('Bravura', BravuraFont, BravuraMetrics); + Font.load('Bravura', BravuraFont, CommonMetrics); } diff --git a/src/fonts/load_leland.ts b/src/fonts/load_leland.ts index 959c50677d..07485a0a04 100644 --- a/src/fonts/load_leland.ts +++ b/src/fonts/load_leland.ts @@ -2,9 +2,9 @@ // MIT License import { Font } from '../font'; +import { CommonMetrics } from './common_metrics'; import { LelandFont } from './leland_glyphs'; -import { LelandMetrics } from './leland_metrics'; export function loadLeland() { - Font.load('Leland', LelandFont, LelandMetrics); + Font.load('Leland', LelandFont, CommonMetrics); } diff --git a/src/fonts/load_petaluma.ts b/src/fonts/load_petaluma.ts index 8d791c39ba..28ffa173ba 100644 --- a/src/fonts/load_petaluma.ts +++ b/src/fonts/load_petaluma.ts @@ -2,9 +2,9 @@ // MIT License import { Font } from '../font'; +import { CommonMetrics } from './common_metrics'; import { PetalumaFont } from './petaluma_glyphs'; -import { PetalumaMetrics } from './petaluma_metrics'; export function loadPetaluma() { - Font.load('Petaluma', PetalumaFont, PetalumaMetrics); + Font.load('Petaluma', PetalumaFont, CommonMetrics); } diff --git a/src/fonts/petaluma_metrics.ts b/src/fonts/petaluma_metrics.ts deleted file mode 100644 index 112c8def25..0000000000 --- a/src/fonts/petaluma_metrics.ts +++ /dev/null @@ -1,575 +0,0 @@ -/** - * The Petaluma font was created by Steinberg Media. - * https://github.com/steinbergmedia/petaluma - */ -export const PetalumaMetrics = { - name: 'Petaluma', - smufl: true, - - stave: { - padding: 15, - endPaddingMax: 15, - endPaddingMin: 7, - unalignedNotePadding: 12, - }, - - accidental: { - noteheadAccidentalPadding: 1, - leftPadding: 2, - accidentalSpacing: 3, - }, - - chordSymbol: { - global: { - superscriptOffset: -400, - subscriptOffset: 300, - kerningOffset: -150, - lowerKerningText: ['D', 'F', 'P', 'T', 'V', 'Y'], - upperKerningText: ['L'], - spacing: 20, - superSubRatio: 0.73, - }, - glyphs: { - csymDiminished: { - leftSideBearing: -95, - advanceWidth: 506, - yOffset: 0, - }, - csymHalfDiminished: { - leftSideBearing: -32, - advanceWidth: 506, - yOffset: 0, - }, - csymAugmented: { - leftSideBearing: -25, - advanceWidth: 530, - yOffset: 0, - }, - csymParensLeftTall: { - leftSideBearing: 0, - advanceWidth: 155, - yOffset: 150, - }, - csymParensRightTall: { - leftSideBearing: 40, - advanceWidth: 189, - yOffset: 150, - }, - csymBracketLeftTall: { - leftSideBearing: 0, - advanceWidth: 328, - yOffset: 0, - }, - csymBracketRightTall: { - leftSideBearing: 1, - advanceWidth: 600, - yOffset: 0, - }, - csymParensLeftVeryTall: { - leftSideBearing: 0, - advanceWidth: 210, - yOffset: 250, - }, - csymParensRightVeryTall: { - leftSideBearing: -100, - advanceWidth: 111, - yOffset: 250, - }, - csymDiagonalArrangementSlash: { - leftSideBearing: -1, - advanceWidth: 990, - yOffset: 0, - }, - csymMinor: { - leftSideBearing: 0, - advanceWidth: 482, - yOffset: 0, - }, - csymMajorSeventh: { - leftSideBearing: 100, - yOffset: 0, - advanceWidth: 600, - }, - accidentalSharp: { - leftSideBearing: 0, - advanceWidth: 425, - yOffset: -422, - }, - accidentalFlat: { - leftSideBearing: -10, - advanceWidth: 228, - yOffset: -284, - }, - }, - }, - clef_default: { - width: 26, - annotations: { - '8va': { - point: 18, - treble: { - line: -1.4, - shiftX: 12, - }, - }, - '8vb': { - point: 18, - treble: { - line: 6, - shiftX: 10, - }, - bass: { - line: 3.5, - shiftX: 1, - }, - }, - }, - }, - clef_small: { - width: 20, - annotations: { - '8va': { - point: 16, - treble: { - line: -0.2, - shiftX: 8, - }, - }, - '8vb': { - point: 16, - treble: { - line: 5.3, - shiftX: 6, - }, - bass: { - line: 3.1, - shiftX: 0.5, - }, - }, - }, - }, - ornament: { - brassScoop: { - xOffset: -12, - yOffset: 0, - stemUpYOffset: 0, - reportedWidth: 15, - }, - brassDoitMedium: { - xOffset: 16, - yOffset: 0, - stemUpYOffset: 0, - reportedWidth: 19, - }, - brassFallLipShort: { - xOffset: 16, - yOffset: 0, - stemUpYOffset: 0, - reportedWidth: 19, - }, - brassLiftMedium: { - xOffset: 16, - yOffset: 5, - stemUpYOffset: 0, - reportedWidth: 15, - }, - brassFallRoughMedium: { - xOffset: 16, - yOffset: 26, - stemUpYOffset: 0, - reportedWidth: 5, - }, - brassBend: { - xOffset: 3, - yOffset: -8, - stemUpYOffset: 28, - reportedWidth: 5, - }, - brassMuteClosed: { - xOffset: 3, - yOffset: -8, - stemUpYOffset: 26, - reportedWidth: 5, - }, - brassMuteOpen: { - xOffset: 4, - yOffset: -8, - stemUpYOffset: 27, - reportedWidth: 5, - }, - brassFlip: { - xOffset: 10, - yOffset: -4, - stemUpYOffset: 7, - reportedWidth: 5, - }, - brassJazzTurn: { - xOffset: 6, - yOffset: -4, - stemUpYOffset: 5, - reportedWidth: 30, - }, - brassSmear: { - xOffset: 10, - yOffset: -4, - stemUpYOffset: 5, - reportedWidth: 5, - }, - }, - parenthesis: { - default: { - point: 39, - width: 7, - }, - gracenote: { - point: (39 * 3) / 5, - width: 3, - }, - }, - - pedalMarking: { - up: { - point: 40, - }, - down: { - point: 34, - }, - }, - - // These are for numeric digits, such as in time signatures - digits: { - // used by timesig - shiftLine: -1, - point: 22, - - // used by tuplets - tupletPoint: 16, - shiftY: -2, - }, - - articulation: { - articStaccatissimoAbove: { - padding: 2, - }, - articStaccatissimoBelow: { - padding: 2, - }, - }, - - tremolo: { - default: { - point: 25, - spacing: 5, - offsetYStemUp: -5, - offsetYStemDown: 5, - offsetXStemUp: 13, - offsetXStemDown: 1, - }, - grace: { - point: 18, - spacing: 4, - offsetYStemUp: -5, - offsetYStemDown: 5, - offsetXStemUp: 8, - offsetXStemDown: 1, - }, - }, - - staveRepetition: { - symbolText: { - offsetX: 12, - offsetY: 25, - spacing: 5, - }, - coda: { - offsetY: 25, - }, - segno: { - offsetY: 10, - }, - }, - - noteHead: { - minPadding: 2, - displacedShiftX: -2, - }, - - stem: { - heightAdjustmentForFlag: -3, - // These are stem (Y) offsets to the note heads. To shift the - // noteheads (x-position) themselves, see glyphs.notehead.custom. - noteHead: { - noteheadTriangleUpHalf: { - offsetYBaseStemUp: 5, - offsetYBaseStemDown: 4, - }, - noteheadTriangleUpBlack: { - offsetYBaseStemUp: 5, - offsetYBaseStemDown: 4, - }, - noteheadTriangleUpWhole: { - offsetYBaseStemUp: 5, - offsetYBaseStemDown: 4, - }, - noteheadXHalf: { - offsetYBaseStemUp: -4, - offsetYBaseStemDown: 4, - }, - noteheadXBlack: { - offsetYBaseStemUp: -4, - offsetYBaseStemDown: 4, - }, - noteheadXWhole: { - offsetYBaseStemUp: -4, - offsetYBaseStemDown: 4, - }, - noteheadHalf: { - offsetYBaseStemDown: 1.8, - offsetYBaseStemUp: -1.8, - }, - noteheadBlack: { - offsetYBaseStemDown: 2, - offsetYBaseStemUp: -2, - }, - noteheadSquareWhite: { - offsetYBaseStemDown: -5, - offsetYBaseStemUp: 5, - }, - }, - }, - - stringNumber: { - verticalPadding: 8, - stemPadding: 2, - leftPadding: 5, - rightPadding: 6, - }, - - tuplet: { - noteHeadOffset: 20, - stemOffset: 10, - bottomLine: 4, - topModifierOffset: 20, - }, - - // Values under here are used by the Glyph class to reposition and rescale - // glyphs based on their category. This should be the first stop for - // custom font glyph repositioning. - // - // The glyph loader first looks up a specific set of settings based on the - // glyph code, and if not found, uses the defaults from the category. See - // glyphs.textNote for an example of this. - // - // Details in Glyph.lookupFontMetrics. - glyphs: { - coda: { - point: 20, - shiftX: -7, - shiftY: 8, - }, - segno: { - shiftX: -7, - }, - flag: { - shiftX: -0.77, - flag16thUp: { - shiftX: -0.75, - }, - flag32ndUp: { - shiftX: -0.85, - }, - flag64thUp: { - shiftX: -1.55, - }, - flag128thUp: { - shiftX: -1.3, - }, - flag16thDown: { - shiftX: -0.75, - }, - flag32ndDown: { - shiftX: -0.76, - }, - flag64thDown: { - shiftX: -1.5, - }, - flag128thDown: { - shiftX: -1.2, - }, - staveTempo: { - shiftX: -1, - }, - }, - clef_default: { - point: 32, - gClef: { - scale: 1.1, - shiftY: 1, - }, - fClef: { - shiftY: -0.5, - }, - '6stringTabClef': { - point: 32, - shiftY: -5.5, - }, - }, - clef_small: { - point: 26, - gClef: { - shiftY: 1.5, - }, - }, - clefNote_default: { - point: 32, - }, - clefNote_small: { - point: 26, - }, - - ornament: { - ornamentTurn: { - scale: 1.2, - }, - ornamentTurnSlash: { - scale: 1.2, - }, - brassScoop: { - scale: 1.0, - }, - brassDoitMedium: { - scale: 1.0, - }, - brassFallLipShort: { - scale: 1.0, - }, - brassLiftMedium: { - scale: 1.0, - }, - brassFallRoughMedium: { - scale: 1.0, - }, - brassBend: { - scale: 1.0, - }, - brassMuteClosed: { - scale: 1.0, - }, - brassMuteOpen: { - scale: 1.0, - }, - brassFlip: { - scale: 1.0, - }, - brassJazzTurn: { - scale: 1.0, - }, - brassSmear: { - scale: 1.0, - }, - }, - stroke_straight: { - arrowheadBlackDown: { - shiftX: -4.5, - }, - arrowheadBlackUp: { - shiftX: -0.85, - }, - }, - stroke_wiggly: { - arrowheadBlackDown: { - shiftX: -1, - shiftY: 1, - }, - arrowheadBlackUp: { - shiftX: -1, - shiftY: 1, - }, - }, - textNote: { - point: 34, - breathMarkTick: { - point: 36, - shiftY: 9, - }, - breathMarkComma: { - point: 36, - }, - segno: { - point: 30, - shiftX: -7, - shiftY: 8, - }, - coda: { - point: 20, - shiftX: -7, - shiftY: 8, - }, - ornamentTrill: { - shiftX: -10, - shiftY: 8, - }, - ornamentMordent: { - shiftX: -8, - }, - ornamentShortTrill: { - shiftX: -8, - }, - }, - noteHead: { - noteheadBlackStemUp: { - shiftX: 0.5, - }, - noteheadHalfStemUp: { - shiftX: 0.725, - }, - noteheadWholeStemUp: { - shiftX: 1, - }, - }, - chordSymbol: { - csymDiminished: { - scale: 0.8, - }, - csymHalfDiminished: { - scale: 0.8, - }, - csymAugmented: { - scale: 1, - }, - csymParensLeftTall: { - scale: 0.8, - }, - csymParensRightTall: { - scale: 0.8, - }, - csymBracketLeftTall: { - scale: 0.8, - }, - csymBracketRightTall: { - scale: 0.8, - }, - csymParensLeftVeryTall: { - scale: 0.95, - }, - csymParensRightVeryTall: { - scale: 0.9, - }, - csymDiagonalArrangementSlash: { - scale: 0.6, - }, - csymMinor: { - scale: 0.7, - }, - csymMajorSeventh: { - scale: 0.8, - }, - accidentalSharp: { - scale: 0.7, - }, - accidentalFlat: { - scale: 0.8, - }, - }, - }, -}; diff --git a/src/timesigglyph.ts b/src/timesigglyph.ts index 0edc85135f..82f7ecf3e3 100644 --- a/src/timesigglyph.ts +++ b/src/timesigglyph.ts @@ -13,6 +13,7 @@ export class TimeSignatureGlyph extends Glyph { topStartX: number; botStartX: number; width: number; + lineShift: number; xMin: number; constructor( @@ -29,6 +30,7 @@ export class TimeSignatureGlyph extends Glyph { this.botGlyphs = []; let topWidth = 0; + let height = 0; for (let i = 0; i < topDigits.length; ++i) { let timeSigType = topDigits[i]; switch (topDigits[i]) { @@ -49,6 +51,7 @@ export class TimeSignatureGlyph extends Glyph { this.topGlyphs.push(topGlyph); topWidth += topGlyph.getMetrics().width ?? 0; + height = Math.max(height, topGlyph.getMetrics().height); } let botWidth = 0; @@ -69,8 +72,11 @@ export class TimeSignatureGlyph extends Glyph { this.botGlyphs.push(botGlyph); botWidth += defined(botGlyph.getMetrics().width); + height = Math.max(height, botGlyph.getMetrics().height); } + this.lineShift = height > 20 ? 1 : 0; + this.width = Math.max(topWidth, botWidth); this.xMin = this.getMetrics().x_min; this.topStartX = (this.width - topWidth) / 2.0; @@ -92,7 +98,7 @@ export class TimeSignatureGlyph extends Glyph { let start_x = x + this.topStartX; let y = 0; - if (this.botGlyphs.length > 0) y = stave.getYForLine(this.timeSignature.topLine); + if (this.botGlyphs.length > 0) y = stave.getYForLine(this.timeSignature.topLine - this.lineShift); else y = (stave.getYForLine(this.timeSignature.topLine) + stave.getYForLine(this.timeSignature.bottomLine)) / 2; for (let i = 0; i < this.topGlyphs.length; ++i) { const glyph = this.topGlyphs[i]; @@ -101,7 +107,7 @@ export class TimeSignatureGlyph extends Glyph { } start_x = x + this.botStartX; - y = stave.getYForLine(this.timeSignature.bottomLine); + y = stave.getYForLine(this.timeSignature.bottomLine + this.lineShift); for (let i = 0; i < this.botGlyphs.length; ++i) { const glyph = this.botGlyphs[i]; this.timeSignature.placeGlyphOnLine(glyph, stave, this.timeSignature.getLine()); From bd9b7ce10228414a6030ceff7b29ed5a0b23bbce Mon Sep 17 00:00:00 2001 From: Rodrigo Vilar Date: Fri, 17 Feb 2023 17:12:28 +0100 Subject: [PATCH 2/2] review comments --- src/timesigglyph.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/timesigglyph.ts b/src/timesigglyph.ts index 82f7ecf3e3..fd89e315db 100644 --- a/src/timesigglyph.ts +++ b/src/timesigglyph.ts @@ -75,6 +75,8 @@ export class TimeSignatureGlyph extends Glyph { height = Math.max(height, botGlyph.getMetrics().height); } + // If the height of the digits is more than two staff spaces (20), shift to the next line + // in order to center the digits on lines 1 and 5 rather than 2 and 4. this.lineShift = height > 20 ? 1 : 0; this.width = Math.max(topWidth, botWidth);