Pārlūkot izejas kodu

feat(label): Add support for no-print on part names
Don't render part name if no-print attribute = no

Justin Litten 5 gadi atpakaļ
vecāks
revīzija
c3e6c8d878

+ 1 - 0
demo/index.js

@@ -46,6 +46,7 @@ import * as svg2pdf from '../node_modules/svg2pdf.js/dist/svg2pdf.min';
             "OSMD Function Test - High Slur Test": "Slurtest_highNotes.musicxml",
             "Schubert, F. - An Die Musik": "Schubert_An_die_Musik.xml",
             "Actor, L. - Prelude (Large Sample, loading time)": "ActorPreludeSample.xml",
+            "Actor, L. - Prelude (Large, No Print Part Names)": "ActorPreludeSample_PartName.xml",
             "Anonymous - Saltarello": "Saltarello.mxl",
             "Debussy, C. - Mandoline": "Debussy_Mandoline.xml",
             "Levasseur, F. - Parlez Mois": "Parlez-moi.mxl",

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

@@ -33,7 +33,6 @@ export class EngravingRules {
     private titleBottomDistance: number;
     private systemLeftMargin: number;
     private systemRightMargin: number;
-    private firstSystemMargin: number;
     private systemLabelsRightMargin: number;
     private systemComposerDistance: number;
     private instrumentLabelTextHeight: number;
@@ -270,7 +269,6 @@ export class EngravingRules {
         this.betweenStaffLinesDistance = EngravingRules.unit;
         this.systemLeftMargin = 0.0;
         this.systemRightMargin = 0.0;
-        this.firstSystemMargin = 15.0;
         this.systemLabelsRightMargin = 2.0;
         this.systemComposerDistance = 2.0;
         this.instrumentLabelTextHeight = 2;
@@ -621,12 +619,6 @@ export class EngravingRules {
     public set SystemRightMargin(value: number) {
         this.systemRightMargin = value;
     }
-    public get FirstSystemMargin(): number {
-        return this.firstSystemMargin;
-    }
-    public set FirstSystemMargin(value: number) {
-        this.firstSystemMargin = value;
-    }
     public get SystemLabelsRightMargin(): number {
         return this.systemLabelsRightMargin;
     }

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

@@ -1626,7 +1626,7 @@ export abstract class MusicSheetCalculator {
     protected maxInstrNameLabelLength(): number {
         let maxLabelLength: number = 0.0;
         for (const instrument of this.graphicalMusicSheet.ParentMusicSheet.Instruments) {
-            if (instrument.Voices.length > 0 && instrument.Voices[0].Visible) {
+            if (instrument.NameLabel.print && instrument.Voices.length > 0 && instrument.Voices[0].Visible) {
                 let renderedLabel: Label = instrument.NameLabel;
                 if (!this.rules.RenderPartNames) {
                     renderedLabel = new Label("", renderedLabel.textAlignment, renderedLabel.font);

+ 19 - 9
src/MusicalScore/Graphical/MusicSystem.ts

@@ -289,12 +289,14 @@ export abstract class MusicSystem extends GraphicalObject {
      */
     public createMusicSystemLabel(  instrumentLabelTextHeight: number, systemLabelsRightMargin: number,
                                     labelMarginBorderFactor: number, isFirstSystem: boolean = false): void {
+
+        const originalSystemLabelsRightMargin: number = systemLabelsRightMargin;
         for (let idx: number = 0, len: number = this.staffLines.length; idx < len; ++idx) {
             const instrument: Instrument = this.staffLines[idx].ParentStaff.ParentInstrument;
             let instrNameLabel: Label;
             if (isFirstSystem) {
                 instrNameLabel = instrument.NameLabel;
-                if (!this.rules.RenderPartNames) {
+                if (!this.rules.RenderPartNames || !instrNameLabel?.print) {
                     instrNameLabel = new Label("", instrument.NameLabel.textAlignment, instrument.NameLabel.font);
                     systemLabelsRightMargin = 0; // might affect lyricist/tempo placement. but without this there's still some extra x-spacing.
                 }
@@ -310,14 +312,18 @@ export abstract class MusicSystem extends GraphicalObject {
                 // const labelText: string = instrument.NameLabel.text[0] + ".";
                 instrNameLabel = new Label(labelText, instrument.NameLabel.textAlignment, instrument.NameLabel.font);
             }
-            const graphicalLabel: GraphicalLabel = new GraphicalLabel(
-                instrNameLabel, instrumentLabelTextHeight, TextAlignmentEnum.LeftCenter, this.rules, this.boundingBox
-            );
-            graphicalLabel.setLabelPositionAndShapeBorders();
-            this.labels.setValue(instrument, graphicalLabel);
-            // X-Position will be 0 (Label starts at the same PointF_2D with MusicSystem)
-            // Y-Position will be calculated after the y-Spacing
-            // graphicalLabel.PositionAndShape.RelativePosition = new PointF2D(0.0, 0.0);
+            if (instrument?.NameLabel?.print) {
+                const graphicalLabel: GraphicalLabel = new GraphicalLabel(
+                    instrNameLabel, instrumentLabelTextHeight, TextAlignmentEnum.LeftCenter, this.rules, this.boundingBox
+                );
+                graphicalLabel.setLabelPositionAndShapeBorders();
+                this.labels.setValue(instrument, graphicalLabel);
+                // X-Position will be 0 (Label starts at the same PointF_2D with MusicSystem)
+                // Y-Position will be calculated after the y-Spacing
+                // graphicalLabel.PositionAndShape.RelativePosition = new PointF2D(0.0, 0.0);
+            } else {
+                systemLabelsRightMargin = 0;
+            }
         }
 
         // calculate maxLabelLength (needed for X-Spacing)
@@ -325,8 +331,12 @@ export abstract class MusicSystem extends GraphicalObject {
         const labels: GraphicalLabel[] = this.labels.values();
         for (let idx: number = 0, len: number = labels.length; idx < len; ++idx) {
             const label: GraphicalLabel = labels[idx];
+            if (!label.Label.print) {
+                continue;
+            }
             if (label.PositionAndShape.Size.width > this.maxLabelLength) {
                 this.maxLabelLength = label.PositionAndShape.Size.width;
+                systemLabelsRightMargin = originalSystemLabelsRightMargin;
             }
         }
         this.updateMusicSystemStaffLineXPosition(systemLabelsRightMargin);

+ 2 - 8
src/MusicalScore/Graphical/MusicSystemBuilder.ts

@@ -332,14 +332,8 @@ export class MusicSystemBuilder {
             musicSystem.StaffLines.push(staffLine);
             const boundingBox: BoundingBox = staffLine.PositionAndShape;
             const relativePosition: PointF2D = new PointF2D();
-            if (musicSystem === this.musicSystems[0] &&
-                !this.rules.CompactMode) {
-                relativePosition.x = this.rules.FirstSystemMargin;
-                boundingBox.BorderRight = musicSystem.PositionAndShape.Size.width - this.rules.FirstSystemMargin;
-            } else {
-                relativePosition.x = 0.0;
-                boundingBox.BorderRight = musicSystem.PositionAndShape.Size.width;
-            }
+            relativePosition.x = 0.0;
+            boundingBox.BorderRight = musicSystem.PositionAndShape.Size.width;
             relativePosition.y = relativeYPosition;
             boundingBox.RelativePosition = relativePosition;
             boundingBox.BorderLeft = 0.0;

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

@@ -387,6 +387,9 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
      */
     protected renderLabel(graphicalLabel: GraphicalLabel, layer: number, bitmapWidth: number,
                           bitmapHeight: number, heightInPixel: number, screenPosition: PointF2D): void {
+        if (!graphicalLabel.Label.print) {
+            return;
+        }
         const height: number = graphicalLabel.Label.fontHeight * unitInPixels;
         const { font, text } = graphicalLabel.Label;
         let color: string;

+ 3 - 1
src/MusicalScore/Label.ts

@@ -10,14 +10,16 @@ import {FontStyles} from "../Common/Enums/FontStyles";
 export class Label {
 
     constructor(text: string = "", alignment: TextAlignmentEnum = TextAlignmentEnum.CenterBottom,
-                font: Fonts = undefined) {
+                font: Fonts = undefined, print: boolean = true) {
         this.text = text;
+        this.print = print;
         this.textAlignment = alignment;
         this.font = font;
         this.fontFamily = undefined; // default value, will use EngravingRules.DefaultFontFamily at rendering
     }
 
     public text: string;
+    public print: boolean;
     public color: OSMDColor;
     public colorDefault: string; // TODO this is Vexflow format, convert to OSMDColor. for now convenient for default colors.
     public font: Fonts;

+ 4 - 0
src/MusicalScore/ScoreIO/MusicSheetReader.ts

@@ -727,6 +727,10 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
                         try {
                             if (partElement.name === "part-name") {
                                 instrument.Name = partElement.value;
+                                if (partElement.attribute("print-object") &&
+                                   partElement.attribute("print-object").value === "no") {
+                                    instrument.NameLabel.print = false;
+                                }
                             } else if (partElement.name === "part-abbreviation") {
                                 instrument.PartAbbreviation = partElement.value;
                             } else if (partElement.name === "score-instrument") {