Created
September 18, 2019 06:29
-
-
Save sharapeco/439a683fbefe4c775ffa736fa5402a18 to your computer and use it in GitHub Desktop.
Google Fonts からダウンロードした Oswald-*.ttf の variant が全部 Regular になっているので修正する
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
## Google Fonts からダウンロードした Oswald-*.ttf の variant が全部 Regular になっているので修正する | |
## | |
## Requires: | |
## pip install fonttools | |
import sys | |
from fontTools.ttLib import TTFont | |
weights = [ | |
'ExtraLight', | |
'Light', | |
'Regular', | |
'Medium', | |
'SemiBold', | |
'Bold', | |
] | |
for weight in weights: | |
font = TTFont('src/Oswald-' + weight + '.ttf') | |
namerecord_list = font["name"].names | |
for record in namerecord_list: | |
if record.nameID == 2: | |
record.string = weight | |
break | |
output_path = 'dest/Oswald-' + weight + '.ttf' | |
try: | |
font.save(output_path) | |
except Exception as e: | |
sys.stderr.write('ERROR: unable to write "' + output_path + '"') | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment