Browse Source

fix(Transparency): ledger lines of invisible notes are now invisible as well. (#799)

sschmid 4 years ago
parent
commit
d73e8acddf

+ 1 - 1
src/MusicalScore/Graphical/EngravingRules.ts

@@ -422,7 +422,7 @@ export class EngravingRules {
 
         // Line Widths
         this.staffLineWidth = 0.12;
-        this.ledgerLineWidth = undefined; // if not undefined, the vexflow default will be overwritten
+        this.ledgerLineWidth = 1; // vexflow units (pixels). if not undefined, the vexflow default will be overwritten
         this.ledgerLineStrokeStyle = undefined; // if not undefined, the vexflow default will be overwritten
         this.wedgeLineWidth = 0.12;
         this.tupletLineWidth = 0.12;

+ 2 - 0
src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts

@@ -287,6 +287,8 @@ export class VexFlowConverter {
             vfnote = new Vex.Flow.StaveNote(vfnoteStruct);
         }
         if (rules.LedgerLineWidth || rules.LedgerLineStrokeStyle) {
+            // FIXME should probably use vfnote.setLedgerLineStyle. this doesn't seem to do anything.
+            // however, this is also set in VexFlowVoiceEntry.color() anyways.
             if (!((vfnote as any).ledgerLineStyle)) {
                 (vfnote as any).ledgerLineStyle = {};
             }

+ 12 - 0
src/MusicalScore/Graphical/VexFlow/VexFlowVoiceEntry.ts

@@ -120,6 +120,18 @@ export class VexFlowVoiceEntry extends GraphicalVoiceEntry {
                         notehead.setStyle({ fillStyle: noteheadColor, strokeStyle: noteheadColor });
                     }
                 }
+                // set ledger line color. TODO coordinate this with VexFlowConverter.StaveNote(), where there's also still code for this, maybe unnecessarily.
+                if (noteheadColor === transparentColor) {
+                    (vfStaveNote as any).setLedgerLineStyle({ fillStyle: noteheadColor, strokeStyle: noteheadColor, lineWidth: this.rules.LedgerLineWidth });
+                } else {
+                    (vfStaveNote as any).setLedgerLineStyle({
+                        fillStyle: this.rules.DefaultColorNotehead,
+                        lineWidth: this.rules.LedgerLineWidth,
+                        strokeStyle: this.rules.DefaultColorNotehead
+                    });
+                    // we could give the color (style) as noteheadColor, but then we need to figure out which note has the ledger line.
+                    // otherwise ledger lines get the color of the top note, see Function Test Color.
+                }
             }
         }