Browse Source

Add basic copyright rendering (#100)

* Add basic copyright rendering

* Add copyright as a drawing parameter

* Change default of copyright render to false
fredmeister77 2 years ago
parent
commit
0cd4402688

+ 11 - 0
src/MusicalScore/Graphical/DrawingParameters.ts

@@ -36,6 +36,7 @@ export class DrawingParameters {
     public drawSubtitle: boolean = true;
     public drawLyricist: boolean = true;
     public drawComposer: boolean = true;
+    public drawCopyright: boolean = false;
     public drawCredits: boolean = true;
     public drawPartNames: boolean = true;
     public coloringMode: ColoringModes;
@@ -178,6 +179,7 @@ export class DrawingParameters {
         this.DrawTitle = value;
         this.DrawSubtitle = value;
         this.DrawLyricist = value;
+        this.DrawCopyright = value;
     }
     // TODO these drawCredits settings are duplicate in drawingParameters and EngravingRules. Maybe we only need them in EngravingRules.
     // this sets the parameter in DrawingParameters, which in turn sets the parameter in EngravingRules.
@@ -229,6 +231,15 @@ export class DrawingParameters {
         this.rules.RenderLyricist = value;
     }
 
+    public get DrawCopyright(): boolean {
+        return this.drawCopyright;
+    }
+
+    public set DrawCopyright(value: boolean) {
+        this.drawCopyright = value;
+        this.rules.RenderCopyright = value;
+    }
+
     public get DrawPartNames(): boolean {
         return this.drawPartNames;
     }

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

@@ -34,6 +34,8 @@ export class EngravingRules {
     public SheetMinimumDistanceBetweenTitleAndSubtitle: number;
     public SheetComposerHeight: number;
     public SheetAuthorHeight: number;
+    public SheetCopyrightHeight: number;
+    public SheetCopyrightMargin: number;
     public CompactMode: boolean;
     public PagePlacementEnum: PagePlacementEnum;
     public PageHeight: number;
@@ -321,6 +323,7 @@ export class EngravingRules {
     public RenderTitle: boolean;
     public RenderSubtitle: boolean;
     public RenderLyricist: boolean;
+    public RenderCopyright: boolean;
     public RenderPartNames: boolean;
     public RenderPartAbbreviations: boolean;
     public RenderFingerings: boolean;
@@ -426,6 +429,8 @@ export class EngravingRules {
         this.SheetMinimumDistanceBetweenTitleAndSubtitle = 1.0;
         this.SheetComposerHeight = 2.0;
         this.SheetAuthorHeight = 2.0;
+        this.SheetCopyrightHeight = 1.5;
+        this.SheetCopyrightMargin = 2.0;
 
         // Staff sizing Variables
         this.CompactMode = false;
@@ -722,6 +727,7 @@ export class EngravingRules {
         this.RenderTitle = true;
         this.RenderSubtitle = true;
         this.RenderLyricist = true;
+        this.RenderCopyright = false;
         this.RenderPartNames = true;
         this.RenderPartAbbreviations = true;
         this.RenderFingerings = true;

+ 9 - 0
src/MusicalScore/Graphical/GraphicalMusicSheet.ts

@@ -53,6 +53,7 @@ export class GraphicalMusicSheet {
     private subtitle: GraphicalLabel;
     private composer: GraphicalLabel;
     private lyricist: GraphicalLabel;
+    private copyright: GraphicalLabel;
     private cursors: GraphicalLine[] = [];
     private selectionStartSymbol: SelectionStartSymbol;
     private selectionEndSymbol: SelectionEndSymbol;
@@ -129,6 +130,14 @@ export class GraphicalMusicSheet {
         this.lyricist = value;
     }
 
+    public get Copyright(): GraphicalLabel {
+        return this.copyright;
+    }
+
+    public set Copyright(value: GraphicalLabel) {
+        this.copyright = value;
+    }
+
     public get Cursors(): GraphicalLine[] {
         return this.cursors;
     }

+ 24 - 0
src/MusicalScore/Graphical/MusicSheetCalculator.ts

@@ -2052,6 +2052,16 @@ export abstract class MusicSheetCalculator {
         } else if (!this.rules.RenderLyricist) {
             this.graphicalMusicSheet.Lyricist = undefined;
         }
+        if (musicSheet.Copyright !== undefined && this.rules.RenderCopyright) {
+            const copyright: GraphicalLabel = new GraphicalLabel(
+                musicSheet.Copyright, this.rules.SheetCopyrightHeight, TextAlignmentEnum.CenterBottom, this.rules);
+                copyright.Label.IsCreditLabel = true;
+                copyright.Label.colorDefault = defaultColorTitle;
+            this.graphicalMusicSheet.Copyright = copyright;
+            copyright.setLabelPositionAndShapeBorders();
+        } else if (!this.rules.RenderCopyright) {
+            this.graphicalMusicSheet.Copyright = undefined;
+        }
     }
 
     protected checkMeasuresForWholeRestNotes(): void {
@@ -2180,9 +2190,12 @@ export abstract class MusicSheetCalculator {
         // The PositionAndShape child elements of page need to be manually connected to the lyricist, composer, subtitle, etc.
         // because the page is only available now
         let firstSystemAbsoluteTopMargin: number = 10;
+        let lastSystemAbsoluteBottomMargin: number = -1;
         if (page.MusicSystems.length > 0) {
             const firstMusicSystem: MusicSystem = page.MusicSystems[0];
             firstSystemAbsoluteTopMargin = firstMusicSystem.PositionAndShape.RelativePosition.y + firstMusicSystem.PositionAndShape.BorderTop;
+            const lastMusicSystem: MusicSystem = page.MusicSystems[page.MusicSystems.length - 1];
+            lastSystemAbsoluteBottomMargin = lastMusicSystem.PositionAndShape.RelativePosition.y + lastMusicSystem.PositionAndShape.BorderBottom;
         }
         //const firstStaffLine: StaffLine = this.graphicalMusicSheet.MusicPages[0].MusicSystems[0].StaffLines[0];
         if (this.graphicalMusicSheet.Title && this.rules.RenderTitle) {
@@ -2274,6 +2287,17 @@ export abstract class MusicSheetCalculator {
             lyricist.PositionAndShape.RelativePosition = relative;
             page.Labels.push(lyricist);
         }
+        const copyright: GraphicalLabel = this.graphicalMusicSheet.Copyright;
+        if (copyright && this.rules.RenderCopyright) {
+            copyright.PositionAndShape.Parent = page.PositionAndShape;
+            copyright.setLabelPositionAndShapeBorders();
+            const relative: PointF2D = new PointF2D();
+            relative.x = page.PositionAndShape.Size.width / 2;
+            relative.y = lastSystemAbsoluteBottomMargin + this.rules.SheetCopyrightMargin;
+            relative.y -= copyright.PositionAndShape.BorderTop;
+            copyright.PositionAndShape.RelativePosition = relative;
+            page.Labels.push(copyright);
+        }
     }
 
     protected createGraphicalTies(): void {

+ 18 - 0
src/MusicalScore/MusicSheet.ts

@@ -20,6 +20,7 @@ import log from "loglevel";
 import { Dictionary } from "typescript-collections";
 import { PlaybackEntry } from "./Playback/PlaybackEntry";
 import { PlaybackSettings } from "../Common/DataObjects/PlaybackSettings";
+import { TextAlignmentEnum } from "../Common";
 
 // FIXME Andrea: Commented out some unnecessary/not-ported-yet code, have a look at (*)
 
@@ -59,6 +60,7 @@ export class MusicSheet /*implements ISettableMusicSheet, IComparable<MusicSheet
     private subtitle: Label;
     private composer: Label;
     private lyricist: Label;
+    private copyright: Label;
     // private languages: Language[] = [];
     // private activeLanguage: Language;
     private musicPartManager: MusicPartManager = undefined;
@@ -196,6 +198,16 @@ export class MusicSheet /*implements ISettableMusicSheet, IComparable<MusicSheet
     public set LyricistString(value: string) {
         this.Lyricist = new Label(value);
     }
+    public get CopyrightString(): string {
+        if (this.copyright) {
+            return this.copyright.text;
+        } else {
+            return "";
+        }
+    }
+    public set CopyrightString(value: string) {
+        this.Copyright = new Label(value, TextAlignmentEnum.CenterBottom, undefined, true);
+    }
     public get Title(): Label {
         return this.title;
     }
@@ -220,6 +232,12 @@ export class MusicSheet /*implements ISettableMusicSheet, IComparable<MusicSheet
     public set Lyricist(value: Label) {
         this.lyricist = value;
     }
+    public get Copyright(): Label {
+        return this.copyright;
+    }
+    public set Copyright(value: Label) {
+        this.copyright = value;
+    }
     public get Rules(): EngravingRules {
         if (!this.rules) {
             log.debug("warning: sheet.Rules was undefined. Creating new EngravingRules.");

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

@@ -23,6 +23,7 @@ import {RepetitionInstructionReader} from "./MusicSymbolModules/RepetitionInstru
 import {RepetitionCalculator} from "./MusicSymbolModules/RepetitionCalculator";
 import {EngravingRules} from "../Graphical/EngravingRules";
 import { ReaderPluginManager } from "./ReaderPluginManager";
+import { TextAlignmentEnum } from "../../Common";
 
 export class MusicSheetReader /*implements IMusicSheetReader*/ {
 
@@ -510,6 +511,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
     private pushSheetLabels(root: IXmlElement, filePath: string): void {
         this.readComposer(root);
         this.readTitle(root);
+        this.readCopyright(root);
         try {
             if (!this.musicSheet.Title || !this.musicSheet.Composer) {
                 this.readTitleAndComposerFromCredits(root); // this can also throw an error
@@ -560,6 +562,23 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
         }
     }
 
+    private readCopyright(root: IXmlElement): void {
+        const idElements: IXmlElement[] = root.elements("identification");
+        if(idElements.length > 0){
+            const idElement: IXmlElement = idElements[0];
+            const rightElements: IXmlElement[] = idElement.elements("rights");
+            if(rightElements.length > 0){
+                for(let idx: number = 0, len: number = rightElements.length; idx < len; ++idx){
+                    const rightElement: IXmlElement = rightElements[idx];
+                    if(rightElement.value){
+                        this.musicSheet.Copyright = new Label(rightElement.value, TextAlignmentEnum.CenterBottom, undefined, true);
+                        break;
+                    }
+                }
+            }
+        }
+    }
+
     private readTitleAndComposerFromCredits(root: IXmlElement): void {
         const systemYCoordinates: number = this.computeSystemYCoordinates(root);
         if (systemYCoordinates === 0) {