HTML5 canvas ctx.fillText won't do line breaks? HTML5 canvas ctx.fillText won't do line breaks? javascript javascript

HTML5 canvas ctx.fillText won't do line breaks?


If you just want to take care of the newline chars in the text you could simulate it by splitting the text at the newlines and calling multiple times the fillText()

Something like http://jsfiddle.net/BaG4J/1/

var c = document.getElementById('c').getContext('2d');c.font = '11px Courier';    console.log(c);var txt = 'line 1\nline 2\nthird line..';var x = 30;var y = 30;var lineheight = 15;var lines = txt.split('\n');for (var i = 0; i<lines.length; i++)    c.fillText(lines[i], x, y + (i*lineheight) );
canvas{background-color:#ccc;}
<canvas id="c" width="150" height="150"></canvas>