Explorar o código

test: fix BoundingBoxes not drawable in generateImages, add StaffEntry bbox setting (#872)

sschmid %!s(int64=4) %!d(string=hai) anos
pai
achega
c4f7771874

+ 28 - 2
src/MusicalScore/Graphical/MusicSheetDrawer.ts

@@ -25,6 +25,8 @@ import {MusicSymbolDrawingStyle, PhonicScoreModes} from "./DrawingMode";
 import {GraphicalObject} from "./GraphicalObject";
 import { GraphicalInstantaneousDynamicExpression } from "./GraphicalInstantaneousDynamicExpression";
 import { GraphicalContinuousDynamicExpression } from "./GraphicalContinuousDynamicExpression";
+import { VexFlowContinuousDynamicExpression, VexFlowGraphicalNote, VexFlowMeasure, VexFlowStaffEntry, VexFlowStaffLine, VexFlowVoiceEntry } from "./VexFlow";
+import { StaffLineActivitySymbol } from "./StaffLineActivitySymbol";
 // import { FontStyles } from "../../Common/Enums/FontStyles";
 
 /**
@@ -503,8 +505,32 @@ export abstract class MusicSheetDrawer {
      * @param type Type of element to show bounding boxes for as string.
      */
     private drawBoundingBoxes(startBox: BoundingBox, layer: number = 0, type: string = "all"): void {
-        const dataObjectString: string = (startBox.DataObject.constructor as any).name;
-        if (dataObjectString === type || type === "all") {
+        const dataObjectString: string = (startBox.DataObject.constructor as any).name; // only works with non-minified build or sourcemap
+        let typeMatch: boolean = false;
+        if (type === "all") {
+            typeMatch = true;
+        } else {
+            if (type === "VexFlowStaffEntry") {
+                typeMatch = startBox.DataObject instanceof VexFlowStaffEntry;
+            } else if (type === "VexFlowMeasure") {
+                typeMatch = startBox.DataObject instanceof VexFlowMeasure;
+            } else if (type === "VexFlowGraphicalNote") {
+                typeMatch = startBox.DataObject instanceof VexFlowGraphicalNote;
+            } else if (type === "VexFlowVoiceEntry") {
+                typeMatch = startBox.DataObject instanceof VexFlowVoiceEntry;
+            } else if (type === "GraphicalLabel") {
+                typeMatch = startBox.DataObject instanceof GraphicalLabel;
+            } else if (type === "VexFlowStaffLine") {
+                typeMatch = startBox.DataObject instanceof VexFlowStaffLine;
+            } else if (type === "SystemLine") {
+                typeMatch = startBox.DataObject instanceof SystemLine;
+            } else if (type === "StaffLineActivitySymbol") {
+                typeMatch = startBox.DataObject instanceof StaffLineActivitySymbol;
+            } else if (type === "VexFlowContinuousDynamicExpression") {
+                typeMatch = startBox.DataObject instanceof VexFlowContinuousDynamicExpression;
+            }
+        }
+        if (typeMatch || dataObjectString === type) {
             let tmpRect: RectangleF2D = new RectangleF2D(startBox.AbsolutePosition.x + startBox.BorderMarginLeft,
                                                          startBox.AbsolutePosition.y + startBox.BorderMarginTop,
                                                          startBox.BorderMarginRight - startBox.BorderMarginLeft,

+ 3 - 0
test/Util/generateImages_browserless.js

@@ -262,6 +262,7 @@ async function generateSampleImage (sampleFilename, directory, osmdInstance, osm
         const isFunctionTestDrawingRange = sampleFilename.startsWith("OSMD_function_test_measuresToDraw_");
         const defaultOrCompactTightMode = sampleFilename.startsWith("OSMD_Function_Test_Container_height") ? "compacttight" : "default";
         const isTestFlatBeams = sampleFilename.startsWith("test_drum_tuplet_beams");
+        const isTestEndClefStaffEntryBboxes = sampleFilename.startsWith("test_end_measure_clefs_staffentry_bbox");
         osmdInstance.setOptions({
             autoBeam: isFunctionTestAutobeam, // only set to true for function test autobeam
             coloringMode: isFunctionTestAutoColoring ? 2 : 0,
@@ -278,6 +279,8 @@ async function generateSampleImage (sampleFilename, directory, osmdInstance, osm
         });
         osmdInstance.drawSkyLine = includeSkyBottomLine; // if includeSkyBottomLine, draw skyline and bottomline, else not
         osmdInstance.drawBottomLine = includeSkyBottomLine;
+        const drawBoundingBoxValue = isTestEndClefStaffEntryBboxes ? "VexFlowStaffEntry" : undefined;
+        osmdInstance.setDrawBoundingBox(drawBoundingBoxValue, false); // false: don't render (now)
         if (isTestFlatBeams) {
             osmdInstance.EngravingRules.FlatBeams = true;
             // osmdInstance.EngravingRules.FlatBeamOffset = 30;