Skip to main content
Question

Figma API font weights


Knuc29

I’m dynamically loading the font weights of selected fonts, but I have to map values to make a Preview feature work. Problem, there are many different naming conventions,
most fonts have thin = 100, but some like Helvetica Neue have thin = 200 and ultraLight = 100 for example. And writing conditions for each font is not really what I’m aiming for 🙂

Is there another way to handle something like that ?

switch (style) {
                            case 'Thin': value = '100'; break;
                            case 'UltraLight': value = '100'; break;
                            case 'Thin Italic': value = '100 Italic'; break;
                            case 'UltraLight Italic': value = '100 Italic'; break;
                            case 'Extra Light': value = '200'; break;
                            case 'Extra Light Italic': value = '200 Italic'; break;
                            case 'ExtraLight Italic': value = '200 Italic'; break;
                            case 'Light': value = '300'; break;
                            case 'Light Italic': value = '300 Italic'; break;
                            case 'Light Oblique': value = '300 Italic'; break;
                            case 'Regular': 
                            case '400': value = '400'; break;
                            case 'Book': value = 'Book'; break;
                            case 'Book Italic': value = 'Book Italic'; break;
                            case 'Medium': value = '500'; break;
                            case 'Medium Italic': value = '500 Italic'; break;
                            case 'Semi Bold': value = '600'; break;
                            case 'Semi Bold Italic': value = '600 Italic'; break;
                            case 'SemiBold Italic': value = '600 Italic'; break;
                            case 'Bold': value = '700'; break;
                            case 'Condensed Bold': value = '700'; break;
                            case 'Bold Italic': value = '700 Italic'; break;
                            case 'Bold Oblique': value = '700 Italic'; break;
                            case 'Extra Bold': value = '800'; break;
                            case 'Extra Bold Italic': value = '800 Italic'; break;
                            case 'ExtraBold Italic': value = '800 Italic'; break;
                            case 'Black': value = '900'; break;
                            case 'Condensed Black': value = '900'; break;
                            case 'Black Italic': value = '900 Italic'; break;
                            default: value = style;
                        }
This topic has been closed for comments

2 replies

jefflee
Figmate
  • Figmate
  • 22 replies
  • March 21, 2024

Howdy! It sounds like you’re hoping to use the Plugin API to create mapping between a) font style strings in Font objects and b) numeric weight values.

If that’s correct…unfortunately, there isn’t a way to do that right now, but we feel your pain. But I’ve gone ahead and noted this as a feature request.


Knuc29
  • Author
  • 4 replies
  • March 23, 2024

Thanks for the feature request, is there a way to upvote it?


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