Skip to content

Commit

Permalink
Merge pull request #1569 from 0xfe/chord-symbol-metrics
Browse files Browse the repository at this point in the history
re-introduce font-specific formatting to chord symbol metrics
  • Loading branch information
rvilarl authored May 28, 2023
2 parents fff37a0 + 83e4008 commit 6cf8770
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/chordsymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,6 @@ export class ChordSymbol extends Modifier {
const glyphArgs = ChordSymbol.glyphs[params.glyph];
const glyphPoints = 20;
symbolBlock.glyph = new Glyph(glyphArgs.code, glyphPoints, { category: 'chordSymbol' });
// Beware: glyph.metrics is not the same as glyph.getMetrics() !
// rv.glyph.point = rv.glyph.point * rv.glyph.metrics.scale;
// rv.width = rv.glyph.getMetrics().width;
// don't set yShift here, b/c we need to do it at formatting time after the font is set.
} else if (symbolType === SymbolTypes.TEXT) {
symbolBlock.width = this.textFormatter.getWidthForTextInEm(symbolBlock.text);
} else if (symbolType === SymbolTypes.LINE) {
Expand Down
81 changes: 80 additions & 1 deletion src/fonts/load_petaluma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,86 @@
import { Font } from '../font';
import { CommonMetrics } from './common_metrics';
import { PetalumaFont } from './petaluma_glyphs';
import { ChordSymbolGlyphMetrics } from '../chordsymbol';
import { FontMetrics } from '../font';

const petalumaChordMetrics: Record<string, ChordSymbolGlyphMetrics> = {
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,
}
}
export function loadPetaluma() {
Font.load('Petaluma', PetalumaFont, CommonMetrics);
const metrics: FontMetrics = JSON.parse(JSON.stringify(CommonMetrics));
const chordMetrics = metrics.chordSymbol;
if (chordMetrics) {
chordMetrics.glyphs = petalumaChordMetrics;
}
Font.load('Petaluma', PetalumaFont, metrics);
}

0 comments on commit 6cf8770

Please sign in to comment.