Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-introduce font-specific formatting to chord symbol metrics #1569

Merged
merged 3 commits into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 14 additions & 0 deletions src/fonts/common_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,71 +26,85 @@ export const CommonMetrics = {
},
glyphs: {
csymDiminished: {
scale: 0.8,
leftSideBearing: -32,
advanceWidth: 506,
yOffset: 0,
},
csymHalfDiminished: {
scale: 0.8,
leftSideBearing: -32,
advanceWidth: 506,
yOffset: 0,
},
csymAugmented: {
scale: 0.8,
leftSideBearing: 0,
advanceWidth: 530,
yOffset: 0,
},
csymParensLeftTall: {
scale: 0.8,
leftSideBearing: -20,
advanceWidth: 184,
yOffset: 250,
},
csymParensRightTall: {
scale: 0.8,
leftSideBearing: 0,
advanceWidth: 189,
yOffset: 250,
},
csymBracketLeftTall: {
scale: 0.8,
leftSideBearing: 0,
advanceWidth: 328,
yOffset: 0,
},
csymBracketRightTall: {
scale: 0.8,
leftSideBearing: 1,
advanceWidth: 600,
yOffset: 0,
},
csymParensLeftVeryTall: {
scale: 0.8,
leftSideBearing: 50,
advanceWidth: 121,
yOffset: 350,
},
csymParensRightVeryTall: {
scale: 0.8,
leftSideBearing: 0,
advanceWidth: 111,
yOffset: 350,
},
csymDiagonalArrangementSlash: {
scale: 0.8,
leftSideBearing: 250,
advanceWidth: 990,
yOffset: 300,
},
csymMinor: {
scale: 0.8,
leftSideBearing: 0,
advanceWidth: 482,
yOffset: 0,
},
csymMajorSeventh: {
scale: 0.8,
leftSideBearing: 200,
yOffset: 0,
advanceWidth: 600,
},
accidentalSharp: {
scale: 0.8,
leftSideBearing: 20,
advanceWidth: 250,
yOffset: -302,
},
accidentalFlat: {
scale: 0.8,
leftSideBearing: -20,
advanceWidth: 226,
yOffset: -184,
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: {
Comment on lines +10 to +16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvilarl is this approach OK with you?

Before, we had a separate metrics file for the petaluma font.

With this PR, it is hard-coded into the load_petaluma.ts file.

I guess this can serve as a way to illustrate how we can customize metrics even though those files no longer exist.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine with me for vexflow4.

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);
}