From cbc01173834f26bf0fda83af91cb23de0dcdfffd Mon Sep 17 00:00:00 2001 From: Benjamin Bloomfield Date: Thu, 28 Jul 2016 12:41:05 -0400 Subject: [PATCH] Added function to make an svg for each chant system rather than a single svg comprising all systems, for use when printing --- src/Exsurge.Chant.ChantLine.js | 4 ++-- src/Exsurge.Chant.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Exsurge.Chant.ChantLine.js b/src/Exsurge.Chant.ChantLine.js index abbb3c4..fa404b5 100644 --- a/src/Exsurge.Chant.ChantLine.js +++ b/src/Exsurge.Chant.ChantLine.js @@ -226,7 +226,7 @@ export class ChantLine extends ChantLayoutElement { canvasCtxt.translate(-this.bounds.x, -this.bounds.y); } - createSvgFragment(ctxt) { + createSvgFragment(ctxt, top = 0) { var inner = ""; // add the chant lines @@ -291,7 +291,7 @@ export class ChantLine extends ChantLayoutElement { return QuickSvg.createFragment('g', { 'class': 'chantLine', - 'transform': 'translate(' + this.bounds.x + ',' + this.bounds.y + ')' + 'transform': 'translate(' + this.bounds.x + ',' + (this.bounds.y - top) + ')' }, inner); } diff --git a/src/Exsurge.Chant.js b/src/Exsurge.Chant.js index 0fff14a..819fd40 100644 --- a/src/Exsurge.Chant.js +++ b/src/Exsurge.Chant.js @@ -592,6 +592,36 @@ export class ChantScore { return fragment; } + createSvgForEachLine(ctxt) { + + var fragment = "", + fragmentDefs = ""; + + // create defs section + for (var def in ctxt.defs) + if (ctxt.defs.hasOwnProperty(def)) + fragmentDefs += ctxt.defs[def]; + + fragmentDefs = QuickSvg.createFragment('defs', {}, fragmentDefs); + var top = 0; + for (var i = 0; i < this.lines.length; i++) { + var lineFragment = fragmentDefs + this.lines[i].createSvgFragment(ctxt, top); + var height = this.lines[i].bounds.height + ctxt.staffInterval * 1.5; + lineFragment = QuickSvg.createFragment('g', {}, lineFragment); + lineFragment = QuickSvg.createFragment('svg', { + 'xmlns': 'http://www.w3.org/2000/svg', + 'version': '1.1', + 'xmlns:xlink': 'http://www.w3.org/1999/xlink', + 'class': 'ChantScore', + 'width': this.bounds.width, + 'height': height + }, lineFragment); + fragment += lineFragment; + top += height; + } + return fragment; + } + unserializeFromJson(data) { this.autoColoring = data['auto-coloring'];