Javascript 如何从画布元素上的字体渲染glyph
在其CSS文件中指定图示符,如下所示:Javascript 如何从画布元素上的字体渲染glyph,javascript,html,canvas,webfonts,Javascript,Html,Canvas,Webfonts,在其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
/* 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字符串中指定这些图示符?您应该使用:
或者Unicode转义的以下语法:
ctx.fillText("\uf000", 20, 20);
这对我来说很有效,使用以下格式:
createjs.Text('\uf178',100px,'red')
。非常感谢。我来这里是想在画布上渲染材质设计图标。对我来说,String.fromCodePoint(0xF0625)
成功了。其中,F0909
对应于CSScontent
属性中的值:.mdi帮助圆圈outline::before{content:\F0625”}
注意,并非所有浏览器都实现String.fromCodePoint(即再次):
ctx.fillText("\uf000", 20, 20);