abcjs-rails 1.4 → 1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1184,7 +1184,10 @@ window.ABCJS.parse.Parse = function() {
1184
1184
  var fraction = tokenizer.getFraction(line, i);
1185
1185
  chordDuration = fraction.value;
1186
1186
  i = fraction.index;
1187
- postChordDone = true;
1187
+ if (line.charAt(i) === '-' || line.charAt(i) === ')')
1188
+ i--; // Subtracting one because one is automatically added below
1189
+ else
1190
+ postChordDone = true;
1188
1191
  break;
1189
1192
  default:
1190
1193
  postChordDone = true;
@@ -47,18 +47,18 @@ ABCJS.write.StaffGroupElement.prototype.finished = function() {
47
47
  ABCJS.write.StaffGroupElement.prototype.layout = function(spacing, printer, debug) {
48
48
  this.spacingunits = 0; // number of space units taken up (as opposed to fixed width). Layout engine then decides how many a pixels a space unit should be
49
49
  this.minspace = 1000; // a big number to start off with
50
- var x = printer.paddingleft;
50
+ var x = printer.paddingleft*printer.scale;
51
51
 
52
52
  // find out how much space will be taken up by voice headers
53
53
  var voiceheaderw = 0;
54
54
  for (var i=0;i<this.voices.length;i++) {
55
55
  if(this.voices[i].header) {
56
- var t = printer.paper.text(100, -10, this.voices[i].header).attr({"font-size":12, "font-family":"serif"}); // code duplicated below // don't scale this as we ask for the bbox
56
+ var t = printer.paper.text(100*printer.scale, -10*printer.scale, this.voices[i].header).attr({"font-size":12*printer.scale, "font-family":"serif", 'font-weight':'bold'}); // code duplicated below // don't scale this as we ask for the bbox
57
57
  voiceheaderw = Math.max(voiceheaderw,t.getBBox().width);
58
58
  t.remove();
59
59
  }
60
60
  }
61
- x=x+voiceheaderw*1.1; // 10% of 0 is 0
61
+ x=x+voiceheaderw*(1/printer.scale)*1.1; // 10% of 0 is 0
62
62
  this.startx=x;
63
63
 
64
64
  var currentduration = 0;
@@ -273,7 +273,9 @@ ABCJS.write.VoiceElement.prototype.draw = function (printer, bartop) {
273
273
 
274
274
  if (this.header) { // print voice name
275
275
  var textpitch = 12 - (this.voicenumber+1)*(12/(this.voicetotal+1));
276
- printer.paper.text((this.startx-printer.paddingleft)/2+printer.paddingleft, printer.calcY(textpitch), this.header).attr({"font-size":12, "font-family":"serif"}); // code duplicated above //TODO scale
276
+ var headerX = (this.startx-printer.paddingleft)/2+printer.paddingleft;
277
+ headerX = headerX*printer.scale;
278
+ printer.paper.text(headerX, printer.calcY(textpitch)*printer.scale, this.header).attr({"font-size":12*printer.scale, "font-family":"serif", 'font-weight':'bold'}); // code duplicated above
277
279
  }
278
280
 
279
281
  for (var i=0, ii=this.children.length; i<ii; i++) {
@@ -475,7 +477,7 @@ ABCJS.write.EndingElem.prototype.draw = function (printer, linestartx, lineendx)
475
477
  pathString = ABCJS.write.sprintf("M %f %f L %f %f",
476
478
  linestartx, printer.y, linestartx, printer.y+10);
477
479
  printer.printPath({path:pathString, stroke:"#000000", fill:"#000000"}); //TODO scale
478
- printer.printText(linestartx+5, 18.5, this.text).attr({"font-size":"10px"});
480
+ printer.printText(linestartx+5*printer.scale, 18.5, this.text).attr({"font-size":""+10*printer.scale+"px"});
479
481
  }
480
482
 
481
483
  if (this.anchor2) {
@@ -173,7 +173,7 @@ ABCJS.write.Layout.prototype.printABCElement = function() {
173
173
  break;
174
174
  case "part":
175
175
  var abselem = new ABCJS.write.AbsoluteElement(elem,0,0);
176
- abselem.addChild(new ABCJS.write.RelativeElement(elem.title, 0, 0, 18, {type:"text", attributes:{"font-weight":"bold", "font-size":"16px", "font-family":"serif"}}));
176
+ abselem.addChild(new ABCJS.write.RelativeElement(elem.title, 0, 0, 18, {type:"text", attributes:{"font-weight":"bold", "font-size":""+16*this.printer.scale+"px", "font-family":"serif"}}));
177
177
  elemset[0] = abselem;
178
178
  break;
179
179
  // case "tempo":
@@ -180,10 +180,10 @@ ABCJS.write.Printer.prototype.printStem = function (x, dx, y1, y2) {
180
180
 
181
181
  ABCJS.write.Printer.prototype.printText = function (x, offset, text, anchor) {
182
182
  anchor = anchor || "start";
183
- var ret = this.paper.text(x, this.calcY(offset), text).attr({"text-anchor":anchor, "font-size":12});
184
- if (this.scale!==1) {
185
- ret.scale(this.scale, this.scale, 0, 0);
186
- }
183
+ var ret = this.paper.text(x*this.scale, this.calcY(offset)*this.scale, text).attr({"text-anchor":anchor, "font-size":12*this.scale});
184
+ // if (this.scale!==1) {
185
+ // ret.scale(this.scale, this.scale, 0, 0);
186
+ // }
187
187
  return ret;
188
188
  };
189
189
 
@@ -316,12 +316,13 @@ ABCJS.write.Printer.prototype.printABC = function(abctunes) {
316
316
  };
317
317
 
318
318
  ABCJS.write.Printer.prototype.printTempo = function (tempo, paper, layouter, y, printer, x) {
319
+ var fontStyle = {"text-anchor":"start", 'font-size':12*printer.scale, 'font-weight':'bold'};
319
320
  if (tempo.preString) {
320
- var text = paper.text(x, y + 20, tempo.preString).attr({"text-anchor":"start"});
321
- x += (text.getBBox().width + 10);
321
+ var text = paper.text(x*printer.scale, y*printer.scale + 20*printer.scale, tempo.preString).attr(fontStyle);
322
+ x += (text.getBBox().width + 20*printer.scale);
322
323
  }
323
324
  if (tempo.duration) {
324
- var temposcale = 0.75;
325
+ var temposcale = 0.75*printer.scale;
325
326
  var tempopitch = 14.5;
326
327
  var duration = tempo.duration[0]; // TODO when multiple durations
327
328
  var abselem = new ABCJS.write.AbsoluteElement(tempo, duration, 1);
@@ -346,19 +347,19 @@ ABCJS.write.Printer.prototype.printTempo = function (tempo, paper, layouter, y,
346
347
  var p1 = tempopitch + 1 / 3 * temposcale;
347
348
  var p2 = tempopitch + 7 * temposcale;
348
349
  var dx = temponote.dx + temponote.w;
349
- var width = -0.6;
350
+ var width = -0.6*printer.scale;
350
351
  abselem.addExtra(new ABCJS.write.RelativeElement(null, dx, 0, p1, {"type":"stem", "pitch2":p2, linewidth:width}));
351
352
  }
352
- abselem.x = x;
353
+ abselem.x = x*(1/printer.scale); // TODO-PER: For some reason it scales this element twice, so just compensate.
353
354
  abselem.draw(printer, null);
354
- x += (abselem.w + 5);
355
- text = paper.text(x, y + 20, "= " + tempo.bpm).attr({"text-anchor":"start"});
356
- x += text.getBBox().width + 10;
355
+ x += (abselem.w + 5*printer.scale);
356
+ text = paper.text(x, y*printer.scale + 20*printer.scale, "= " + tempo.bpm).attr(fontStyle);
357
+ x += text.getBBox().width + 10*printer.scale;
357
358
  }
358
359
  if (tempo.postString) {
359
- paper.text(x, y + 20, tempo.postString).attr({"text-anchor":"start"});
360
+ paper.text(x, y*printer.scale + 20*printer.scale, tempo.postString).attr(fontStyle);
360
361
  }
361
- y += 15;
362
+ y += 15*printer.scale;
362
363
  return y;
363
364
  };
364
365
 
@@ -387,22 +388,25 @@ ABCJS.write.Printer.prototype.printTune = function (abctune) {
387
388
  this.width=this.staffwidth;
388
389
  }
389
390
  this.width+=this.paddingleft;
390
- if (abctune.formatting.scale) { this.scale=abctune.formatting.scale; }
391
- this.paper.text(this.width/2, this.y, abctune.metaText.title).attr({"font-size":20, "font-family":"serif"});
392
- this.y+=20;
391
+ if (abctune.formatting.scale) { this.scale=abctune.formatting.scale; } else this.scale = 1;
392
+ this.paper.text(this.width*this.scale/2, this.y, abctune.metaText.title).attr({"font-size":20*this.scale, "font-family":"serif"});
393
+ this.y+=20*this.scale;
393
394
  if (abctune.lines[0] && abctune.lines[0].subtitle) {
394
395
  this.printSubtitleLine(abctune.lines[0]);
395
- this.y+=20;
396
+ this.y+=20*this.scale;
396
397
  }
397
398
  if (abctune.metaText.rhythm) {
398
- this.paper.text(this.paddingleft, this.y, abctune.metaText.rhythm).attr({"text-anchor":"start","font-style":"italic","font-family":"serif", "font-size":12});
399
- !(abctune.metaText.author || abctune.metaText.origin || abctune.metaText.composer) && (this.y+=15);
399
+ this.paper.text(this.paddingleft, this.y, abctune.metaText.rhythm).attr({"text-anchor":"start","font-style":"italic","font-family":"serif", "font-size":12*this.scale});
400
+ !(abctune.metaText.author || abctune.metaText.origin || abctune.metaText.composer) && (this.y+=15*this.scale);
400
401
  }
401
- if (abctune.metaText.author) {this.paper.text(this.width, this.y, abctune.metaText.author).attr({"text-anchor":"end","font-style":"italic","font-family":"serif", "font-size":12}); this.y+=15;}
402
- if (abctune.metaText.origin) {this.paper.text(this.width, this.y, "(" + abctune.metaText.origin + ")").attr({"text-anchor":"end","font-style":"italic","font-family":"serif", "font-size":12});this.y+=15;}
403
- if (abctune.metaText.composer) {this.paper.text(this.width, this.y, abctune.metaText.composer).attr({"text-anchor":"end","font-style":"italic","font-family":"serif", "font-size":12});this.y+=15;}
402
+ var composerLine = "";
403
+ if (abctune.metaText.composer) composerLine += abctune.metaText.composer;
404
+ if (abctune.metaText.origin) composerLine += ' (' + abctune.metaText.origin + ')';
405
+ if (composerLine.length > 0) {this.paper.text(this.width*this.scale, this.y, composerLine).attr({"text-anchor":"end","font-style":"italic","font-family":"serif", "font-size":12*this.scale});this.y+=15;}
406
+ if (abctune.metaText.author) {this.paper.text(this.width*this.scale, this.y, abctune.metaText.author).attr({"text-anchor":"end","font-style":"italic","font-family":"serif", "font-size":12*this.scale}); this.y+=15;}
404
407
  if (abctune.metaText.tempo && !abctune.metaText.tempo.suppress) {
405
408
  this.y = this.printTempo(abctune.metaText.tempo, this.paper, this.layouter, this.y, this, 50);
409
+ this.y += 20*this.scale;
406
410
  }
407
411
  this.staffgroups = [];
408
412
  var maxwidth = this.width;
@@ -430,7 +434,7 @@ ABCJS.write.Printer.prototype.printTune = function (abctune) {
430
434
  this.y+=ABCJS.write.spacing.STAVEHEIGHT*0.2;
431
435
  } else if (abcline.subtitle && line!==0) {
432
436
  this.printSubtitleLine(abcline);
433
- this.y+=20; //hardcoded
437
+ this.y+=20*this.scale; //hardcoded
434
438
  } else if (abcline.text) {
435
439
  if (typeof abcline.text === 'string')
436
440
  this.paper.text(100, this.y, "TEXT: " + abcline.text);
@@ -441,35 +445,41 @@ ABCJS.write.Printer.prototype.printTune = function (abctune) {
441
445
  }
442
446
  this.paper.text(100, this.y, "TEXT: " + str);
443
447
  }
444
- this.y+=20; //hardcoded
448
+ this.y+=20*this.scale; //hardcoded
445
449
  }
446
450
  }
447
- var extraText = ""; // TODO-PER: This is just an easy way to display this info for now.
451
+ var extraText = "";
452
+ var text2;
453
+ var height;
448
454
  if (abctune.metaText.partOrder) extraText += "Part Order: " + abctune.metaText.partOrder + "\n";
449
- if (abctune.metaText.notes) extraText += "Notes:\n" + abctune.metaText.notes + "\n";
450
- if (abctune.metaText.book) extraText += "Book: " + abctune.metaText.book + "\n";
451
- if (abctune.metaText.source) extraText += "Source: " + abctune.metaText.source + "\n";
455
+ if (abctune.metaText.unalignedWords) {
456
+ for (var j = 0; j < abctune.metaText.unalignedWords.length; j++) {
457
+ if (typeof abctune.metaText.unalignedWords[j] === 'string')
458
+ extraText += abctune.metaText.unalignedWords[j] + "\n";
459
+ else {
460
+ for (var k = 0; k < abctune.metaText.unalignedWords[j].length; k++) {
461
+ extraText += " FONT " + abctune.metaText.unalignedWords[j][k].text;
462
+ }
463
+ extraText += "\n";
464
+ }
465
+ }
466
+ text2 = this.paper.text(this.paddingleft*this.scale+50*this.scale, this.y*this.scale+25*this.scale, extraText).attr({"text-anchor":"start", "font-family":"serif", "font-size":17*this.scale});
467
+ height = text2.getBBox().height + 17*this.scale;
468
+ text2.translate(0,height/2);
469
+ this.y+=height;
470
+ extraText = "";
471
+ }
472
+ if (abctune.metaText.book) extraText += "Book: " + abctune.metaText.book + "\n";
473
+ if (abctune.metaText.source) extraText += "Source: " + abctune.metaText.source + "\n";
474
+ if (abctune.metaText.discography) extraText += "Discography: " + abctune.metaText.discography + "\n";
475
+ if (abctune.metaText.notes) extraText += "Notes: " + abctune.metaText.notes + "\n";
452
476
  if (abctune.metaText.transcription) extraText += "Transcription: " + abctune.metaText.transcription + "\n";
453
- if (abctune.metaText.discography) extraText += "Discography: " + abctune.metaText.discography + "\n";
454
477
  if (abctune.metaText.history) extraText += "History: " + abctune.metaText.history + "\n";
455
- if (abctune.metaText.unalignedWords) {
456
- extraText += "Words:\n";
457
- for (var j = 0; j < abctune.metaText.unalignedWords.length; j++) {
458
- if (typeof abctune.metaText.unalignedWords[j] === 'string')
459
- extraText += abctune.metaText.unalignedWords[j] + "\n";
460
- else {
461
- for (var k = 0; k < abctune.metaText.unalignedWords[j].length; k++) {
462
- extraText += " FONT " + abctune.metaText.unalignedWords[j][k].text;
463
- }
464
- extraText += "\n";
465
- }
466
- }
467
- }
468
- var text2 = this.paper.text(this.paddingleft, this.y+25, extraText).attr({"text-anchor":"start", "font-family":"serif", "font-size":13});
469
- var height = text2.getBBox().height;
478
+ text2 = this.paper.text(this.paddingleft, this.y*this.scale+25*this.scale, extraText).attr({"text-anchor":"start", "font-family":"serif", "font-size":17*this.scale});
479
+ height = text2.getBBox().height;
470
480
  text2.translate(0,height/2);
471
- this.y+=25+height;
472
- var sizetoset = {w: maxwidth*this.scale+this.paddingright,h: this.y*this.scale+this.paddingbottom};
481
+ this.y+=25*this.scale+height*this.scale;
482
+ var sizetoset = {w: (maxwidth+this.paddingright)*this.scale,h: this.y+this.paddingbottom*this.scale};
473
483
  this.paper.setSize(sizetoset.w,sizetoset.h);
474
484
  // Correct for IE problem in calculating height
475
485
  var isIE=/*@cc_on!@*/false;//IE detector
@@ -1,5 +1,5 @@
1
1
  module Abcjs
2
2
  module Rails
3
- VERSION = "1.4"
3
+ VERSION = "1.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abcjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.4'
4
+ version: '1.5'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-01 00:00:00.000000000 Z
12
+ date: 2013-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties