HTML5画布:度符号

jac*_*ore 8 html5 canvas

我不知道为什么,但我无法使用fillText的"度"符号(°).我尝试了一切:ALT + 248,ALT + 0176,°,从网上复制/粘贴...我得到的只是没有或者是°.在HTML中的代码或同一页面上工作正常 - 只是不在画布中.

有人知道怎么修这个东西吗?谢谢.

Phr*_*ogz 10

这适用于我,在文本中使用文字Unicode字符.在这里查看示例:http: //jsfiddle.net/W5d7D/

是你的源文件:

  1. 保存为UTF-8,和
  2. 描述为使用Unicode字符集,和
  3. 将JavaScript源描述为使用Unicode字符集?

这是一个独立的示例,显示了使用HTML和Canvas工作的Unicode.您可以在http://phrogz.net/tmp/canvas_unicode_degree_symbol.html上在线查看

<!DOCTYPE html>
<html><head>
  <meta charset="utf-8">
  <title>Unicode Degree Symbol on HTML5 Canvas</title>
  <style type="text/css" media="screen">
    body { margin:4em; background:#eee; text-align:center }
    canvas { background:#fff; border:1px solid #ccc; display:block; margin:2em auto }
  </style>
</head><body>
  <canvas></canvas>
  <p>Unicode characters 'just work' with a proper setup, e.g. "212° Fahrenheit"</p>
  <script type="text/javascript" charset="utf-8">
    var c = document.getElementsByTagName('canvas')[0];
    c.width = c.height = 400;

    var ctx = c.getContext('2d');
    ctx.font = "bold 24px sans-serif";
    ctx.fillText("212° Fahrenheit", 100, 100);
  </script>
</body></html>
Run Code Online (Sandbox Code Playgroud)