Skip to content

Instantly share code, notes, and snippets.

@sharapeco
Created September 18, 2019 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharapeco/439a683fbefe4c775ffa736fa5402a18 to your computer and use it in GitHub Desktop.
Save sharapeco/439a683fbefe4c775ffa736fa5402a18 to your computer and use it in GitHub Desktop.
Google Fonts からダウンロードした Oswald-*.ttf の variant が全部 Regular になっているので修正する
## 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