I have used the following code to write text using canvas.
<html>开发者_StackOverflow中文版;
<head>
<script type="text/javascript">
function convert(){
draw(document.getElementById('canvas').getContext('2d'));
}
function draw(txt){
var fillText="Some text";
txt.textBaseline="top";
txt.font="Arial";
txt.fillStyle="red";
txt.fillText(fillText,20,20);
}
</script>
</head>
<body onload="convert()">
<canvas id="canvas"></canvas>
</body>
</html>
My question is: is it possible to write text in other languages also?
As long as the font you use supports the other language's character sets there should be no problems.
If the font is not a common font (And a Japanese/Arabic/Hebrew font isn't) you should use @font-face
to supply the font file.
Yuo can read this thread: Drawing text to <canvas> with @font-face does not work at the first time for a common gotcha.
精彩评论