Load custom font for Fabric.js

独自空忆成欢 提交于 2019-12-23 04:53:19

问题


I'm looking to add an Open-Type Font to my Fabric.js app. I found this question, Custom font in Pixi.js, pretty much asking the same thing. How can we load a font from our file system? I tried using CSS @font-face as well.


回答1:


The answer was found on this question and the one linked above. It seems I had some spelling issues with my code in relation to my filename. So to be clear, the correct answer is to use CSS font face like:

@font-face {
    font-family: test-family;
    src: url('path/to/fontfile');
}

Then use the font family name inside the text object as such:

var t = new fabric.Text('text', {
    fontFamily: 'test-family',
});


来源:https://stackoverflow.com/questions/21010750/load-custom-font-for-fabric-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!