简体   繁体   English

如何在html 5画布上使用FontAwesome图标

[英]How can I use FontAwesome icons on a html 5 canvas

I have a problem with using FontAwesome icons in my HTML 5 canvas, I tried this: 我在HTML 5画布中使用FontAwesome图标时遇到问题,我试过这个:

ct.fillStyle = "black";
ct.font = "20px Font Awesome";
ct.textAlign = "center";

var h = 'F1E2';

ct.fillText(String.fromCharCode(parseInt(h, 16)), x, y);

I tried importing the FontAwesome CSS file but it didn't work! 我尝试导入FontAwesome CSS文件,但它不起作用! Can anybody help me with this? 任何人都可以帮我吗?

Thanks! 谢谢!

  • First, if you're using FA5, use Font Awesome 5 Free . 首先,如果您使用的是FA5,请使用Font Awesome 5 Free If you're using FA4, you can just use FontAwesome . 如果您使用的是FA4,则可以使用FontAwesome
  • You need to set the font-weight to a high value (like 600). 您需要将font-weight设置为较高的值(如600)。

Example: 例:

 var ctx = canvas.getContext("2d"); document.fonts.ready.then(_ => { ctx.font = '600 48px "Font Awesome 5 Free"'; ctx.fillStyle = "black"; setTimeout(_ => ctx.fillText("\", 45, 45), 200); }); 
 @import url('https://use.fontawesome.com/releases/v5.0.9/css/all.css'); canvas { font-family: 'Font Awesome 5 Free'; font-weight: 600; } 
 <canvas id="canvas"></canvas> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM