Work-Sans/sources/tools/replaceBracketTrick.py
weiweihuanghuang 616f74fb43 Update Build
2018-11-15 16:18:09 +08:00

62 lines
2.7 KiB
Python
Executable File

### Based on a script by Stephen Nixon
import os
import sys
import fontTools
from fontTools.ttLib import TTFont
from fontTools.varLib.featureVars import addFeatureVariations
inputTTF = sys.argv[1]
# style = sys.argv[2]
f = TTFont(inputTTF)
if "Italic" in inputTTF:
condSubst = [
# A list of (Region, Substitution) tuples.
([{"wght": (.81, 1)}], {"uni20B5": "uni20B5.rvrn", # cedi
"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",
"uni20A9": "uni20A9.rvrn"}), # won
([{"wght": (0.38, 1)}], {"uni20A6": "uni20A6.rvrn", # naira,
"colonmonetary": "colonmonetary.rvrn"}),
([{"wght": (0.178, 1)}], {"uni20B1": "uni20B1.rvrn"}), # peso
([{"wght": (0, 1)}], {"uni2761": "uni2761.rvrn", # curvedStemParagraphSignOrnament
"paragraph": "paragraph.rvrn"}) # won
]
else:
condSubst = [
# A list of (Region, Substitution) tuples.
([{"wght": (-.47, .18)}], {"uniF8FF": "uniF8FF.rvrn"}), # apple
([{"wght": (.81, 1)}], {"uni20B5": "uni20B5.rvrn", # cedi
"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",
"uni20A9": "uni20A9.rvrn"}), # won
([{"wght": (0.38, 1)}], {"uni20A6": "uni20A6.rvrn", # naira,
"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"}),
([{"wght": (0.178, 1)}], {"uni20B1": "uni20B1.rvrn"}), # peso
([{"wght": (0, 1)}], {"uni2761": "uni2761.rvrn", # curvedStemParagraphSignOrnament
"paragraph": "paragraph.rvrn"}) # won
]
addFeatureVariations(f, condSubst)
outputTTF = inputTTF.replace('.ttf', '-swap.ttf')
f.save(outputTTF)