Browse Source

feat(Options): new option spacingBetweenTextLines for spacing in multiline labels like composers (#835) (merge 'experiment/refactor')

refactor: rename options.StretchLastSystemLine to options.stretchLastSystemLine (consistency) (#842)

Merge branch 'experiment/refactor' into develop

# Conflicts:
#	src/MusicalScore/Graphical/EngravingRules.ts
#	src/OpenSheetMusicDisplay/OSMDOptions.ts
#	src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts
sschmid 5 năm trước cách đây
mục cha
commit
d578432f95

+ 8 - 0
src/MusicalScore/Graphical/EngravingRules.ts

@@ -251,6 +251,7 @@ export class EngravingRules {
     private renderSingleHorizontalStaffline: boolean;
     private restoreCursorAfterRerender: boolean;
     private stretchLastSystemLine: boolean;
+    private spacingBetweenTextLines: number;
 
     private static fixStafflineBoundingBox: boolean; // TODO temporary workaround
 
@@ -518,6 +519,7 @@ export class EngravingRules {
         this.pageFormat = PageFormat.UndefinedPageFormat; // default: undefined / 'infinite' height page, using the canvas'/container's width and height
         this.pageBackgroundColor = undefined; // default: transparent. half-transparent white: #FFFFFF88"
         this.renderSingleHorizontalStaffline = false;
+        this.spacingBetweenTextLines = 0;
 
         this.populateDictionaries();
         try {
@@ -1830,6 +1832,12 @@ export class EngravingRules {
     public set RestoreCursorAfterRerender(value: boolean) {
         this.restoreCursorAfterRerender = value;
     }
+    public get SpacingBetweenTextLines(): number {
+        return this.spacingBetweenTextLines;
+    }
+    public set SpacingBetweenTextLines(value: number) {
+        this.spacingBetweenTextLines = value;
+    }
     public get StretchLastSystemLine(): boolean {
         return this.stretchLastSystemLine;
     }

+ 4 - 1
src/MusicalScore/Graphical/GraphicalLabel.ts

@@ -83,7 +83,10 @@ export class GraphicalLabel extends Clickable {
             line.xOffset = xOffset;
         }
 
-        const height: number = this.Label.fontHeight * numOfLines;
+        let height: number = this.Label.fontHeight * numOfLines;
+        if (this.rules.SpacingBetweenTextLines > 0 && this.TextLines.length > 1) {
+            height += (this.rules.SpacingBetweenTextLines * numOfLines) / 10;
+        }
         const bbox: BoundingBox = this.PositionAndShape;
 
         switch (this.Label.textAlignment) {

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

@@ -425,6 +425,9 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
             const linePosition: PointF2D = new PointF2D(screenPosition.x + xOffsetInPixel, screenPosition.y);
             this.backend.renderText(height, fontStyle, font, currLine.text, fontHeightInPixel, linePosition, color, graphicalLabel.Label.fontFamily);
             screenPosition.y = screenPosition.y + fontHeightInPixel;
+            if (graphicalLabel.TextLines.length > 1) {
+             screenPosition.y += this.rules.SpacingBetweenTextLines;
+            }
         }
         // font currently unused, replaced by fontFamily
     }

+ 6 - 2
src/OpenSheetMusicDisplay/OSMDOptions.ts

@@ -94,7 +94,7 @@ export interface IOSMDOptions {
     measureNumberInterval?: number;
     /** Whether to draw fingerings (only left to the note for now). Default true (unless solo part). */
     drawFingerings?: boolean;
-    /** Where to draw fingerings (left, right, above, below, auto).
+    /** Where to draw fingerings (left, right, above, below, or auto).
      * Default left. Auto, above, below experimental (potential collisions because bounding box not correct)
      */
     fingeringPosition?: string;
@@ -204,9 +204,13 @@ export interface IOSMDOptions {
      */
     spacingFactorSoftmax?: number;
     /**
+     * Number in pixels, of spacing between multi-line labels
+     */
+    spacingBetweenTextLines?: number;
+    /**
      * Set to true if the last system line should be streched across the whole page just as the other systems. Default is false
      */
-    StretchLastSystemLine?: boolean;
+    stretchLastSystemLine?: boolean;
 }
 
 export enum AlignRestOption {

+ 5 - 2
src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts

@@ -524,8 +524,11 @@ export class OpenSheetMusicDisplay {
         if (options.spacingFactorSoftmax !== undefined) {
             this.rules.SoftmaxFactorVexFlow = options.spacingFactorSoftmax;
         }
-        if (options.StretchLastSystemLine !== undefined) {
-            this.rules.StretchLastSystemLine = options.StretchLastSystemLine;
+        if (options.spacingBetweenTextLines !== undefined) {
+            this.rules.SpacingBetweenTextLines = options.spacingBetweenTextLines;
+        }
+        if (options.stretchLastSystemLine !== undefined) {
+            this.rules.StretchLastSystemLine = options.stretchLastSystemLine;
         }
     }