开发者

Writing text using canvas in HTML5

开发者 https://www.devze.com 2023-03-15 02:06 出处:网络
I have used the following code to write text using canvas. <html>开发者_StackOverflow中文版;

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号