var Hershey={
glyphs:
{
"1":[{t:'M',x:0,y:-5},{t:'L',x:-4,y:4},{t:'M',x:0,y:-5},{t:'L',x:4,y:4},{t:'M',x:-2,y:1},{t:'L',x:2,y:1}],"2":[{t:'M',x:-3,y:-5},{t:'L',x:-3,y:4},{t:'M',x:-3,y:-5},{t:'L',x:1,y:-5},{t:'L',x:3,y:-4},{t:'L',x:3,y:-2},{t:'L',x:1,y:-1},{t:'M',x:-3,y:-1},{t:'L',x:1,y:-1},{t:'L',x:3,y:0},{t:'L',x:3,y:3},{t:'L',x:1,y:4},{t:'L',x:-3,y:4}],"3":[{t:'M',x:4,y:-4},{t:'L',x:2,y:-5},{t:'L',x:0,y:-5},{t:'L',x:-2,y:-4},{t:'L',x:-3,y:-2},{t:'L',x:-3,y:1},{t:'L',x:-2,y:3},{t:'L',x:0,y:4},{t:'L',x:2,y:4},{t:'L',x:4,y:3}],"4":[{t:'M',x:-3,y:-5},{t:'L',x:-3,y:4},{t:'M',x:-3,y:-5},{t:'L',x:0,y:-5},{t:'L',x:2,y:-4},{t:'L',x:3,y:-2},{t:'L',x:3,y:1},{t:'L',x:2,y:3},{t:'L',x:0,y:4},{t:'L',x:-3,y:4}],"5":[{t:'M',x:-3,y:-5},{t:'L',x:-3,y:4},{t:'M',x:-3,y:-5},{t:'L',x:3,y:-5},{t:'M',x:-3,y:-1},{t:'L',x:1,y:-1},{t:'M',x:-3,y:4},{t:'L',x:3,y:4}],"6":[{t:'M',x:-3,y:-5},{t:'L',x:-3,y:4},{t:'M',x:-3,y:-5},{t:'L',x:3,y:-5},{t:'M',x:-3,y:-1},{t:'L',x:1,y:-1}],"7":[{t:'M',x:4,y:-4},{t:'L',x:2,y:-5},{t:'L',x:0,y:-5},{t:'L',x:-2,y:-4},{t:'L',x:-3,y:-2},{t:'L',x:-3,y:1},{t:'L',x:-2,y:3},{t:'L',x:0,y:4},{t:'L',x:2,y:4},{t:'L',x:4,y:3},{t:'L',x:4,y:0},{t:'M',x:1,y:0},{t:'L',x:4,y:0}],"8":[{t:'M',x:-3,y:-5},{t:'L',x:-3,y:4},{t:'M',x:3,y:-5},{t:'L',x:3,y:4},{t:'M',x:-3,y:-1},{t:'L',x:3,y:-1}],"9":[{t:'M',x:0,y:-5},{t:'L',x:0,y:4}],"10":[{t:'M',x:1,y:-5},{t:'L',x:1,y:2},{t:'L',x:0,y:4},{t:'L',x:-2,y:4},{t:'L',x:-3,y:2},{t:'L',x:-3,y:1}],"11":[{t:'M',x:-3,y:-5},{t:'L',x:-3,y:4},{t:'M',x:3,y:-5},{t:'L',x:-3,y:1},{t:'M',x:-1,y:-1},{t:'L',x:3,y:4}],"12":[{t:'M',x:-3,y:-5},{t:'L',x:-3,y:4},{t:'M',x:-3,y:4},{t:'L',x:3,y:4}],"13":[{t:'M',x:-4,y:-5},{t:'L',x:-4,y:4},{t:'M',x:-4,y:-5},{t:'L',x:0,y:4},{t:'M',x:4,y:-5},{t:'L',x:0,y:4},{t:'M',x:4,y:-5},{t:'L',x:4,y:4}],"14":[{t:'M',x:-3,y:-5},{t:'L',x:-3,y:4},{t:'M',x:-3,y:-5},{t:'L',x:3,y:4},{t:'M',x:3,y:-5},{t:'L',x:3,y:4}],"15":[{t:'M',x:0,y:-5},{t:'L',x:-2,y:-4},{t:'L',x:-3,y:-2},{t:'L',x:-3,y:1},{t:'L',x:-2,y:3},{t:'L',x:0,y:4},{t:'L',x:1,y:4},{t:'L',x:3,y:3},{t:'L',x:4,y:1},{t:'L',x:4,y:-2},{t:'L',x:3,y:-4},{t:'L',x:1,y:-5},{t:'L',x:0,y:-5}],"16":[{t:'M',x:-3,y:-5},{t:'L',x:-3,y:4},{t:'M',x:-3,y:-5},{t:'L',x:1,y:-5},{t:'L',x:3,y:-4},{t:'L',x:3,y:-1},{t:'L',x:1,y:0},{t:'L',x:-3,y:0}],"17":[{t:'M',x:0,y:-5},{t:'L',x:-2,y:-4},{t:'L',x:-3,y:-2},{t:'L',x:-3,y:1},{t:'L',x:-2,y:3},{t:'L',x:0,y:4},{t:'L',x:1,y:4},{t:'L',x:3,y:3},{t:'L',x:4,y:1},{t:'L',x:4,y:-2},{t:'L',x:3,y:-4},{t:'L',x:1,y:-5},{t:'L',x:0,y:-5},{t:'M',x:1,y:2},{t:'L',x:4,y:5}],"18":[{t:'M',x:-3,y:-5},{t:'L',x:-3,y:4},{t:'M',x:-3,y:-5},{t:'L',x:1,y:-5},{t:'L',x:3,y:-4},{t:'L',x:3,y:-1},{t:'L',x:1,y:0},{t:'L',x:-3,y:0},{t:'M',x:0,y:0},{t:'L',x:3,y:4}],"19":[{t:'M',x:3,y:-4},{t:'L',x:1,y:-5},{t:'L',x:-1,y:-5},{t:'L',x:-3,y:-4},{t:'L',x:-3,y:-3},{t:'L',x:-2,y:-2},{t:'L',x:2,y:0},{t:'L',x:3,y:1},{t:'L',x:3,y:3},{t:'L',x:1,y:4},{t:'L',x:-1,y:4},{t:'L',x:-3,y:3}],"20":[{t:'M',x:0,y:-5},{t:'L',x:0,y:4},{t:'M',x:-4,y:-5},{t:'L',x:4,y:-5}],"21":[{t:'M',x:-3,y:-5},{t:'L',x:-3,y:1},{t:'L',x:-2,y:3},{t:'L',x:0,y:4},{t:'L',x:1,y:4},{t:'L',x:3,y:3},{t:'L',x:4,y:1},{t:'L',x:4,y:-5}],"22":[{t:'M',x:-4,y:-5},{t:'L',x:0,y:4},{t:'M',x:4,y:-5},{t:'L',x:0,y:4}],"23":[{t:'M',x:-4,y:-5},{t:'L',x:-2,y:4},{t:'M',x:0,y:-5},{t:'L',x:-2,y:4},{t:'M',x:0,y:-5},{t:'L',x:2,y:4},{t:'M',x:4,y:-5},{t:'L',x:2,y:4}],"24":[{t:'M',x:-3,y:-5},{t:'L',x:3,y:4},{t:'M',x:3,y:-5},{t:'L',x:-3,y:4}],"25":[{t:'M',x:-4,y:-5},{t:'L',x:0,y:-1},{t:'L',x:0,y:4},{t:'M',x:4,y:-5},{t:'L',x:0,y:-1}],"26":[{t:'M',x:3,y:-5},{t:'L',x:-3,y:4},{t:'M',x:-3,y:-5},{t:'L',x:3,y:-5},{t:'M',x:-3,y:4},{t:'L',x:3,y:4}]
},
print: function(ctx,s,x,y,w,h)
{
var i=0;
if(s.length==0 || h==0 || w==0) return;
var rows=s.split(/\n/);
if(rows.length!=1)
{
var dh= h/rows.length ;
/* max length */
var maxL=0;
for(i=0;i<rows.length;++i)
{
maxL=(maxL <rows[i].length ?rows[i].length:maxL);
}
for(i=0;i<rows.length;++i)
{
var s2=rows[i];
while(s2.length < maxL) s2+=".";
this.print(ctx,s2,x,y+(i*dh),w,dh);
}
return;
}
var dx=w/s.length;
for(i=0;i<s.length;++i)
{
var c=s.toUpperCase().charCodeAt(i);
if(c>=65 || c<=90)
{
var g=Hershey.glyphs[""+(c-64)];
if(!g) continue;
var j;
for(j=0;j<g.length;++j)
{
var px=( (g[j].x) / this.scalex)*dx + (x+dx*i) +dx/2.0;
var py=( (g[j].y) / this.scaley)*h + y +h/2.0 ;
//console.log("p="+px+"/"+py);
if(g[j].t=='L')
{
ctx.lineTo(px,py);
}
else
{
ctx.moveTo(px,py);
}
}
}
}
},
scalex:15.0,
scaley:15.0
};
function randomRect(ctx,s)
{
var W=500;
var H=500;
var x=W*Math.random();
var y=H*Math.random();
var w=(W-x)*Math.random();
var h=(H-y)*Math.random();
x-=w/2; y-=h/2;
ctx.save();
ctx.translate(W/2,H/2);
ctx.rotate(Math.random()*360);
ctx.fillStyle = "rgba(226, 226, 226, 0.7)";
ctx.fillRect(x,y,w,h);
ctx.strokeStyle = "rgba(0, 0, 0, 0.9)";
ctx.strokeRect(x,y,w,h);
ctx.lineWidth = (w>100 && h>100 ? 2:1);
ctx.beginPath();
Hershey.print(ctx,s,x,y,w,h);
ctx.stroke();
ctx.restore();
}
function paint1258902511126()
{
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
for(var i=0;i<200;++i)
{
var s="Monsieur Jack,\nvous dactylographiez\nbien mieux que\nvotre ami Wolf";
if(i%2==0) s="The quick brown fox\njumps over\nthe lazy dog";
randomRect(ctx,s);
}
}
paint1258902511126();
<canvas id="myCanvas" width="500" height="500" style="border:1px solid #000000;">
</canvas>