measureText (TXT)
You can measure text using canvas. canvas.measureText(txt).width
Here is a basic example with various limitations. To create large canvases, one more math is required ...
txtHeight- this is basically a line-height.
offsetis the distance you want to move the text.
- , .
var b=document.createElement('canvas');
b.width=320;
b.height=160;
c=b.getContext("2d");
function draw(txt){
c.font="20px Arial";
var txtHeight=25;
var offset=5;
var w=Math.ceil(c.measureText(txt).width);
var txt=new Array(w*2).join(txt+' ');
for(var i=0;i<Math.ceil(b.height/txtHeight);i++){
c.fillText(txt,-(i*offset),i*txtHeight);
}
}
document.body.appendChild(b);
draw('1234567');
Demo
https://jsfiddle.net/wav0xmLz/1/
.
, , txt.... . iiii TTTT .
.... , , ... .
split,shift,join,push
https://jsfiddle.net/kds7zkkf/