// Code goes here
var c = document.getElementById("myCanvas");
var context = c.getContext("2d");
wrapText(context,"bartrts iusohias vela jhfjhfj",10,80,80,13);
//ctx.moveTo(0,0);
//ctx.lineTo(200,100);
//ctx.stroke();
function wrapText(context, text, x, y, maxWidth, lineHeight){
// context.font = "30px Arial";
//context.fillText("Hello World",10,50);
var words = text.split(" ");
var line = "";
//var x=0;
//var miy=90;
//var maxWidth=100;
// var lineHeight=50;
context.fillStyle = "rgb(0, 255, 178)";
context.fillRect(x, y-lineHeight, maxWidth, lineHeight*3+5);
alert(x);
context.font = "12pt Calibri";
context.fillStyle = "blue";
for (var n = 0; n < words.length; n++) {
var testLine = line + words[n] + " ";
var metrics = context.measureText(testLine);
var testWidth = metrics.width;
if (testWidth > maxWidth) {
alert(testWidth);
context.fillText(line, x, y);
line = words[n] + " ";
y += lineHeight;
}
else {
line = testLine;
}
}
context.fillText(line, x, y);
}