diff options
author | James Godfrey-Kittle <jamesgk@google.com> | 2015-02-18 10:19:11 -0800 |
---|---|---|
committer | James Godfrey-Kittle <jamesgk@google.com> | 2015-04-16 12:16:29 -0700 |
commit | 4b6f8d9a34d1f20cdc0cd29a761ca875820761f4 (patch) | |
tree | 48319d37017a9735b9de92a46bd87498e19ddb73 /scripts/lib/fontbuild/features.py | |
parent | d730ec25ef5899637e3d93ff5e6e0871cda88166 (diff) |
Catch more glyphs when converting via FDK.
Diffstat (limited to 'scripts/lib/fontbuild/features.py')
-rwxr-xr-x | scripts/lib/fontbuild/features.py | 28 |
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."""
|