satie
Version:
A sheet music renderer for the web
153 lines (152 loc) • 6.04 kB
JavaScript
/**
* 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 musicxml_interfaces_1 = require("musicxml-interfaces");
var lodash_1 = require("lodash");
var chai_1 = require("chai");
var private_measureLayout_1 = require("../private_measureLayout");
var etestutil_1 = require("./etestutil");
var implLine_justifyPostprocessor_1 = require("../implLine_justifyPostprocessor");
var engine_processors_measure_1 = require("../engine_processors_measure");
describe("[lineProcessor.ts]", function () {
describe("justify", function () {
it("partially justifies multiple voices and measures on the final line", function () {
var segments = [
{
staves: [null, etestutil_1.createFakeStaffSegment(4, 4, 1)],
voices: [
null,
etestutil_1.createFakeVoiceSegment(2, 6, 1),
etestutil_1.createFakeVoiceSegment(1, 7, 2)
]
},
{
staves: [null, etestutil_1.createFakeStaffSegment(4, 4, 1)],
voices: [
null,
etestutil_1.createFakeVoiceSegment(1, 7, 1),
etestutil_1.createFakeVoiceSegment(2, 6, 2)
]
}
];
var layouts = lodash_1.map(segments, function (seg, idx) { return engine_processors_measure_1.layoutMeasure({
attributes: { "P1": [] },
document: {
__fakeDocument: true
},
preview: false,
print: null,
fixup: null,
measure: {
idx: idx,
number: String(idx + 1),
version: 0,
parts: {
"P1": {
voices: seg.voices,
staves: seg.staves
}
},
uuid: 1248 + idx,
width: NaN
},
header: {
partList: [
{
_class: "ScorePart",
id: "P1"
}
]
},
x: 0,
lineBarOnLine: 0,
lineCount: 1,
lineIndex: 0,
lineShortest: 1,
lineTotalBarsOnLine: 1,
factory: etestutil_1.fakeFactory,
singleLineMode: false,
}); });
var padding = 12;
var detachedLayouts = lodash_1.map(layouts, private_measureLayout_1.detach);
lodash_1.forEach(detachedLayouts, function (layout) {
layout.attributes = {
P1: [, {
divisions: 4,
time: {
beats: ["4"],
beatTypes: [4]
}
}]
};
});
var justified = implLine_justifyPostprocessor_1.default({
document: {
__fakeDocument: true
},
preview: false,
fixup: null,
attributes: {},
lineCount: 1,
lineIndex: 0,
measures: new Array(2),
header: {
partList: [
{
_class: "ScorePart",
id: "P1"
}
]
},
print: {
pageLayout: {
pageHeight: 1000,
pageWidth: 1000,
pageMargins: [{
leftMargin: padding,
rightMargin: padding,
bottomMargin: padding,
topMargin: padding,
type: musicxml_interfaces_1.OddEvenBoth.Both
}]
}
},
modelFactory: etestutil_1.fakeFactory,
preprocessors: [],
postprocessors: [implLine_justifyPostprocessor_1.default],
singleLineMode: false,
}, {
left: 12,
right: 1000 - 12,
systemLayout: null,
top: 0,
}, detachedLayouts);
var expectedWidth = justified[0].elements[0][4].x -
justified[0].elements[0][0].x + 10;
chai_1.expect(justified[0].elements[0][0].x).to.be.closeTo(layouts[0].elements[0][0].x, 0.05);
chai_1.expect(justified[0].elements[0][2].x).to.be.closeTo(24.16, 0.1);
chai_1.expect(justified[0].width).to.be.closeTo(expectedWidth, 0.01);
lodash_1.forEach(justified, function (just, idx) {
chai_1.expect(just.width).to.not.equal(layouts[idx].width);
});
});
});
});