Подтвердить что ты не робот

Как отображать глифы из FontAwesome на элементе Canvas

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?

4b9b3361

Ответ 1

Вы должны использовать String.fromCharCode:

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

или этот синтаксис для экранов Unicode:

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