Browse Source

feat(textlines): Added option for additional spacing between multiline text labels

anita2822 4 năm trước cách đây
mục cha
commit
b5303169be

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

@@ -248,6 +248,7 @@ export class EngravingRules {
     private pageBackgroundColor: string; // vexflow-color-string (#FFFFFF). Default undefined/transparent.
     private renderSingleHorizontalStaffline: boolean;
     private restoreCursorAfterRerender: boolean;
+    private spacingBetweenTextLines: number;
 
     private static fixStafflineBoundingBox: boolean; // TODO temporary workaround
 
@@ -513,6 +514,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 {
@@ -1819,6 +1821,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 resetChordSymbolLabelTexts(chordtexts: Dictionary<ChordSymbolEnum, string>): Dictionary<ChordSymbolEnum, string> {
         chordtexts.setValue(ChordSymbolEnum.minor, "m");

+ 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
     }

+ 5 - 0
src/OpenSheetMusicDisplay/OSMDOptions.ts

@@ -203,6 +203,11 @@ export interface IOSMDOptions {
      *  Setting this is the same as setting osmd.EngravingRules.SoftmaxFactorVexFlow.
      */
     spacingFactorSoftmax?: number;
+
+    /**
+     * Number in pixels, of spacing between multi-line labels
+     */
+    spacingBetweenTextLines?: number;
 }
 
 export enum AlignRestOption {

+ 3 - 0
src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts

@@ -524,6 +524,9 @@ export class OpenSheetMusicDisplay {
         if (options.spacingFactorSoftmax !== undefined) {
             this.rules.SoftmaxFactorVexFlow = options.spacingFactorSoftmax;
         }
+        if (options.spacingBetweenTextLines !== undefined) {
+            this.rules.SpacingBetweenTextLines = options.spacingBetweenTextLines;
+        }
     }
 
     public setColoringMode(options: IOSMDOptions): void {