瀏覽代碼

PageFormat: add idString attribute (e.g. "A4_L"), Equals method

sschmid 5 年之前
父節點
當前提交
303f11a17f
共有 2 個文件被更改,包括 23 次插入12 次删除
  1. 10 1
      src/MusicalScore/Graphical/EngravingRules.ts
  2. 13 11
      src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts

+ 10 - 1
src/MusicalScore/Graphical/EngravingRules.ts

@@ -1632,12 +1632,14 @@ export class EngravingRules {
 
 // TODO maybe this should be moved to OSMDOptions. Also see OpenSheetMusicDisplay.PageFormatStandards
 export class PageFormat {
-    constructor(width: number, height: number) {
+    constructor(width: number, height: number, idString: string = "noIdStringGiven") {
         this.width = width;
         this.height = height;
+        this.idString = idString;
     }
     public width: number;
     public height: number;
+    public idString: string;
     public get aspectRatio(): number {
         if (!this.IsUndefined) {
             return this.width / this.height;
@@ -1653,4 +1655,11 @@ export class PageFormat {
     public static get UndefinedPageFormat(): PageFormat {
         return new PageFormat(0, 0);
     }
+
+    public Equals(otherPageFormat: PageFormat): boolean {
+        if (!otherPageFormat) {
+            return false;
+        }
+        return otherPageFormat.width === this.width && otherPageFormat.height === this.height;
+    }
 }

+ 13 - 11
src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts

@@ -626,17 +626,17 @@ export class OpenSheetMusicDisplay {
 
     /** Standard page format options like A4 or Letter, in portrait and landscape. E.g. PageFormatStandards["A4_P"] or PageFormatStandards["Letter_L"]. */
     public static PageFormatStandards: {[type: string]: PageFormat} = {
-        "A3_L": new PageFormat(420, 297), // id strings should use underscores instead of white spaces to facilitate use as URL parameters.
-        "A3_P": new PageFormat(297, 420),
-        "A4_L": new PageFormat(297, 210),
-        "A4_P": new PageFormat(210, 297),
-        "A5_L": new PageFormat(210, 148),
-        "A5_P": new PageFormat(148, 210),
-        "A6_L": new PageFormat(148, 105),
-        "A6_P": new PageFormat(105, 148),
+        "A3_L": new PageFormat(420, 297, "A3_L"), // id strings should use underscores instead of white spaces to facilitate use as URL parameters.
+        "A3_P": new PageFormat(297, 420, "A3_P"),
+        "A4_L": new PageFormat(297, 210, "A4_L"),
+        "A4_P": new PageFormat(210, 297, "A4_P"),
+        "A5_L": new PageFormat(210, 148, "A5_L"),
+        "A5_P": new PageFormat(148, 210, "A5_P"),
+        "A6_L": new PageFormat(148, 105, "A6_L"),
+        "A6_P": new PageFormat(105, 148, "A6_P"),
         "Endless": PageFormat.UndefinedPageFormat,
-        "Letter_L": new PageFormat(279.4, 215.9),
-        "Letter_P": new PageFormat(215.9, 279.4)
+        "Letter_L": new PageFormat(279.4, 215.9, "Letter_L"),
+        "Letter_P": new PageFormat(215.9, 279.4, "Letter_P")
     };
 
     public static StringToPageFormat(formatId: string): PageFormat {
@@ -653,7 +653,9 @@ export class OpenSheetMusicDisplay {
 
     /** Sets page format by string. Alternative to setOptions({pageFormat: PageFormatStandards.Endless}) for example. */
     public setPageFormat(formatId: string): void {
-        EngravingRules.Rules.PageFormat = OpenSheetMusicDisplay.StringToPageFormat(formatId);
+        const newPageFormat: PageFormat = OpenSheetMusicDisplay.StringToPageFormat(formatId);
+        this.needBackendUpdate = !(newPageFormat.Equals(EngravingRules.Rules.PageFormat));
+        EngravingRules.Rules.PageFormat = newPageFormat;
     }
 
     public setCustomPageFormat(width: number, height: number): void {