Work-Sans/sources/tools/replaceBracketTrick.py

62 lines
2.7 KiB
Python
Raw Normal View History

2018-11-07 11:05:48 +03:00
### Based on a script by Stephen Nixon
import os
import sys
import fontTools
from fontTools.ttLib import TTFont
from fontTools.varLib.featureVars import addFeatureVariations
2018-11-08 13:36:47 +03:00
inputTTF = sys.argv[1]
2018-11-15 07:54:13 +03:00
# style = sys.argv[2]
2018-11-07 11:05:48 +03:00
2018-11-08 02:25:24 +03:00
f = TTFont(inputTTF)
2018-11-15 07:54:13 +03:00
if "Italic" in inputTTF:
2018-11-09 14:27:09 +03:00
condSubst = [
# A list of (Region, Substitution) tuples.
2018-11-15 11:18:09 +03:00
([{"wght": (.81, 1)}], {"uni20B5": "uni20B5.rvrn", # cedi
2018-11-12 19:42:47 +03:00
"cent": "cent.rvrn",
"dollar": "dollar.rvrn",
"uni20B2": "uni20B2.rvrn", # guarani
"dollar.tf": "dollar.tf.rvrn",
"cent.tf": "cent.tf.rvrn"}),
([{"wght": (0.6, 1)}], {"peseta": "peseta.rvrn",
2018-11-15 11:18:09 +03:00
"uni20A9": "uni20A9.rvrn"}), # won
2018-11-12 19:42:47 +03:00
([{"wght": (0.38, 1)}], {"uni20A6": "uni20A6.rvrn", # naira,
2018-11-15 07:54:13 +03:00
"colonmonetary": "colonmonetary.rvrn"}),
2018-11-15 11:18:09 +03:00
([{"wght": (0.178, 1)}], {"uni20B1": "uni20B1.rvrn"}), # peso
([{"wght": (0, 1)}], {"uni2761": "uni2761.rvrn", # curvedStemParagraphSignOrnament
"paragraph": "paragraph.rvrn"}) # won
2018-11-09 14:27:09 +03:00
]
2018-11-12 19:42:47 +03:00
2018-11-15 07:54:13 +03:00
else:
2018-11-09 14:27:09 +03:00
condSubst = [
# A list of (Region, Substitution) tuples.
2018-11-15 11:18:09 +03:00
([{"wght": (-.47, .18)}], {"uniF8FF": "uniF8FF.rvrn"}), # apple
2018-11-15 07:54:13 +03:00
([{"wght": (.81, 1)}], {"uni20B5": "uni20B5.rvrn", # cedi
2018-11-12 19:42:47 +03:00
"cent": "cent.rvrn",
"dollar": "dollar.rvrn",
"uni20B2": "uni20B2.rvrn", # guarani
"dollar.tf": "dollar.tf.rvrn",
"cent.tf": "cent.tf.rvrn"}),
([{"wght": (0.6, 1)}], {"peseta": "peseta.rvrn",
2018-11-15 11:18:09 +03:00
"uni20A9": "uni20A9.rvrn"}), # won
2018-11-12 19:42:47 +03:00
([{"wght": (0.38, 1)}], {"uni20A6": "uni20A6.rvrn", # naira,
2018-11-15 07:54:13 +03:00
"colonmonetary": "colonmonetary.rvrn", # colon
"Adieresis": "Adieresis.rvrn",
"Adieresis.titl": "Adieresis.titl.rvrn",
"Odieresis.titl": "Odieresis.titl.rvrn",
"Odieresis": "Odieresis.rvrn",
"Udieresis": "Udieresis.rvrn",
"Udieresis.titl": "Udieresis.titl.rvrn"}),
2018-11-15 11:18:09 +03:00
([{"wght": (0.178, 1)}], {"uni20B1": "uni20B1.rvrn"}), # peso
([{"wght": (0, 1)}], {"uni2761": "uni2761.rvrn", # curvedStemParagraphSignOrnament
"paragraph": "paragraph.rvrn"}) # won
2018-11-09 14:27:09 +03:00
]
2018-11-07 11:05:48 +03:00
addFeatureVariations(f, condSubst)
2018-11-08 02:25:24 +03:00
outputTTF = inputTTF.replace('.ttf', '-swap.ttf')
2018-11-09 14:27:09 +03:00
f.save(outputTTF)