FontAwesome在CSS文件中指定字形,如下所示:
/* Font Awesome uses the Unicode Private Use Area (PUA) to ensure
screen readers do not read off random characters that represent icons */
.icon-glass:before { content: "\f000"; }
.icon-music:before { content: "\f001"; }
我正在尝试将此字体中的图标渲染为画布元素,但无法查看如何访问这些字形。
ctx.font = "40px FontAwesome";
ctx.fillText("\f000",20,20); // no cigar
如何在JavaScript字符串中指定这些字形?
答案 0 :(得分:22)
您应该使用String.fromCharCode:
ctx.fillText(String.fromCharCode("0xf000"), 20, 20);
或Unicode转义的这种语法:
ctx.fillText("\uf000", 20, 20);