最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Font weight in fabric.js library for HTML5 canvas - Stack Overflow

programmeradmin2浏览0评论

I've been playing with canvas and the awesome fabric library. I can't get text to display in anything other than the normal weight. i.e.

    var text2 = new fabric.Text('tseting', {
    fontsize: 50,
    fontFamily: 'Arial',
    fontStyle = 'bold',
    left: 100, 
    top: 100,
    fill:"#FF0000"
});

canvas2.add(text2);

The 'bold' tag doesn't get applied. When I created the font.js file suing cufon, I included the bold and italic fonts. Any ideas gratefully received.

I've been playing with canvas and the awesome fabric library. I can't get text to display in anything other than the normal weight. i.e.

    var text2 = new fabric.Text('tseting', {
    fontsize: 50,
    fontFamily: 'Arial',
    fontStyle = 'bold',
    left: 100, 
    top: 100,
    fill:"#FF0000"
});

canvas2.add(text2);

The 'bold' tag doesn't get applied. When I created the font.js file suing cufon, I included the bold and italic fonts. Any ideas gratefully received.

Share Improve this question edited Jun 25, 2017 at 5:14 ɢʀᴜɴᴛ 32.9k15 gold badges122 silver badges114 bronze badges asked Mar 7, 2012 at 15:30 user1255031user1255031 411 silver badge3 bronze badges 1
  • fontStyle = 'bold' you have used wrong property that means you should use bold property with fontWeight – Rash Commented Jun 19, 2013 at 14:23
Add a ment  | 

2 Answers 2

Reset to default 5

You've used the wrong property, and a typo ( the fontStyle = 'bold',). Use this instead:

var text2 = new fabric.Text('testing', {
    fontSize: 50,
    fontFamily: 'Arial',
    fontWeight: 'bold',
    left: 100, 
    top: 100,
    fill: "#FF0000"
});

canvas2.add(text2);

fontStyle refers to italic / normal.

Try fontWeight: bold or fontWeight: 700?

发布评论

评论列表(0)

  1. 暂无评论