From dc31a13db8cc4842685bd67b521597bc4598bd68 Mon Sep 17 00:00:00 2001 From: Rodrigo Vilar Date: Sun, 27 Nov 2022 11:42:00 +0100 Subject: [PATCH] custom noteheads refactored --- src/fonts/bravura_metrics.ts | 47 -------------------------------- src/fonts/gonville_metrics.ts | 11 -------- src/fonts/leland_metrics.ts | 41 ---------------------------- src/fonts/petaluma_metrics.ts | 50 ----------------------------------- src/notehead.ts | 16 ++++++++--- 5 files changed, 13 insertions(+), 152 deletions(-) diff --git a/src/fonts/bravura_metrics.ts b/src/fonts/bravura_metrics.ts index 250c957e16..7a86f83938 100644 --- a/src/fonts/bravura_metrics.ts +++ b/src/fonts/bravura_metrics.ts @@ -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: { diff --git a/src/fonts/gonville_metrics.ts b/src/fonts/gonville_metrics.ts index 603055482f..f15c3c5a3b 100644 --- a/src/fonts/gonville_metrics.ts +++ b/src/fonts/gonville_metrics.ts @@ -240,17 +240,6 @@ export const GonvilleMetrics = { }, noteHead: { minPadding: 2, - custom: { - noteheadCircleXStemUp: { - shiftX: -1.5, - }, - noteheadXWholeStemUp: { - shiftX: -5, - }, - noteheadTriangleUpWholeStemUp: { - shiftX: -6, - }, - }, }, chordSymbol: { global: { diff --git a/src/fonts/leland_metrics.ts b/src/fonts/leland_metrics.ts index 80b89445b9..528a9e3c6a 100644 --- a/src/fonts/leland_metrics.ts +++ b/src/fonts/leland_metrics.ts @@ -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: { diff --git a/src/fonts/petaluma_metrics.ts b/src/fonts/petaluma_metrics.ts index 391be5a823..cf8cec009a 100644 --- a/src/fonts/petaluma_metrics.ts +++ b/src/fonts/petaluma_metrics.ts @@ -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: { diff --git a/src/notehead.ts b/src/notehead.ts index 31ec4e32b9..9f27a0e061 100644 --- a/src/notehead.ts +++ b/src/notehead.ts @@ -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 { @@ -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; @@ -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}`, }); } }