UNPKG

satie

Version:

A sheet music renderer for the web

216 lines (215 loc) 8.34 kB
/** * This file is part of Satie music engraver <https://github.com/jnetterf/satie>. * Copyright (C) Joshua Netterfield <joshua.ca> 2015 - present. * * Satie is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * Satie is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Satie. If not, see <http://www.gnu.org/licenses/>. */ "use strict"; /** * @file part of Satie test suite */ var engine_processors_measure_1 = require("../engine_processors_measure"); var engine_processors_layout_1 = require("../engine_processors_layout"); var chai_1 = require("chai"); var document_1 = require("../document"); var engine_divisions_1 = require("../engine_divisions"); var etestutil_1 = require("./etestutil"); describe("[engine/measureProcessor.ts]", function () { describe("reduce", function () { it("can lay out multiple voices", function () { var segments = [ etestutil_1.createFakeStaffSegment(4, 4, 1), etestutil_1.createFakeVoiceSegment(2, 6, 1), etestutil_1.createFakeVoiceSegment(1, 7, 2) // 01111111 ]; segments[0].owner = 1; segments[0].part = "P1"; segments[1].owner = 1; segments[1].part = "P1"; segments[2].owner = 2; segments[2].part = "P1"; engine_divisions_1.normalizeDivisionsInPlace(etestutil_1.fakeFactory, segments); // test without alignment var opts = { document: { __fakeDocument: true }, preview: false, print: null, fixup: null, lineBarOnLine: 0, lineCount: 1, lineIndex: 0, lineShortest: 1, lineTotalBarsOnLine: 1, header: null, measure: { idx: 0, uuid: 777, number: "1", parts: {}, version: 0, }, measureX: 100, segments: segments, noAlign: true, factory: etestutil_1.fakeFactory, mode: engine_processors_measure_1.RefreshMode.RefreshLayout, attributes: { "P1": [] }, singleLineMode: false, }; var layout = engine_processors_measure_1.refreshMeasure(opts).elements; chai_1.expect(layout[0].length).to.equal(2); chai_1.expect(layout[0][0].x).to.equal(100, "without merging"); // Occurs after division 1 or 2, so add the end of the measure chai_1.expect(layout[0][1].x).to.equal(190, "without merging"); chai_1.expect(layout[2].length).to.equal(2); chai_1.expect(layout[2][0].x).to.equal(110, "without merging"); // + 10 for staff chai_1.expect(layout[2][1].x).to.equal(120, "without merging"); chai_1.expect(layout[1].length).to.equal(2); chai_1.expect(layout[1][0].x).to.equal(110, "without merging"); chai_1.expect(layout[1][1].x).to.equal(130, "without merging"); // Now test opts.noAlign = false; layout = engine_processors_measure_1.refreshMeasure(opts).elements; layout[1].map(function (l) { return delete l.key; }); chai_1.expect(layout[1]).to.deep.equal([ { division: 0, x: 100, model: null, renderClass: document_1.Type.Attributes }, { boundingBoxes: [], division: 0, expandPolicy: "after", x: 110, part: "P1", model: segments[1][0], renderClass: document_1.Type.Chord }, { division: 1, expandPolicy: "after", x: 120, model: null, renderClass: document_1.Type.Chord }, { boundingBoxes: [], expandPolicy: "after", division: 2, x: 130, part: "P1", model: segments[1][1], renderClass: document_1.Type.Chord }, { division: 4, x: 190, model: null, renderClass: document_1.Type.Attributes }, ]); }); }); describe("layoutMeasure", function () { it("lays out a case with multiple voices", function () { var staffSegments = [ null, etestutil_1.createFakeStaffSegment(4, 4, 1) ]; var voiceSegments = [ null, etestutil_1.createFakeVoiceSegment(2, 6, 1), etestutil_1.createFakeVoiceSegment(1, 7, 2) ]; var layout = engine_processors_measure_1.layoutMeasure({ document: { __fakeDocument: true }, preview: false, print: null, fixup: null, header: { partList: [ { _class: "ScorePart", id: "P1" } ] }, measure: { idx: 0, number: "1", version: 0, parts: { "P1": { voices: voiceSegments, staves: staffSegments } }, uuid: 248, width: NaN }, x: 100, lineBarOnLine: 0, lineTotalBarsOnLine: 0, lineShortest: 42, lineCount: 1, lineIndex: 0, factory: etestutil_1.fakeFactory, attributes: { "P1": [] }, singleLineMode: false, }); // We've tested this exact case in ISegment.layout$, so we can be // a bit soft here. chai_1.expect(layout.paddingBottom).to.deep.equal([, 0]); chai_1.expect(layout.paddingTop).to.deep.equal([, 0]); chai_1.expect(layout.elements[0].length).to.equal(5); chai_1.expect(layout.elements[0][4].x).to.equal(190); chai_1.expect(layout.elements[0][0].x).to.equal(100); chai_1.expect(layout.width).to.equal(100); }); }); describe("approximateWidth", function () { it("approximates mid-line width", function () { var staffSegments = [ null, etestutil_1.createFakeStaffSegment(4, 4, 1) ]; var voiceSegments = [ null, etestutil_1.createFakeVoiceSegment(2, 6, 1), etestutil_1.createFakeVoiceSegment(1, 7, 2) ]; var width = engine_processors_layout_1.getApproximateMeasureWidth({ idx: 0, number: "1", version: 0, parts: { "P1": { voices: voiceSegments, staves: staffSegments } }, uuid: 1248, width: NaN }, 42); // 100 - 10 for attribute 1. See createFakeStaffSegment chai_1.expect(width).to.equal(90); }); }); });