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

feat: font variation settings (wip) #36371

Closed
wants to merge 6 commits into from

Conversation

matinzd
Copy link
Contributor

@matinzd matinzd commented Mar 4, 2023

Summary

This PR adds font variation settings feature for variable fonts in react native. The fontVariationSettings property provides low-level control over variable font characteristics, by specifying the four letter axis names of the characteristics you want to vary, along with their values.

Registered axes are the most commonly encountered — common enough that the authors of the specification felt they were worth standardizing. Note that this doesn't mean that the author has to include all of these in their font.

Custom axes can be anything the font designer wants to vary in their font, for example ascender or descender heights, the size of serifs, or anything else they can imagine. Any axis can be used as long as it is given a unique 4-character axis. Some will end up becoming more common, and may even become registered over time.

Example:

<Text
  style={{
    fontFamily: 'MaterialSymbolsSharp',
    fontVariationSettings: "'wght' 100, 'FILL' 0",
  }}>
  {String.fromCodePoint(59576)}
</Text>

Font characteristics set using fontVariationSettings will always override those set using the corresponding basic font properties, e.g. fontWeight regardless of the order.

Android reference: https://developer.android.com/reference/android/graphics/fonts/FontVariationAxis
iOS reference: https://developer.apple.com/documentation/coretext/kctfontvariationattribute
MDN reference: https://developer.mozilla.org/en-US/docs/Web/CSS/font-variation-settings
Spec: https://learn.microsoft.com/en-us/typography/opentype/spec/otvaroverview

Changelog

[General] [Added] - add fontVariationSettings support for variable font

Test Plan

TBD

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 4, 2023
@matinzd matinzd changed the title feat: font variation settings feat: font variation settings (wip) Mar 4, 2023
@react-native-bot react-native-bot added the Type: Enhancement A new feature or enhancement of an existing feature. label Mar 4, 2023
@analysis-bot
Copy link

analysis-bot commented Mar 4, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 10,890,932 +2,371,933
android hermes armeabi-v7a 10,206,825 +2,372,307
android hermes x86 11,373,021 +2,373,698
android hermes x86_64 11,226,214 +2,371,625
android jsc arm64-v8a 11,514,570 +2,371,967
android jsc armeabi-v7a 10,706,288 +2,372,331
android jsc x86 11,571,079 +2,373,716
android jsc x86_64 11,827,121 +2,371,661

Base commit: cfa03db
Branch: main

@matinzd
Copy link
Contributor Author

matinzd commented Mar 6, 2023

Your comments are welcome regarding the implementation! @NickGerleman @cortinico

@matinzd matinzd force-pushed the feat/font_variation_settings branch from bb4dee0 to 50d0f73 Compare March 6, 2023 11:39
@matinzd matinzd force-pushed the feat/font_variation_settings branch from 50d0f73 to 38692ac Compare March 12, 2023 14:12
@NicoCaro-io
Copy link

Any luck on pushing this @matinzd ?

@shenghan97
Copy link

@matinzd hey! is this pr close to ready for review?

@davebcn87
Copy link

Also interested on this. Any way I can help make some progress here @matinzd?

@matinzd
Copy link
Contributor Author

matinzd commented May 7, 2024

I was away for some time from the community. I will try to see if I can continue. There has been a lot of conflicts since then :)

I may need to open a new PR.

@davebcn87
Copy link

@matinzd if you need any help I can give a hand on this task

@matinzd
Copy link
Contributor Author

matinzd commented May 8, 2024

@davebcn87 Sure! I am up for it. Try to see if you have push access on my branch. We can work on it together. My username is the same on Discord if you want to continue the conversation further.

@davebcn87
Copy link

awesome, let's chat on Discord then. Maybe it be nice we start a nice branch as you mentioned so we avoid all the conflicts.

@davebcn87
Copy link

Got some progress on iOS side, all the variations that I tried and that the variable font supports work for now:

<Text style={{fontFamily: 'Inter', fontVariationSettings: '"wght" 100'}}>Inter wght 100</Text>
<Text style={{fontFamily: 'Inter', fontVariationSettings: '"wght" 150'}}>Inter wght 150</Text>
 ...
<Text style={{fontFamily: 'Inter', fontVariationSettings: '"wght" 750'}}>Inter wght 750</Text>
<Text style={{fontFamily: 'Inter', fontVariationSettings: '"wght" 800'}}>Inter wght 800</Text>
<Text style={{fontFamily: 'Inter', fontVariationSettings: "'wght' 700"}}>Inter wght 1000</Text>
<Text style={{fontFamily: 'Inter', fontVariant: ['tabular-nums'], fontVariationSettings: "'wght' 700"}}>Inter wght 1000 w/ tabular-nums</Text>
<Text style={{fontFamily: 'Amstelvar', fontVariationSettings: "'wght' 700, 'wdth' 60"}}>Amstelvar wght 700 wdth 60</Text>
<Text style={{fontFamily: 'Amstelvar', fontVariationSettings: "'wght' 700, 'wdth' 120"}}>Amstelvar wght 700 wdth 120</Text>
<Text style={{fontFamily: 'Amstelvar', fontVariationSettings: "'wght' 700, 'opsz' 12"}}>Amstelvar wght 700 opsz 12</Text>
<Text style={{fontFamily: 'Amstelvar', fontVariationSettings: "'wght' 700, 'opsz' 32"}}>Amstelvar wght 700 opsz 32</Text>

Simulator Screenshot - iPhone 15 Pro - 2024-05-23 at 17 28 20

@matinzd
Copy link
Contributor Author

matinzd commented May 23, 2024

Follow here for the updated PR: #44667

@matinzd matinzd closed this May 23, 2024
@matinzd matinzd deleted the feat/font_variation_settings branch May 23, 2024 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants