简体   繁体   中英

How to apply custom font in fabric text object?

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?

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();

通过使用Simple Css属性Font @Face

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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