var fontSize = 12;
var scale = 1.00;

function drawStringAt(ctx, string, x, y)
{
	var length = string.length;
	var width = 0;
	var size = fontSize * scale;

	ctx.save();
	ctx.translate(x,y);
	ctx.scale(size  / 4,size  / 4);
	ctx.lineJoin = "miter";
	ctx.miterLimit = 0;
	ctx.lineWidth = 0.3;

	for(var i = 0; i < length; i++)
	{
		width = drawCharacter(ctx,string.charAt(i));
		ctx.translate(width+1,0);
	}
	ctx.restore();
}

function drawCharacter(ctx, chr)
{
	var width = 2; //3 is the default
	switch(chr)
	{
		case 'a':
			
			ctx.beginPath();
			ctx.arc(1,3,1,0,2*Math.PI,false);
			ctx.moveTo(2,2);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case 'A':
			
			ctx.beginPath();
			ctx.moveTo(0,4);
			ctx.lineTo(0.35,2.5);
			ctx.lineTo(1,0);
			ctx.lineTo(1.65,2.5);
			ctx.lineTo(2,4);
			ctx.moveTo(1.65,2.5);
			ctx.lineTo(0.35,2.5);
			ctx.stroke();
			break;
		case 'b':
			
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(0,4);
			ctx.stroke();
			ctx.beginPath();
			ctx.arc(1,3,1,0,2*Math.PI,false);
			ctx.stroke();
			break;
		case 'B':
			
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(0,4);
			ctx.stroke();
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.bezierCurveTo(2.5,0,2.5,2,0,2);
			ctx.stroke();
			ctx.beginPath();
			ctx.moveTo(0,2);
			ctx.bezierCurveTo(2.5,2,2.5,4,0,4);
			ctx.stroke();
			break;
		case 'c':
			
			ctx.beginPath();
			ctx.arc(1,3,1,1/4*Math.PI,7/4*Math.PI,false);
			ctx.stroke();
			break;
		case 'C':
			
			ctx.save();
			ctx.scale(0.7,1);
			ctx.beginPath();
			ctx.arc(1,2,2,1/4*Math.PI,7/4*Math.PI,false);
			ctx.stroke();
			ctx.restore();
			break;
		case 'd':
			
			ctx.beginPath();
			ctx.moveTo(2,0);
			ctx.lineTo(2,4);
			ctx.stroke();
			ctx.beginPath();
			ctx.arc(1,3,1,0,2*Math.PI,false);
			ctx.stroke();
			break;
			break;
		case 'D':
			
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(0,4);
			ctx.bezierCurveTo(3,4.5,3,-0.5,0,0);
			ctx.stroke();
			break;
		case 'e':
			
			ctx.beginPath();
			ctx.arc(1,3,1,1/5*Math.PI,2*Math.PI,false);
			ctx.lineTo(0,3);
			ctx.stroke();
			break;
		case 'E':
			
			ctx.beginPath();
			ctx.moveTo(2,0);
			ctx.lineTo(0,0);
			ctx.lineTo(0,4);
			ctx.lineTo(2,4);
			ctx.moveTo(0,2);
			ctx.lineTo(1.5,2);
			ctx.stroke();
			break;
		case 'f':
			width = 2;
			ctx.beginPath();
			ctx.arc(1,1,1,Math.PI,13/8*Math.PI,false);
			ctx.stroke();
			ctx.beginPath();
			ctx.moveTo(0,1);
			ctx.lineTo(0,4.2);
			ctx.moveTo(-0.5,2);
			ctx.lineTo(1,2);
			ctx.stroke();
			break;
		case 'F':
			
			ctx.beginPath();
			ctx.moveTo(2,0);
			ctx.lineTo(0,0);
			ctx.lineTo(0,4.2);
			ctx.moveTo(0,2);
			ctx.lineTo(1.5,2);
			ctx.stroke();
			break;
		case 'g':
			width = 3;
			ctx.beginPath();
			ctx.arc(1,3,1,0,2*Math.PI,false);
			ctx.moveTo(2,2);
			ctx.lineTo(2,5);
			ctx.arc(1,5,1,0,Math.PI,false);
			ctx.stroke();
			break;
		case 'G':
			
			ctx.save();
			ctx.scale(0.7,1);
			ctx.beginPath();
			ctx.arc(1,2,2,1/4*Math.PI,7/4*Math.PI,false);
			ctx.moveTo(2.4,3.57);
			ctx.lineTo(2.4,2);
			ctx.lineTo(1,2);
			ctx.stroke();
			ctx.restore();
			break;
		case 'h':
			
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(0,4);
			ctx.moveTo(0,2);
			ctx.bezierCurveTo(2,1.8,2,2,2,4);
			ctx.stroke();
			break;
		case 'H':
			
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(0,4);
			ctx.moveTo(2,0);
			ctx.lineTo(2,4);
			ctx.moveTo(2,2);
			ctx.lineTo(0,2);
			ctx.stroke();
			break;
		case 'i':
			width = 1;
			ctx.beginPath();
			ctx.moveTo(1,1);
			ctx.lineTo(1,1.5);
			ctx.moveTo(1,2);
			ctx.lineTo(1,4);
			ctx.stroke();
			break;
		case 'I':
			
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(2,0);
			ctx.moveTo(1,0);
			ctx.lineTo(1,4);
			ctx.moveTo(0,4);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case 'j':
			ctx.beginPath();
			ctx.moveTo(2,1);
			ctx.lineTo(2,1.5);
			ctx.moveTo(2,2);
			ctx.lineTo(2,5);
			ctx.arc(1,5,1,0,Math.PI,false);
			ctx.stroke();
			break;
		case 'J':
			ctx.beginPath();
			ctx.moveTo(1.5,0);
			ctx.lineTo(2.5,0);
			ctx.moveTo(2,0);
			ctx.lineTo(2,3.3);
			ctx.arc(1,3.3,1,0,Math.PI,false);
			ctx.stroke();
			break;
		case 'k':
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(0,4);
			ctx.moveTo(0,2.5);
			ctx.lineTo(1.5,1);
			ctx.moveTo(0,2.5);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case 'K':
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(0,4);
			ctx.moveTo(0,2);
			ctx.lineTo(2,0);
			ctx.moveTo(0,2);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case 'l':
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(1,0);
			ctx.lineTo(1,4);
			ctx.moveTo(0,4);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case 'L':
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(0,4);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case 'm':
			ctx.beginPath();
			ctx.moveTo(0,2);
			ctx.lineTo(0,4);
			ctx.moveTo(0,2.2);
			ctx.bezierCurveTo(0.4,1.5,1,2,1,2);
			ctx.lineTo(1,4);
			ctx.moveTo(1,2.2);
			ctx.bezierCurveTo(1.4,1.5,2,2,2,2);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case 'M':
			ctx.beginPath();
			ctx.moveTo(0,4);
			ctx.lineTo(0,0);
			ctx.lineTo(1,4);
			ctx.lineTo(2,0);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case 'n':
			ctx.beginPath();
			ctx.moveTo(0,2);
			ctx.lineTo(0,4);
			ctx.moveTo(0,2.2);
			ctx.bezierCurveTo(0.4,1.5,2,1,2,2.5);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case 'N':
			ctx.beginPath();
			ctx.moveTo(0,4);
			ctx.lineTo(0,0);
			ctx.lineTo(2,4);
			ctx.lineTo(2,0);
			ctx.stroke();
			break;
		case '1':
			
			ctx.beginPath();
			ctx.moveTo(0,1);
			ctx.lineTo(1,0);
			ctx.lineTo(1,4);
			ctx.moveTo(0,4);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case '2':
			
			ctx.beginPath();
			ctx.arc(1,1,1,Math.PI,0,false);
			ctx.moveTo(2,1);
			ctx.lineTo(0,4);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case '3':
			
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.bezierCurveTo(2,-1,3,2,0.5,2);
			ctx.bezierCurveTo(3,2,2,5,0,4);
			ctx.stroke();
			break;
		case '4':
			
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(0,2);
			ctx.lineTo(2,2);
			ctx.moveTo(2,0);
			ctx.lineTo(2,4.2);
			ctx.stroke();
			break;
		case '5':
			
			ctx.beginPath();
			ctx.moveTo(2,0);
			ctx.lineTo(0,0);
			ctx.lineTo(0,2);
			ctx.bezierCurveTo(2.5,2,2.5,4,0,4.2);
			ctx.stroke();
			break;
		case '6':
			
			ctx.beginPath();
			ctx.arc(1,1,1,Math.PI,0,false);
			ctx.moveTo(0,1);
			ctx.lineTo(0,3);
			ctx.stroke();
			ctx.beginPath();
			ctx.arc(1,3,1,0,2*Math.PI,false);
			ctx.stroke();
			break;
		case '7':
			
			ctx.beginPath();
			ctx.moveTo(0,1);
			ctx.lineTo(0,0);
			ctx.lineTo(2,0);
			ctx.lineTo(1,4.2);
			ctx.stroke();
			break;
		case '8':
			
			ctx.beginPath();
			ctx.arc(1,1,1,0,2*Math.PI,false);
			ctx.stroke();
			ctx.beginPath();
			ctx.arc(1,3,1,0,2*Math.PI,false);
			ctx.stroke();
			break;
		case '9':
			
			ctx.beginPath();
			ctx.arc(1,1,1,0,2*Math.PI,false);
			ctx.moveTo(2,1);
			ctx.lineTo(2,3);
			ctx.stroke();
			ctx.beginPath();
			ctx.arc(1,3,1,0,-Math.PI,false);
			ctx.stroke();
			break;
		case '0':
			ctx.beginPath();
			ctx.moveTo(1,0);
			ctx.bezierCurveTo(-0.5,0,-0.5,4,1,4);
			ctx.bezierCurveTo(2.5,4,2.5,0,1,0);
			ctx.moveTo(1.5,0.2);
			ctx.lineTo(0.5,3.8);
			ctx.stroke();
			break;
		case '.':
			width = 1;
			ctx.beginPath();
			ctx.rect(0.5,3.5,0.5,0.5);
			ctx.fill();
			break;
		case ':':
			width = 1;
			ctx.beginPath();
			ctx.rect(0.5,1.5,0.5,0.5);
			ctx.rect(0.5,3.5,0.5,0.5);
			ctx.fill();
			break;
		case ';':
			width = 1;
			ctx.beginPath();
			ctx.rect(0.5,1.5,0.5,0.5);
			ctx.moveTo(0.5,3.5);
			ctx.lineTo(1,3.5);
			ctx.lineTo(0.5,4.2);
			ctx.lineTo(0,4.2);
			ctx.fill();
			break;
		case '/':
			ctx.beginPath();
			ctx.moveTo(0,4);
			ctx.lineTo(2,0);
			ctx.stroke();
			break;
		case '\\':
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case ',':
			width = 1;
			ctx.beginPath();
			ctx.moveTo(0.5,3.5);
			ctx.lineTo(1,3.5);
			ctx.lineTo(0.5,4.2);
			ctx.lineTo(0,4.2);
			ctx.fill();
			break;
		case '"':
			width = 2;
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(0,1);
			ctx.moveTo(1,0);
			ctx.lineTo(1,1);
			ctx.stroke();
			break;
		case '\'':
			width = 1;
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(0,1);
			ctx.stroke();
			break;
		case '?':
			ctx.beginPath();
			ctx.arc(1,1,1,5/4*Math.PI,5/2*Math.PI,false);
			ctx.lineTo(1,3);
			ctx.moveTo(1,3.5);
			ctx.lineTo(1,4);
			ctx.stroke();
			break;
		case '<':
			ctx.beginPath();
			ctx.moveTo(0,2);
			ctx.lineTo(2,0);
			ctx.moveTo(0,2);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case '>':
			ctx.beginPath();
			ctx.moveTo(2,2);
			ctx.lineTo(0,0);
			ctx.moveTo(2,2);
			ctx.lineTo(0,4);
			ctx.stroke();
			break;
		case '[':	
			width = 2;
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.lineTo(1,0);
			ctx.moveTo(0,0);
			ctx.lineTo(0,4);
			ctx.lineTo(1,4);
			ctx.stroke();
			break;
		case ']':
			width = 2;
			ctx.beginPath();
			ctx.moveTo(2,0);
			ctx.lineTo(1,0);
			ctx.moveTo(2,0);
			ctx.lineTo(2,4);
			ctx.lineTo(1,4);
			ctx.stroke();
			break;
		case '-':
			ctx.beginPath();
			ctx.moveTo(0,2);
			ctx.lineTo(2,2);
			ctx.stroke();
			break;
		case '_':
			ctx.beginPath();
			ctx.moveTo(0,4);
			ctx.lineTo(2,4);
			ctx.stroke();
			break;
		case '=':
			ctx.moveTo(0,1.5);
			ctx.lineTo(2,1.5);
			ctx.moveTo(0,2.5);
			ctx.lineTo(2,2.5);
			ctx.stroke();
			break;
		case '+':
			ctx.moveTo(1,1);
			ctx.lineTo(1,3);
			ctx.moveTo(0,2);
			ctx.lineTo(2,2);
			ctx.stroke();
			break;
		case '{':
			ctx.moveTo(1,0);
			ctx.bezierCurveTo(0,0,1,2,0,2);
			ctx.bezierCurveTo(1,2,0,4,1,4);
			ctx.stroke();
			break;
		case '}':
			ctx.moveTo(0,0);
			ctx.bezierCurveTo(1,0,0,2,1,2);
			ctx.bezierCurveTo(0,2,1,4,0,4);
			ctx.stroke();
			break;
		case '`':
			ctx.beginPath();
			ctx.moveTo(0.5,0.5);
			ctx.lineTo(1,0.5);
			ctx.lineTo(1.5,1);
			ctx.lineTo(1,1);
			ctx.fill();
			break;
		case '~':
			ctx.beginPath();
			ctx.moveTo(0,0);
			ctx.bezierCurveTo(-0.3,1,2,-1,2,0.3);
			ctx.stroke();
			break;
		case '*':
			ctx.beginPath();
			ctx.moveTo(0,1);
			ctx.lineTo(2,3);
			ctx.moveTo(2,1);
			ctx.lineTo(0,3);
			ctx.moveTo(1,1);
			ctx.lineTo(1,3);
			ctx.moveTo(0,2);
			ctx.lineTo(2,2);
			ctx.stroke();
			break;
		case '!':
			width = 1;
			ctx.beginPath();
			ctx.moveTo(1,0);
			ctx.lineTo(1,3);
			ctx.moveTo(1,3.5);
			ctx.lineTo(1,4);
			ctx.stroke();
			break;	
		case '#':
			ctx.beginPath();
			ctx.moveTo(0,4);
			ctx.lineTo(1,0);
			ctx.moveTo(1,4);
			ctx.lineTo(2,0);
			ctx.moveTo(0,1);
			ctx.lineTo(2.5,1);
			ctx.moveTo(-0.5,3);
			ctx.lineTo(2,3);
			ctx.stroke();
			break;	
		case '%':
			ctx.beginPath();
			ctx.moveTo(0,4);
			ctx.lineTo(2,0);
			ctx.moveTo(1,0.5);
			ctx.arc(0.5,0.5,0.5,0,2*Math.PI,false);
			ctx.moveTo(2.3,3);
			ctx.arc(1.8,3,0.5,0,2*Math.PI,false);
			ctx.stroke();	
			break;
		case '(':
			ctx.beginPath();
			ctx.moveTo(1,0);
			ctx.bezierCurveTo(0,2,0,2,1,4);
			ctx.stroke();
			break;
		case ')':
			ctx.beginPath();
			ctx.moveTo(1,0);
			ctx.bezierCurveTo(2,2,2,2,1,4);
			ctx.stroke();
			break;
		case '^':
			ctx.beginPath();
			ctx.moveTo(0,1);
			ctx.lineTo(1,0);
			ctx.lineTo(2,1);
			ctx.stroke();
			break;
		default:
			ctx.beginPath();
			ctx.rect(0,0,2,4);
			ctx.stroke();
			break;
			
	}

	return width;
}
