Pārlūkot izejas kodu

feat(Options): add new EngravingRules for notationFontScale, stemWidth, staffLineColor (#836)

with VexFlowDefaultNotationFontScale, all notes and rest notes can be scaled.

close #836
sschmid 4 gadi atpakaļ
vecāks
revīzija
2e1ab25fe0

+ 27 - 2
src/MusicalScore/Graphical/EngravingRules.ts

@@ -160,7 +160,10 @@ export class EngravingRules {
     private moodTextHeight: number;
     private unknownTextHeight: number;
     private continuousTempoTextHeight: number;
+    private vexFlowDefaultNotationFontScale: number;
+    private vexFlowDefaultTabFontScale: number;
     private staffLineWidth: number;
+    private staffLineColor: string;
     private ledgerLineWidth: number;
     private ledgerLineStrokeStyle: string;
     private ledgerLineColorDefault: string;
@@ -325,13 +328,13 @@ export class EngravingRules {
         this.staccatoShorteningFactor = 2;
         this.idealStemLength = 3.0;
         this.stemNoteHeadBorderYOffset = 0.2;
-        this.stemWidth = 0.13;
         this.stemMargin = 0.2;
         this.stemMinLength = 2.5;
         this.stemMaxLength = 4.5;
         this.beamSlopeMaxAngle = 10.0;
         this.stemMinAllowedDistanceBetweenNoteHeadAndBeamLine = 1.0;
         this.setWantedStemDirectionByXml = true;
+        // also see stemwidth further below
 
         // GraceNote Variables
         this.graceNoteScalingFactor = 0.6;
@@ -423,7 +426,11 @@ export class EngravingRules {
         this.dynamicExpressionSpacer = 0.5;
 
         // Line Widths
-        this.staffLineWidth = 0.12;
+        this.vexFlowDefaultNotationFontScale = 39; // scales notes, including rests. default value 39 in Vexflow.
+        this.vexFlowDefaultTabFontScale = 39;
+        this.stemWidth = 0.15; // originally 0.13. vexflow default 0.15. should probably be adjusted when increasing vexFlowDefaultNotationFontScale,
+        this.staffLineWidth = 0.10; // originally 0.12, but this will be pixels in Vexflow (*10).
+        this.staffLineColor = undefined; // if undefined, vexflow default (grey). not a width, but affects visual line clarity.
         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.ledgerLineColorDefault = "#000000"; // black, previously grey by default
@@ -1322,12 +1329,30 @@ export class EngravingRules {
     public set UnknownTextHeight(value: number) {
         this.unknownTextHeight = value;
     }
+    public get VexFlowDefaultNotationFontScale(): number {
+        return this.vexFlowDefaultNotationFontScale;
+    }
+    public set VexFlowDefaultNotationFontScale(value: number) {
+        this.vexFlowDefaultNotationFontScale = value;
+    }
+    public get VexFlowDefaultTabFontScale(): number {
+        return this.vexFlowDefaultTabFontScale;
+    }
+    public set VexFlowDefaultTabFontScale(value: number) {
+        this.vexFlowDefaultTabFontScale = value;
+    }
     public get StaffLineWidth(): number {
         return this.staffLineWidth;
     }
     public set StaffLineWidth(value: number) {
         this.staffLineWidth = value;
     }
+    public get StaffLineColor(): string {
+        return this.staffLineColor;
+    }
+    public set StaffLineColor(value: string) {
+        this.staffLineColor = value;
+    }
     public get LedgerLineWidth(): number {
         return this.ledgerLineWidth;
     }

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

@@ -104,9 +104,11 @@ export class VexFlowMeasure extends GraphicalMeasure {
         // TODO save beginning and end bar type, set these again after new stave.
 
         this.stave = new Vex.Flow.Stave(0, 0, 0, {
+            fill_style: this.rules.StaffLineColor,
             space_above_staff_ln: 0,
             space_below_staff_ln: 0
         });
+        // also see VexFlowMusicSheetDrawer.drawSheet() for some other vexflow default value settings (like default font scale)
 
         if (this.ParentStaff) {
             this.setLineNumber(this.ParentStaff.StafflineCount);

+ 7 - 0
src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetDrawer.ts

@@ -56,6 +56,13 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
             (Vex.Flow as any).DEFAULT_FONT_STACK = [(Vex.Flow as any).Fonts?.Gonville, (Vex.Flow as any).Fonts?.Bravura, (Vex.Flow as any).Fonts?.Custom];
         } // else keep new vexflow default Bravura (more cursive, bold).
 
+        // sizing defaults in Vexflow
+        (Vex.Flow as any).STAVE_LINE_THICKNESS = this.rules.StaffLineWidth * unitInPixels;
+        (Vex.Flow as any).STEM_WIDTH = this.rules.StemWidth * unitInPixels;
+        // sets scale/size of notes/rest notes:
+        (Vex.Flow as any).DEFAULT_NOTATION_FONT_SCALE = this.rules.VexFlowDefaultNotationFontScale; // default 39
+        (Vex.Flow as any).DEFAULT_TAB_FONT_SCALE = this.rules.VexFlowDefaultTabFontScale; // default 39 // TODO doesn't seem to do anything
+
         this.pageIdx = 0;
         for (const graphicalMusicPage of graphicalMusicSheet.MusicPages) {
             const backend: VexFlowBackend = this.backends[this.pageIdx];

+ 1 - 0
src/MusicalScore/Graphical/VexFlow/VexFlowTabMeasure.ts

@@ -29,6 +29,7 @@ export class VexFlowTabMeasure extends VexFlowMeasure {
             space_above_staff_ln: 0,
             space_below_staff_ln: 0,
         });
+        // also see VexFlowMusicSheetDrawer.drawSheet() for some other vexflow default value settings (like default font scale)
         this.updateInstructionWidth();
     }