mikaelvesavuori / figmagic

Figmagic is the missing piece between DevOps and design: Generate design tokens, export graphics, and extract design token-driven React components from your Figma documents.
https://docs.figmagic.com
MIT License
807 stars 71 forks source link

Figma erroneously sets certain font weights to 400 #151

Closed Julian-Rojo-Beezy closed 2 years ago

Julian-Rojo-Beezy commented 2 years ago

Describe the bug Font weight values are exported as "400" when there is a whitespace in their names in the Figma font-weight selector (e.g. in the "Inter" font).

To Reproduce

  1. Use any design-token enabled file, such as a duplicate of https://www.figma.com/community/file/821094451476848226.
  2. Change the font-weights and font-families to "Inter" font family (or any other family with whitespace in their font-weight options: "Extra Light", "Semi Bold", but not "ExtraLight" nor "SemiBold").
  3. Apply some of those weights, and optionally other without whitespace for comparison.
  4. Check in the "Inspect" Figma right panel, under the Typography section, how the weights are different according to the selected options.
  5. Run Figmagic and check the values of the fontWeights tokens. Those that have a whitespace in Figma are exported as 400 in all the cases.

Expected behavior The value of those tokens should be the same as the ones shown in the Typography section.

Screenshots imagen imagen imagen

Desktop (please complete the following information):

Additional context usePostscriptFontNames has no effect on the wrong weight values.

mikaelvesavuori commented 2 years ago

Hey!

Interesting. The code in Figmagic for this is rudimentary and fully expects that Figma's value is correct. Please see https://github.com/mikaelvesavuori/figmagic/blob/d4b37cb96bc0df8eb8ca64c6edf90ecce2907100/bin/entities/Token/logic/makeFontWeightTokens.ts#L39

I am indeed seeing the same behavior, for both Helvetica Neue and Inter. See below, for Inter, as I'm outputting the Figma frame data for font weights.

Writing Figma base file...

Writing design tokens...
---> {
  fontFamily: 'Inter',
  fontPostScriptName: 'Inter-Bold',
  fontWeight: 700,
  paragraphSpacing: 1,
  textAutoResize: 'WIDTH_AND_HEIGHT',
  fontSize: 16,
  textAlignHorizontal: 'LEFT',
  textAlignVertical: 'CENTER',
  letterSpacing: 0,
  lineHeightPx: 18.75,
  lineHeightPercent: 100,
  lineHeightUnit: 'INTRINSIC_%'
}

Figmagic completed operations successfully!

~/Web/figmagic   main ±  npm run figmagic

> figmagic@4.4.0 figmagic
> node build/index.js

Attempting to fetch data from Figma API...

Writing Figma base file...

Writing design tokens...
---> {
  fontFamily: 'Inter',
  fontPostScriptName: 'Inter-SemiBold',
  fontWeight: 400,
  paragraphSpacing: 1,
  textAutoResize: 'WIDTH_AND_HEIGHT',
  fontSize: 16,
  textAlignHorizontal: 'LEFT',
  textAlignVertical: 'CENTER',
  letterSpacing: 0,
  lineHeightPx: 18.75,
  lineHeightPercent: 100,
  lineHeightUnit: 'INTRINSIC_%'
}

Figmagic completed operations successfully!

~/Web/figmagic   main ±  npm run figmagic

> figmagic@4.4.0 figmagic
> node build/index.js

Attempting to fetch data from Figma API...

Writing Figma base file...

Writing design tokens...
---> {
  fontFamily: 'Inter',
  fontPostScriptName: 'Inter-ExtraLight',
  fontWeight: 400,
  paragraphSpacing: 1,
  textAutoResize: 'WIDTH_AND_HEIGHT',
  fontSize: 16,
  textAlignHorizontal: 'LEFT',
  textAlignVertical: 'CENTER',
  letterSpacing: 0,
  lineHeightPx: 18.75,
  lineHeightPercent: 100,
  lineHeightUnit: 'INTRINSIC_%'
}

Figmagic completed operations successfully!

~/Web/figmagic   main ±  npm run figmagic

> figmagic@4.4.0 figmagic
> node build/index.js

Attempting to fetch data from Figma API...

Writing Figma base file...

Writing design tokens...
---> {
  fontFamily: 'Inter',
  fontPostScriptName: 'Inter-Thin',
  fontWeight: 100,
  paragraphSpacing: 1,
  textAutoResize: 'WIDTH_AND_HEIGHT',
  fontSize: 16,
  textAlignHorizontal: 'LEFT',
  textAlignVertical: 'CENTER',
  letterSpacing: 0,
  lineHeightPx: 18.75,
  lineHeightPercent: 100,
  lineHeightUnit: 'INTRINSIC_%'
}

Figmagic completed operations successfully!

This seems to be an error on Figma's side, and I think the right course of action is to raise an issue in their support.

mikaelvesavuori commented 2 years ago

This seems to be the same thing, if also the font name has spaces, but the font style does not. Tried with Iowan Old Style, font style Titling: Came back as 400.

EDIT: Well my theory obviously does not hold up, given that the well-working Helvetica Neue also has a space in it.

Julian-Rojo-Beezy commented 2 years ago

Thanks for the information!

Yep, looks like the space in the family name doesn't trigger the problem: I checked with "Noto Sans" (space in family name, but not in weights) and the issue doesn't happen 2021-11-11_17h54_27

mikaelvesavuori commented 2 years ago

Is it OK to close this for now since it is not directly related to Figmagic?