summaryrefslogtreecommitdiff
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
parentd730ec25ef5899637e3d93ff5e6e0871cda88166 (diff)
Catch more glyphs when converting via FDK.
-rwxr-xr-xscripts/lib/fontbuild/features.py28
-rw-r--r--scripts/lib/fontbuild/saveOTF.py32
2 files changed, 49 insertions, 11 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."""
diff --git a/scripts/lib/fontbuild/saveOTF.py b/scripts/lib/fontbuild/saveOTF.py
index 3f03127..7c18fc4 100644
--- a/scripts/lib/fontbuild/saveOTF.py
+++ b/scripts/lib/fontbuild/saveOTF.py
@@ -1,10 +1,13 @@
import re
+
from fontTools.ttLib import newTable
from fontTools.ttLib.tables._c_m_a_p import cmap_format_12
from ufo2fdk import OTFCompiler
from ufo2fdk.makeotfParts import MakeOTFPartsCompiler
from ufo2fdk.outlineOTF import OutlineOTFCompiler
+from fontbuild.features import replaceFeatureFileReferences
+
def saveOTF(font, destFile, autohint=False):
"""Save a RoboFab font as an OTF binary using ufo2fdk."""
@@ -24,28 +27,35 @@ def conformToAGL(font, glyphList):
This function only checks for some Roboto-specific problems.
"""
- ligaNameChanges = {}
+ nameChanges = {}
for glyph in font:
- if glyph.name in glyphList:
+ name_components = glyph.name.split(".")
+ name = name_components.pop(0)
+ ext = ("." + name_components[0]) if name_components else ""
+ if name in glyphList:
continue
# if a ligature name (without underscores) is in the AGL, remove the
# underscores so AFDKO will keep the glyph in the font during conversion
#TODO(jamesgk) figure out why AFDKO throws out names with underscores
- if re.match("([a-z]_)+[a-z]", glyph.name):
- ligaName = glyph.name.replace("_", "")
+ if re.match("([a-z]_)+[a-z]", name):
+ ligaName = name.replace("_", "") + ext
if ligaName in glyphList:
- ligaNameChanges[glyph.name] = ligaName
- glyph.name = ligaName
+ nameChanges[glyph.name] = ligaName
continue
+ # use the glyph's unicode value as its name, if possible
+ if not re.match(r"u(ni)?[\dA-F]+", glyph.name) and glyph.unicode:
+ uvName = ("uni%04X" % glyph.unicode) + ext
+ nameChanges[glyph.name] = uvName
+
# names of glyphs outside the BMP must have prefix "u" and not "uni"
- glyph.name = re.sub(r"^uni([\dA-F]{5,})$", r"u\1", glyph.name)
+ if re.match(r"uni[\dA-F]{5,}", glyph.name):
+ nameChanges[glyph.name] = re.sub("^uni", "u", glyph.name)
- # references to altered ligature names must be updated in the font features
- #TODO(jamesgk) use a more robust system for parsing through RFont features
- for oldName, newName in ligaNameChanges.iteritems():
- font.features.text = font.features.text.replace(oldName, newName)
+ for oldName, newName in nameChanges.items():
+ font[oldName].name = newName
+ replaceFeatureFileReferences(font, nameChanges)
class _PartsCompilerCustomGlyphOrder(MakeOTFPartsCompiler):