|
|
|
|
|
|
|
|
|
|
|
|
|
|
var spacing = require('./helpers/spacing'); |
|
|
var Svg = require('./svg'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var Renderer = function (paper) { |
|
|
this.paper = new Svg(paper); |
|
|
this.controller = null; |
|
|
|
|
|
this.space = 3 * spacing.SPACE; |
|
|
this.padding = {}; |
|
|
this.reset(); |
|
|
this.firefox112 = navigator.userAgent.indexOf('Firefox/112.0') >= 0 |
|
|
}; |
|
|
|
|
|
Renderer.prototype.reset = function () { |
|
|
|
|
|
this.paper.clear(); |
|
|
this.y = 0; |
|
|
this.abctune = null; |
|
|
this.path = null; |
|
|
this.isPrint = false; |
|
|
this.lineThickness = 0; |
|
|
this.initVerticalSpace(); |
|
|
}; |
|
|
|
|
|
Renderer.prototype.newTune = function (abcTune) { |
|
|
this.abctune = abcTune; |
|
|
this.setVerticalSpace(abcTune.formatting); |
|
|
|
|
|
|
|
|
this.isPrint = abcTune.media === 'print'; |
|
|
this.setPadding(abcTune); |
|
|
}; |
|
|
|
|
|
Renderer.prototype.setLineThickness = function (lineThickness) { |
|
|
this.lineThickness = lineThickness |
|
|
}; |
|
|
|
|
|
Renderer.prototype.setPaddingOverride = function (params) { |
|
|
this.paddingOverride = { |
|
|
top: params.paddingtop, bottom: params.paddingbottom, |
|
|
right: params.paddingright, left: params.paddingleft |
|
|
}; |
|
|
}; |
|
|
|
|
|
Renderer.prototype.setPadding = function (abctune) { |
|
|
|
|
|
|
|
|
|
|
|
function setPaddingVariable(self, paddingKey, formattingKey, printDefault, screenDefault) { |
|
|
if (abctune.formatting[formattingKey] !== undefined) |
|
|
self.padding[paddingKey] = abctune.formatting[formattingKey]; |
|
|
else if (self.paddingOverride[paddingKey] !== undefined) |
|
|
self.padding[paddingKey] = self.paddingOverride[paddingKey]; |
|
|
else if (self.isPrint) |
|
|
self.padding[paddingKey] = printDefault; |
|
|
else |
|
|
self.padding[paddingKey] = screenDefault; |
|
|
} |
|
|
|
|
|
|
|
|
setPaddingVariable(this, 'top', 'topmargin', 38, 15); |
|
|
setPaddingVariable(this, 'bottom', 'botmargin', 38, 15); |
|
|
setPaddingVariable(this, 'left', 'leftmargin', 68, 15); |
|
|
setPaddingVariable(this, 'right', 'rightmargin', 68, 15); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Renderer.prototype.adjustNonScaledItems = function (scale) { |
|
|
this.padding.top /= scale; |
|
|
this.padding.bottom /= scale; |
|
|
this.padding.left /= scale; |
|
|
this.padding.right /= scale; |
|
|
this.abctune.formatting.headerfont.size /= scale; |
|
|
this.abctune.formatting.footerfont.size /= scale; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Renderer.prototype.initVerticalSpace = function () { |
|
|
|
|
|
|
|
|
this.spacing = { |
|
|
composer: 7.56, |
|
|
graceBefore: 8.67, |
|
|
graceInside: 10.67, |
|
|
graceAfter: 16, |
|
|
info: 0, |
|
|
lineSkipFactor: 1.1, |
|
|
music: 7.56, |
|
|
paragraphSkipFactor: 0.4, |
|
|
parts: 11.33, |
|
|
slurHeight: 1.0, |
|
|
staffSeparation: 61.33, |
|
|
staffTopMargin: 0, |
|
|
stemHeight: 26.67 + 10, |
|
|
subtitle: 3.78, |
|
|
systemStaffSeparation: 48, |
|
|
text: 18.9, |
|
|
title: 7.56, |
|
|
top: 30.24, |
|
|
vocal: 0, |
|
|
words: 0 |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
Renderer.prototype.setVerticalSpace = function (formatting) { |
|
|
|
|
|
if (formatting.staffsep !== undefined) |
|
|
this.spacing.staffSeparation = formatting.staffsep * 4 / 3; |
|
|
if (formatting.composerspace !== undefined) |
|
|
this.spacing.composer = formatting.composerspace * 4 / 3; |
|
|
if (formatting.partsspace !== undefined) |
|
|
this.spacing.parts = formatting.partsspace * 4 / 3; |
|
|
if (formatting.textspace !== undefined) |
|
|
this.spacing.text = formatting.textspace * 4 / 3; |
|
|
if (formatting.musicspace !== undefined) |
|
|
this.spacing.music = formatting.musicspace * 4 / 3; |
|
|
if (formatting.titlespace !== undefined) |
|
|
this.spacing.title = formatting.titlespace * 4 / 3; |
|
|
if (formatting.sysstaffsep !== undefined) |
|
|
this.spacing.systemStaffSeparation = formatting.sysstaffsep * 4 / 3; |
|
|
if (formatting.stafftopmargin !== undefined) |
|
|
this.spacing.staffTopMargin = formatting.stafftopmargin * 4 / 3; |
|
|
if (formatting.subtitlespace !== undefined) |
|
|
this.spacing.subtitle = formatting.subtitlespace * 4 / 3; |
|
|
if (formatting.topspace !== undefined) |
|
|
this.spacing.top = formatting.topspace * 4 / 3; |
|
|
if (formatting.vocalspace !== undefined) |
|
|
this.spacing.vocal = formatting.vocalspace * 4 / 3; |
|
|
if (formatting.wordsspace !== undefined) |
|
|
this.spacing.words = formatting.wordsspace * 4 / 3; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Renderer.prototype.calcY = function (ofs) { |
|
|
return this.y - ofs * spacing.STEP; |
|
|
}; |
|
|
|
|
|
Renderer.prototype.moveY = function (em, numLines) { |
|
|
if (numLines === undefined) numLines = 1; |
|
|
this.y += em * numLines; |
|
|
}; |
|
|
|
|
|
Renderer.prototype.absolutemoveY = function (y) { |
|
|
this.y = y; |
|
|
}; |
|
|
|
|
|
module.exports = Renderer; |
|
|
|