23

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文字列で指定するにはどうすればよいですか?

4

1 に答える 1

24

String.fromCharCodeを使用する必要があります。

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

または Unicode エスケープのこの構文:

ctx.fillText("\uf000", 20, 20);
于 2013-02-08T14:24:48.690 に答える