Here is my JS code:
function Show(output, startX, startY){
var c = document.getElementById("myCanvas");
var context = c.getContext("2d");
context.fillText ("A" , startX, startY);
context.font = 'bold 20px sans-serif';
context.fillText ("B" , startX, startY + 50);
}
Show(outputcpu, 50, 50);
Show(outputio, 150, 50);
what I expect is some thing like:
A A
B B
But I’m not sure why what i get is:
A A
B B
I think the issue due to context.font last until the next function call. But I don’t know how to stop it!
Any idea!?
You’ll need to reset the font before you draw – try:
Here is a fiddle – http://jsfiddle.net/8Tuzp/
EDIT:
If you really don’t like changing the font twice (I see no problem with doing so), you can save the canvas state and restore it once you have draw the bold text. Restoring the canvas context back to before you changed the font.