2012-12-07 7 views
23

FontAwesome Glyphen in seiner CSS-Datei gibt an, wie so:Wie Glyphen aus FontAwesome auf einem Canvas-Element machen

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

Ich versuche, Symbole aus dieser Schrift auf ein Canvas-Element zu machen, kann aber nicht sehen, wie man Greife auf diese Glyphen zu.

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

Wie gebe ich diese Glyphen in JavaScript-Strings an?

Antwort

22

sollten Sie String.fromCharCode verwenden:

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

oder diese Syntax für Unicode entkommt:

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

Es zeigt mir Platz – Volatil3

+2

Dies funktionierte für mich, in diesem Format: 'createjs.Text (‘ \ ub178 ',' 100px FontAwesome, 'rot') '. Danke vielmals. – ITWitch