Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

font-stretch/weight not exporting #241

Open
MafialDR opened this issue Feb 27, 2023 · 3 comments
Open

font-stretch/weight not exporting #241

MafialDR opened this issue Feb 27, 2023 · 3 comments

Comments

@MafialDR
Copy link

MafialDR commented Feb 27, 2023

We recently started using a variable font and need to use the font-stretch/weight attribute. Even thought it is assigned it doesn't export properly to the JSON.

In Figma :

Screen Shot 2023-02-27 at 11 33 17

Exported JSON:

Screen Shot 2023-02-27 at 11 35 59

@MafialDR MafialDR changed the title font-stretch not exporting font-stretch/weight not exporting Feb 27, 2023
@lukasoppermann
Copy link
Owner

Hey, this is interesting.

The problem is that the plugin is not setup to deal with variable fonts.

For the fontweight, this line would need to be changed:

https://github.com/lukasoppermann/design-tokens/blob/main/src/extractor/extractFonts.ts#L80 to return the input value if it does not find one in the matrix.

best would be to check if it is a number before.

For fontStretch its this line: https://github.com/lukasoppermann/design-tokens/blob/main/src/extractor/extractFonts.ts#L85

I don't know if it always says "CTGR" for variable fonts? If it does this could be something to look for.

@MafialDR would you be able to send a PR for this. I am happy to support you on it.

@MafialDR
Copy link
Author

MafialDR commented Mar 7, 2023

Hello @lukasoppermann,

Thank you for the response.

After discussion with my team, le "CTGR" is juste something on our end. For the rest, I looked over the code and belive to have found a solution but do not have access to commit my code.

Here is what I think would fix the problem :

const parseFontWeight = (fontStyle: any): number => {
  if(Number.isInteger(fontStyle)){
    return fontStyle
  }
  const parts = fontStyle.toLowerCase().split(' ')
  ...
  return fontWeights[weight] || 400
}

const parseFontStretch = (fontStyle: any): FontStretch => {
  if(Number.isInteger(fontStyle)){
    return fontStyle
  }
  const parts = fontStyle.toLowerCase().split(' ')
  return fontStretch[parts[parts.length - 1]] || fontStretch[parts[parts.length - 2]] || 'normal' as FontStretch
}

@lukasoppermann
Copy link
Owner

Hey @MafialDR I had a moment to look into it now, and sadly it does not work like this. :(

Don't as me why figma does it this way, but the data from the inspect panel is not what you get out of the API.

The variable font data is not available in the API. https://www.figma.com/plugin-docs/api/TextStyle#textstyle

The only I currently get the weight and style is by parsing the fontName property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants