Skip to main content
Solved

fontWeight property is missing the text style


mohan_vadivel

fontWeight is an inherent property of text style. But figma.getStyleById for a text style doesn’t return the fontWeight property?

Why though?

Best answer by Gleb

That’s not how it works. fontWeight is not even a property you can set — it’s a readonly property, you can only read it. fontWeight is just a derivative of the chosen fontName, which includes the weight (style) in text format.

Plus, this property was added for text nodes only recently — all the hundreds of plugins that were released before that worked fine without it.

You only need fontName, since fontWeight is directly derived from fontName. If you set the correct fontName, fontWeight would be correct as well.

View original

4 replies

Gleb
  • Power Member
  • 4706 replies
  • June 4, 2023

It’s not inherent. The inherent parameter is fontName, which includes both the name of the font family and its style as in the font selection menu.

figma.com

fontWeight would be useful of course and not sure why it’s not provided but it’s not a must — it’s just a convenience property for codegen for example. You should be able to get this property from a TextStyle by applying this style to a text node and reading the textNode.fontWeight property if you really need it.


mohan_vadivel

Think of this way, all the properties that constitute a style are inherent. For example, take textAlignment property which does not play any part in text style, we can take any text node and update its text alignment property, and still have the same text style. But we can’t do the same with fontWeight property.

Anyhow, I’m working on a plugin to link the detached style to the proper text style, for which I need the fontWeight property to be present in the textStyle obj. For now, I can work around this by applying the style to a text node and looking for the fontWeight property on it.

Thanks for your time 🙂


Gleb
  • Power Member
  • 4706 replies
  • Answer
  • June 4, 2023

That’s not how it works. fontWeight is not even a property you can set — it’s a readonly property, you can only read it. fontWeight is just a derivative of the chosen fontName, which includes the weight (style) in text format.

Plus, this property was added for text nodes only recently — all the hundreds of plugins that were released before that worked fine without it.

You only need fontName, since fontWeight is directly derived from fontName. If you set the correct fontName, fontWeight would be correct as well.


mohan_vadivel

Ohh man! you’re right. I was confused with the fontName.style with the css font-style

Thanks for the help @Gleb 😊


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings