fontWeight property is missing the text style

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

Why though?

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.

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.

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 :slight_smile:

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.

2 Likes

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

Thanks for the help @Gleb :blush:

1 Like