2012-12-07 30 views
23

FontAwesome指定的CSS文件字形,像这样的:如何使从FontAwesome字形canvas元素

/* 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"; } 

我试图从这种字体的canvas元素呈现的图标,但无法看到如何访问这些字形。

ctx.font = "40px FontAwesome"; 
ctx.fillText("\f000",20,20); // no cigar 

如何在JavaScript字符串中指定这些字形?

回答

22

你应该使用String.fromCharCode

ctx.fillText(String.fromCharCode("0xf000"), 20, 20); 

或本语法Unicode转义:

ctx.fillText("\uf000", 20, 20); 
+0

它显示了广场,我 – Volatil3

+2

这个工作对我来说,使用这种格式:'createjs.Text(” ','100px FontAwesome,'红色')'。非常感谢。 – ITWitch