加载Fabric.js的自定义字体 [英] Load custom font for Fabric.js

查看:1699
本文介绍了加载Fabric.js的自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的Fabric.js应用添加一个Open Type字体。我发现这个问题, Pixi.js中的自定义字体,几乎要求相同的东西。我们如何从我们的文件系统加载一个字体?我试过使用CSS @ font-face。

解决方案

答案在问题和上面链接的一个。似乎我有我的代码与我的文件名相关的拼写问题。所以要清楚,正确的答案是使用CSS字体,如:

  @ font-face {
字体家庭:测试家庭;
src:url('path / to / fontfile');

$ / code>

然后在文本对象中使用字体名称:

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


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.

解决方案

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',
});

这篇关于加载Fabric.js的自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆