summaryrefslogtreecommitdiff
path: root/scripts/lib
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
parent15a678c34e3606e65c436c77c74b04539e2e14bb (diff)
Make feature creation compatible with features.py.
Specifically the "mark" and "mkmk" features.
Diffstat (limited to 'scripts/lib')
-rwxr-xr-xscripts/lib/fontbuild/features.py17
-rwxr-xr-xscripts/lib/fontbuild/markFeature.py7
-rwxr-xr-xscripts/lib/fontbuild/mkmkFeature.py7
3 files changed, 25 insertions, 6 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()))
diff --git a/scripts/lib/fontbuild/markFeature.py b/scripts/lib/fontbuild/markFeature.py
index c966085..e2e36c1 100755
--- a/scripts/lib/fontbuild/markFeature.py
+++ b/scripts/lib/fontbuild/markFeature.py
@@ -1,3 +1,6 @@
+from fontbuild.features import updateFeature
+
+
aliases = [["uni0430", "a"], ["uni0435", "e"], ["uni0440", "p"], ["uni0441", "c"], ["uni0445", "x"], ["uni0455", "s"], ["uni0456", "i"], ["uni0471", "psi"]]
def GetAliaseName(gname):
@@ -79,6 +82,4 @@ def GenerateFeature_mark(font):
text += "} mark;\n"
- if "mark" not in font.features.tags:
- font.features.tags.append("mark")
- font.features.values["mark"] = text
+ updateFeature(font, "mark", text)
diff --git a/scripts/lib/fontbuild/mkmkFeature.py b/scripts/lib/fontbuild/mkmkFeature.py
index e2195f5..a839dae 100755
--- a/scripts/lib/fontbuild/mkmkFeature.py
+++ b/scripts/lib/fontbuild/mkmkFeature.py
@@ -1,3 +1,6 @@
+from fontbuild.features import updateFeature
+
+
def CreateAccNameList(font, acc_anchor_name):
lst = []
for g in font:
@@ -56,6 +59,4 @@ def GenerateFeature_mkmk(font):
text += "} mkmk;\n"
- if "mkmk" not in font.features.tags:
- font.features.tags.append("mkmk")
- font.features.values["mkmk"] = text
+ updateFeature(font, "mkmk", text)