Created
March 11, 2023 16:23
-
-
Save natintosh/cdf57521d3ba4c26a3b04b522e79a17c to your computer and use it in GitHub Desktop.
Custom fonts CookBook example not working as expected flutter/website#3591 Based on what @jason-simmons mentioned, I created the following python script to "fix" your custom font files to use the correct weights that flutter respects. Create a src directory and put all your fonts in there. Create an empty out directory and the script will place …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from fontTools import ttLib | |
# Declare your font file names and the correct weights here | |
to_change = { | |
'Galano Grotesque Thin.otf': 100, | |
'Galano Grotesque Thin Italic.otf': 100, | |
'Galano Grotesque Extra Light.otf': 200, | |
'Galano Grotesque Extra Light Italic.otf': 200, | |
'Galano Grotesque Light.otf': 300, | |
'Galano Grotesque Light Italic.otf': 300, | |
'Galano Grotesque Regular.otf': 400, | |
'Galano Grotesque Regular Italic.otf': 400, | |
'Galano Grotesque Medium.otf': 500, | |
'Galano Grotesque Medium Italic.otf': 500, | |
'Galano Grotesque Semi Bold.otf': 600, | |
'Galano Grotesque Semi Bold Italic.otf': 600, | |
'Galano Grotesque Bold.otf': 700, | |
'Galano Grotesque Bold Italic.otf': 700, | |
'Galano Grotesque Extra Bold.otf': 800, | |
'Galano Grotesque Extra Bold Italic.otf': 800, | |
'Galano Grotesque Black.otf': 900, | |
'Galano Grotesque Black Italic.otf': 900, | |
} | |
for file, weight in to_change.items(): | |
with ttLib.TTFont(os.path.join('src', file)) as tt: | |
tt['OS/2'].usWeightClass = weight | |
tt.save(os.path.join('out',file)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment