问题
Afaik, you can only set the font for the WHOLE canvas.
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.font = "30px Arial"
I would like lets say, text1 to be "30px Arial" and text2 to be "10px Arial". Is this possible?
回答1:
Yes, its is possible:
//first text
ctx.font = "30px Arial";
ctx.fillText("Hello World",10,50);
//second text
ctx.font = "20px Arial";
ctx.fillText("Bell World",50,100);
来源:https://stackoverflow.com/questions/36801391/javascript-is-it-possible-to-set-different-font-sizes-for-different-texts-in-a