Skip to content

Commit

Permalink
Added scaling to renderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiety committed Jan 22, 2012
1 parent c560b86 commit e93fc95
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.rdoc
Expand Up @@ -142,6 +142,7 @@ Here are all optional keys to the second "render options" object:
{
width: 200,
height: 180,
scale: 1, // Scales entire renderer up or down (default 1 - no scaling)
clef: "treble" // or: ["treble", "bass"]
}

Expand Down
6 changes: 6 additions & 0 deletions examples.html
Expand Up @@ -27,6 +27,12 @@ <h2>Simple Chord</h2>
<script type="text/javascript">
render_vexflow("simple-chord", ["C", "E", "G", "Bb"]);
</script>

<h2>Simple Chord Scaled 75%</h2>
<canvas id="simple-chord-scaled" width="200" height="120"></canvas>
<script type="text/javascript">
render_vexflow("simple-chord-scaled", ["C", "E", "G", "Bb"], { scale: 0.75 });
</script>

<h2>Simple Chord with Octaves</h2>
<canvas id="simple-chord-with-octaves" width="600" height="120"></canvas>
Expand Down
16 changes: 12 additions & 4 deletions vexflow.json.js
Expand Up @@ -65,10 +65,16 @@
});
};

Vex.Flow.JSON.prototype.draw_canvas = function(canvas) {
Vex.Flow.JSON.prototype.draw_canvas = function(canvas, canvas_options) {
canvas_options = canvas_options || {};

this.canvas = canvas;
this.renderer = new Vex.Flow.Renderer(this.canvas, Vex.Flow.Renderer.Backends.CANVAS);
this.context = this.renderer.getContext();

if (canvas_options.scale) {
this.context.scale(canvas_options.scale, canvas_options.scale);
}
};

Vex.Flow.JSON.prototype.draw_stave = function(clef, options) {
Expand Down Expand Up @@ -106,7 +112,6 @@
};

Vex.Flow.JSON.prototype.draw_notes = function(notes) {
console.log("DRAWING NOTES");
Vex.Flow.Formatter.FormatAndDraw(this.context, this.staves["treble"], notes);
};

Expand All @@ -125,7 +130,6 @@
};

Vex.Flow.JSON.prototype.draw_voices = function(voices) {
console.log("DRAWING VOICES");
var formatter = new Vex.Flow.Formatter().joinVoices(voices).format(voices, this.width - 120);
_(voices).each(function(voice) {
voice.draw(this.context, this.staves["treble"]);
Expand All @@ -137,8 +141,12 @@
this.width = options.width || element.width || 600;
this.height = options.height || element.height || 120;
this.clef = options.clef;
this.scale = options.scale || 1;

this.draw_canvas(element);
this.draw_canvas(element, {
scale: this.scale
});

this.draw_stave(this.clef);

if (this.voices) {
Expand Down

0 comments on commit e93fc95

Please sign in to comment.