1

I have used the following code to write text using canvas.

<html>
 <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?

Variant
  • 17,279
  • 4
  • 40
  • 65
user475685
  • 8,041
  • 7
  • 26
  • 24

1 Answers1

6

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.

Community
  • 1
  • 1
Variant
  • 17,279
  • 4
  • 40
  • 65