How to apply custom font in fabric text object?

2019-03-14 01:11发布

I would like to use custom font in fabric text object, I followed the link below: http://fabricjs.com/fabric-intro-part-4/

But it seems that it's only supported in node.js.

Is there any way to support it on simple fabric text object on canvas?

2条回答
Viruses.
2楼-- · 2019-03-14 02:05

By using Simple Css property Font @Face

查看更多
Explosion°爆炸
3楼-- · 2019-03-14 02:13

Use CSS:

@font-face
{
font-family: myFirstFont;
src: url('Sansation_Light.ttf'),
url('Sansation_Light.eot'); /* IE9 */
}

Create fabric text object instance :

 var object = new fabric.Text("NEW TEXT", { 
    fontFamily: "myFirstFont", 
    left: 150,
    top: 100,
    fontSize: 24,
    textAlign: "left",
    fill: "#000000"
});
canvas.add(object);
canvas.renderAll();
查看更多
登录 后发表回答