diff options
Diffstat (limited to 'scripts/lib/fontbuild/saveOTF.py')
-rw-r--r-- | scripts/lib/fontbuild/saveOTF.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/scripts/lib/fontbuild/saveOTF.py b/scripts/lib/fontbuild/saveOTF.py index b2a6483..25c9dea 100644 --- a/scripts/lib/fontbuild/saveOTF.py +++ b/scripts/lib/fontbuild/saveOTF.py @@ -9,11 +9,6 @@ from ufo2fdk.outlineOTF import OutlineOTFCompiler def saveOTF(font, destFile, checkOutlines=False, autohint=False): """Save a RoboFab font as an OTF binary using ufo2fdk.""" - # according to the AGL spec, names of glyphs outside the BMP must have - # prefix "u" and not "uni": http://sourceforge.net/adobe/aglfn/aglspec - for glyph in font: - glyph.name = re.sub(r"uni([\dA-F]{5,})", r"u\1", glyph.name) - compiler = OTFCompiler(partsCompilerClass=_PartsCompilerBlankGlyphOrder, outlineCompilerClass=_OutlineCompilerFormat12) reports = compiler.compile(font, destFile, checkOutlines=checkOutlines, @@ -25,6 +20,35 @@ def saveOTF(font, destFile, checkOutlines=False, autohint=False): print reports["makeotf"] +def conformToAGL(font, glyphList): + """Ensure a font's glyph names conform to the AGL specification. + + The spec is described at http://sourceforge.net/adobe/aglfn/aglspec. + This function only checks for some Roboto-specific problems. + """ + + ligaNameChanges = {} + for glyph in font: + if glyph.name in glyphList: + continue + + # ligature names cannot contain underscores between components + if re.match("([a-z]_)+[a-z]", glyph.name): + ligaName = glyph.name.replace("_", "") + if ligaName in glyphList: + ligaNameChanges[glyph.name] = ligaName + glyph.name = ligaName + continue + + # 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) + + # 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) + + class _PartsCompilerBlankGlyphOrder(MakeOTFPartsCompiler): """Child class of parts compiler which produces a blank glyph order file. |