Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set font-weight in Kinetic.Text (KineticJS)?

Tags:

kineticjs

Is there a way to set font-weight in KineticJS's Text object?

Here's example code:

  var myText = new Kinetic.Text(
  {
    x: 350,
    y: 50,
    text: 'OK',
    fontSize: 18,
    fontFamily: 'Verdana',
    fill: 'white'
  });

I'd like the font-weight to be 100 or 200, rather than the default (400). Not finding a fontWeight property in the documentation, I tried the following without success:

  • Using the fontStyle property (which lets you specific bold, normal, italic)
  • Setting the id property and trying to set font-weight via CSS.

Thanks for any tips.

like image 820
Marc Avatar asked Nov 20 '25 05:11

Marc


1 Answers

Use the fontStyle property (Hint: the value must be a string--not number):

var myText = new Kinetic.Text({
    x:100,
    y:100,
    text:"Hello World!",
    fill: 'red',
    fontFamily:"Calibri",
    fontSize:18,
    fontStyle:"100"
});
like image 123
markE Avatar answered Nov 22 '25 03:11

markE