summaryrefslogtreecommitdiff
path: root/scripts/lib/fontbuild/features.py
diff options
context:
space:
mode:
authorJames Godfrey-Kittle <jamesgk@google.com>2015-03-05 12:44:54 -0800
committerJames Godfrey-Kittle <jamesgk@google.com>2015-04-16 12:16:32 -0700
commit56f51cda42125bb0c8612007917bf58d4c3c038c (patch)
tree88db3ec5ec2a0eab1524838637104ccf91b320c5 /scripts/lib/fontbuild/features.py
parent15a678c34e3606e65c436c77c74b04539e2e14bb (diff)
Make feature creation compatible with features.py.
Specifically the "mark" and "mkmk" features.
Diffstat (limited to 'scripts/lib/fontbuild/features.py')
-rwxr-xr-xscripts/lib/fontbuild/features.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/scripts/lib/fontbuild/features.py b/scripts/lib/fontbuild/features.py
index 3b52f76..2de484d 100755
--- a/scripts/lib/fontbuild/features.py
+++ b/scripts/lib/fontbuild/features.py
@@ -150,6 +150,23 @@ class FilterFeatureWriter(FDKSyntaxFeatureWriter):
super(FilterFeatureWriter, self).languageSystem(langTag, scriptTag)
+def compileFeatureRE(name):
+ """Compiles a feature-matching regex using feaTool's template."""
+ featureRE = list(parser.featureContentRE)
+ featureRE.insert(2, name)
+ featureRE.insert(6, name)
+ return re.compile("".join(featureRE))
+
+
+def updateFeature(font, name, value):
+ """Add a feature definition, or replace existing one."""
+ featureRE = compileFeatureRE(name)
+ if featureRE.search(font.features.text):
+ font.features.text = featureRE.sub(value, font.features.text)
+ else:
+ font.features.text += "\n" + value
+
+
def readFeatureFile(font, text):
"""Incorporate valid definitions from feature text into font."""
writer = FilterFeatureWriter(set(font.keys()))