summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Godfrey-Kittle <jamesgk@google.com>2015-03-02 18:19:52 -0800
committerJames Godfrey-Kittle <jamesgk@google.com>2015-04-16 12:16:31 -0700
commit0370954d363233e17b2ecd598894f9e50c6bc831 (patch)
treeac047685b24a5fe87717f36eac606aec61b68bda
parentee1d12f1819432c933ada834acd5ddadd0a1aaa1 (diff)
Split up glyphs with more than one unicode value.
This is necessary for OTF generation because ufo2fdk uses FontTools to compile cmaps, which uses a reverse lookup table of glyph names to unicode values.
-rw-r--r--scripts/lib/fontbuild/saveOTF.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/scripts/lib/fontbuild/saveOTF.py b/scripts/lib/fontbuild/saveOTF.py
index 51c3c61..6ae2d4a 100644
--- a/scripts/lib/fontbuild/saveOTF.py
+++ b/scripts/lib/fontbuild/saveOTF.py
@@ -1,9 +1,18 @@
-from ufo2fdk import OTFCompiler
-
-
def saveOTF(font, destFile, autohint=False):
"""Save a RoboFab font as an OTF binary using ufo2fdk."""
+ from ufo2fdk import OTFCompiler
+
+ # glyphs with multiple unicode values must be split up, due to FontTool's
+ # use of a name -> UV dictionary during cmap compilation
+ for glyph in font:
+ if len(glyph.unicodes) > 1:
+ newUV = glyph.unicodes.pop()
+ newGlyph = font.newGlyph("uni%04X" % newUV)
+ newGlyph.appendComponent(glyph.name)
+ newGlyph.unicode = newUV
+ newGlyph.width = glyph.width
+
compiler = OTFCompiler()
reports = compiler.compile(font, destFile, autohint=autohint)
if autohint: