Pārlūkot izejas kodu

wrong staffline bounding box: provide workaround for too large canvas (#643)

only a workaround for #643, still needs a fix. couldn't find it so far.
sschmid 5 gadi atpakaļ
vecāks
revīzija
371cb9f063

+ 8 - 1
src/MusicalScore/Graphical/BoundingBox.ts

@@ -3,6 +3,8 @@ import {ArgumentOutOfRangeException} from "../Exceptions";
 import {PointF2D} from "../../Common/DataObjects/PointF2D";
 import {SizeF2D} from "../../Common/DataObjects/SizeF2D";
 import {RectangleF2D} from "../../Common/DataObjects/RectangleF2D";
+import { StaffLineActivitySymbol } from "./StaffLineActivitySymbol";
+import { EngravingRules } from "./EngravingRules";
 
 /**
  * A bounding box delimits an area on the 2D plane.
@@ -367,7 +369,12 @@ export class BoundingBox {
         for (let idx: number = 0, len: number = this.ChildElements.length; idx < len; ++idx) {
             const childElement: BoundingBox = this.ChildElements[idx];
             minTop = Math.min(minTop, childElement.relativePosition.y + childElement.borderTop);
-            maxBottom = Math.max(maxBottom, childElement.relativePosition.y + childElement.borderBottom);
+            if (!EngravingRules.Rules.FixStafflineBoundingBox || !(childElement.dataObject instanceof StaffLineActivitySymbol)) {
+                maxBottom = Math.max(maxBottom, childElement.relativePosition.y + childElement.borderBottom);
+                // TODO there's a problem with the bottom bounding box of many stafflines, often caused by StaffLineActivitySymbol,
+                // often leading to the page SVG canvas being unnecessarily long in y-direction. This seems to be remedied by this workaround.
+                // see #643
+            }
             minMarginTop = Math.min(minMarginTop, childElement.relativePosition.y + childElement.borderMarginTop);
             maxMarginBottom = Math.max(maxMarginBottom, childElement.relativePosition.y + childElement.borderMarginBottom);
         }

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

@@ -215,6 +215,8 @@ export class EngravingRules {
     private fingeringPosition: PlacementEnum;
     private fingeringInsideStafflines: boolean;
 
+    private fixStafflineBoundingBox: boolean; // TODO temporary workaround
+
     constructor() {
         // global variables
         this.samplingUnit = EngravingRules.unit * 3;
@@ -438,6 +440,8 @@ export class EngravingRules {
         this.fingeringPosition = PlacementEnum.Left; // easier to get bounding box, and safer for vertical layout
         this.fingeringInsideStafflines = false;
 
+        this.fixStafflineBoundingBox = false; // TODO temporary workaround
+
         this.populateDictionaries();
         try {
             this.maxInstructionsConstValue = this.ClefLeftMargin + this.ClefRightMargin + this.KeyRightMargin + this.RhythmRightMargin + 11;
@@ -1547,6 +1551,12 @@ export class EngravingRules {
     public set FingeringInsideStafflines(value: boolean) {
         this.fingeringInsideStafflines = value;
     }
+    public set FixStafflineBoundingBox(value: boolean) { // TODO temporary workaround
+        this.fixStafflineBoundingBox = value;
+    }
+    public get FixStafflineBoundingBox(): boolean {
+        return this.fixStafflineBoundingBox;
+    }
 
     /**
      * This method maps NoteDurations to Distances and DistancesScalingFactors.