Skip to content

Commit

Permalink
Merge pull request #1477 from rvilarl/fix/1415
Browse files Browse the repository at this point in the history
custom noteheads refactored
  • Loading branch information
rvilarl committed Nov 27, 2022
2 parents bcf0f48 + dc31a13 commit 3753602
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 152 deletions.
47 changes: 0 additions & 47 deletions src/fonts/bravura_metrics.ts
Expand Up @@ -316,53 +316,6 @@ export const BravuraMetrics = {
point: 35,
},
},
custom: {
noteheadCircleXStemUp: {
shiftX: 1.5,
},
noteheadCircleXStemDown: {
shiftX: 0.25,
},
noteheadDiamondHalfStemUp: {
shiftX: 1.5,
},
noteheadDiamondBlackStemUp: {
shiftX: 1.5,
},
noteheadDiamondWholeStemUp: {
shiftX: 1,
},
noteheadXHalfStemUp: {
shiftX: -2,
},
noteheadXHalfStemDown: {
shiftX: 1,
},
noteheadXWholeStemUp: {
shiftX: -4,
},
noteheadXWholeStemDown: {
shiftX: 1,
},
noteheadXDoubleWholeStemUp: {
shiftX: -4,
},
noteheadXDoubleWholeStemDown: {
shiftX: 1,
},
noteheadSquareWhiteStemDown: {
shiftX: 0.25,
},
noteheadSquareWhiteStemUp: {
shiftX: -0.75,
},
noteheadSquareBlackStemUp: {
shiftX: -0.75,
},
noteheadTriangleUpWholeStemUp: {
shiftX: -0.75,
},
},
},
chordSymbol: {
global: {
Expand Down
11 changes: 0 additions & 11 deletions src/fonts/gonville_metrics.ts
Expand Up @@ -240,17 +240,6 @@ export const GonvilleMetrics = {
},
noteHead: {
minPadding: 2,
custom: {
noteheadCircleXStemUp: {
shiftX: -1.5,
},
noteheadXWholeStemUp: {
shiftX: -5,
},
noteheadTriangleUpWholeStemUp: {
shiftX: -6,
},
},
},
chordSymbol: {
global: {
Expand Down
41 changes: 0 additions & 41 deletions src/fonts/leland_metrics.ts
Expand Up @@ -312,47 +312,6 @@ export const LelandMetrics = {
point: 35,
},
},
custom: {
noteheadCircleXStemUp: {
shiftX: 1.5,
},
noteheadCircleXStemDown: {
shiftX: 0.25,
},
noteheadDiamondHalfStemUp: {
shiftX: 1.5,
},
noteheadDiamondBlackStemUp: {
shiftX: 1.5,
},
noteheadDiamondWholeStemUp: {
shiftX: 1,
},
noteheadXHalfStemUp: {
shiftX: -2,
},
noteheadXHalfStemDown: {
shiftX: 1,
},
noteheadXWholeStemUp: {
shiftX: -4,
},
noteheadXWholeStemDown: {
shiftX: 1,
},
noteheadSquareWhiteStemDown: {
shiftX: 0.25,
},
noteheadSquareWhiteStemUp: {
shiftX: -0.75,
},
noteheadSquareBlackStemUp: {
shiftX: -0.75,
},
noteheadTriangleUpWholeStemUp: {
shiftX: -0.75,
},
},
},
chordSymbol: {
global: {
Expand Down
50 changes: 0 additions & 50 deletions src/fonts/petaluma_metrics.ts
Expand Up @@ -341,56 +341,6 @@ export const PetalumaMetrics = {
shiftX: 1,
},
},
custom: {
noteheadCircleXStemUp: {
shiftX: -1,
},
noteheadCircleXStemDown: {
shiftX: 0.25,
},
noteheadDiamondHalfStemUp: {
shiftX: 1.5,
},
noteheadDiamondBlackStemUp: {
shiftX: 1.5,
},
noteheadDiamondWholeStemUp: {
shiftX: 1,
},
noteheadXBlackStemUp: {
shiftX: 1,
},
noteheadXHalfStemUp: {
shiftX: -3,
},
noteheadXHalfStemDown: {
shiftX: 1,
},
noteheadXWholeStemUp: {
shiftX: -7,
},
noteheadXWholeStemDown: {
shiftX: 1,
},
noteheadXDoubleWholeStemUp: {
shiftX: -12,
},
noteheadXDoubleWholeStemDown: {
shiftX: -4,
},
noteheadSquareWhiteStemDown: {
shiftX: 0.25,
},
noteheadSquareWhiteStemUp: {
shiftX: -0.75,
},
noteheadSquareBlackStemUp: {
shiftX: -0.75,
},
noteheadTriangleUpWholeStemUp: {
shiftX: -0.75,
},
},
},
chordSymbol: {
global: {
Expand Down
16 changes: 13 additions & 3 deletions src/notehead.ts
Expand Up @@ -155,7 +155,13 @@ export class NoteHead extends Note {
glyph_font_scale: noteStruct.glyph_font_scale || Tables.NOTATION_FONT_SCALE,
};

this.setWidth(this.glyph.getWidth(this.render_options.glyph_font_scale));
this.setWidth(
this.custom_glyph &&
!this.glyph_code.startsWith('noteheadSlashed') &&
!this.glyph_code.startsWith('noteheadCircled')
? Glyph.getWidth(this.glyph_code, this.render_options.glyph_font_scale)
: this.glyph.getWidth(this.render_options.glyph_font_scale)
);
}
/** Get the width of the notehead. */
getWidth(): number {
Expand Down Expand Up @@ -264,7 +270,11 @@ export class NoteHead extends Note {
let head_x = this.getAbsoluteX();
if (this.custom_glyph) {
// head_x += this.x_shift;
head_x += this.stem_direction === Stem.UP ? this.stem_up_x_offset : this.stem_down_x_offset;
head_x +=
this.stem_direction === Stem.UP
? this.stem_up_x_offset +
(this.glyph.stem ? this.glyph.getWidth(this.render_options.glyph_font_scale) - this.width : 0)
: this.stem_down_x_offset;
}

const y = this.y;
Expand All @@ -281,7 +291,7 @@ export class NoteHead extends Note {
drawSlashNoteHead(ctx, this.duration, head_x, y, stem_direction, staveSpace);
} else {
Glyph.renderGlyph(ctx, head_x, y, glyph_font_scale, this.glyph_code, {
category: this.custom_glyph ? `noteHead.custom.${categorySuffix}` : `noteHead.standard.${categorySuffix}`,
category: `noteHead.standard.${categorySuffix}`,
});
}
}
Expand Down

0 comments on commit 3753602

Please sign in to comment.