使用 fillText 在 Canvas 中显示国际字符时出现问题
我试图使用 filltext() 将法语字符(例如 é)写入画布,但失败了。 文本仅显示为白色填充的菱形和问号“?”在中心。 所有其他“英文”字符均正常显示。
我的页面标记为:
<!doctype html>
<html lang=en>
<head>
<title> Title </title>
<meta charset="utf-8">
并且我正在使用 Arial 字体。 我的桌面浏览器是 Firefox 10.0,HTC Desire HD 上的默认浏览器是。
我编写文本的代码是:
context.font = "normal 16px Arial, Sans-Serif";
context.fillText('Mission Echouée', x, y);
我应该补充一点,这在过去对我有用。可能是大约5个月前。
有人对我有任何见解/经验吗?
非常感谢 标记
I am trying to write French characters (e.g. é) out to the canvas using filltext() and failing.
The text just displays with the white-filled diamond and question mark "?" in the centre.
All other "English" characters display normally.
My page is marked up as:
<!doctype html>
<html lang=en>
<head>
<title> Title </title>
<meta charset="utf-8">
and I am using the Arial font.
My browser is Firefox 10.0 on the Desktop and the Default browser on an HTC Desire HD.
My code for writing the text is:
context.font = "normal 16px Arial, Sans-Serif";
context.fillText('Mission Echouée', x, y);
I should add that this has worked for me in the past. Possibly about 5 months ago.
Does anyone have any insight / experience for me ?
Many thanks
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
刚刚发现这张旧票,所以想提供答案。
我应该澄清一下,我实际上包含了翻译后的文本数据,如下所示:
问题是 textdata.js 文件未保存为 UTF-8
保存为 UTF-8 后,国际字符将正确显示。
Just found this old ticket so wanted to provide the answer.
I should have clarified that I was actually including the translated text data like this:
The problem was that the textdata.js file was not saved as UTF-8
Once saved as UTF-8 the international characters display correct.
这里一定发生了其他事情。简化你的代码:
http://jsfiddle.net/kHqmP/
这个小提琴在最新的 chrome 中对我来说工作得很好、firefox 和 Windows 7 上的 IE9。它也适用于我的 Galaxy Nexus。
这对你不起作用吗?
我想这是你不必要的设置。
Something else has to be going on here. Simplify your code:
http://jsfiddle.net/kHqmP/
That fiddle works fine for me in the latest chrome, firefox and IE9 on Windows 7. It also works on my Galaxy Nexus.
Does it not work for you?
I imagine its something that you are setting unnecessarily.