summaryrefslogtreecommitdiff
path: root/scripts/lib/fontbuild/features.py
diff options
context:
space:
mode:
authorJames Godfrey-Kittle <jamesgk@google.com>2015-02-18 10:19:11 -0800
committerJames Godfrey-Kittle <jamesgk@google.com>2015-04-16 12:16:29 -0700
commit4b6f8d9a34d1f20cdc0cd29a761ca875820761f4 (patch)
tree48319d37017a9735b9de92a46bd87498e19ddb73 /scripts/lib/fontbuild/features.py
parentd730ec25ef5899637e3d93ff5e6e0871cda88166 (diff)
Catch more glyphs when converting via FDK.
Diffstat (limited to 'scripts/lib/fontbuild/features.py')
-rwxr-xr-xscripts/lib/fontbuild/features.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/scripts/lib/fontbuild/features.py b/scripts/lib/fontbuild/features.py
index 681d6ed..5184c9f 100755
--- a/scripts/lib/fontbuild/features.py
+++ b/scripts/lib/fontbuild/features.py
@@ -100,6 +100,34 @@ def _isValidRef(referencer, ref, font):
return True
+def replaceFeatureFileReferences(font, replace):
+ """Replace references according to a given mapping of old names to new."""
+
+ lines = font.features.text.splitlines()
+ for i, line in enumerate(lines):
+
+ # check for reference in class definitions
+ if _classDef.match(line):
+ name, value = _classDef.match(line).groups()
+ value = " ".join([replace.get(n, n) for n in value.split()])
+ lines[i]= "%s = [%s];" % (name, value)
+
+ # check in substitution rules
+ elif _subRule.match(line):
+ indentation, subbed, sub = _subRule.match(line).groups()
+ subbed = " ".join([replace.get(n, n) for n in subbed.split()])
+ sub = " ".join([replace.get(n, n) for n in sub.split()])
+
+ # put brackets around tokens if they were there before
+ if re.match(r"\s*sub(stitute)?\s+\[.+\]\s+by", line):
+ subbed = "[%s]" % subbed
+ if re.match(r"\s*sub(stitute)?.+by\s+\[.+\]\s*;", line):
+ sub = "[%s]" % sub
+ lines[i] = "%ssub %s by %s;" % (indentation, subbed, sub)
+
+ font.features.text = "\n".join(lines)
+
+
def generateFeatureFile(font):
"""Populate a font's feature file text from its classes and features."""