diff options
author | James Godfrey-Kittle <jamesgk@google.com> | 2015-02-04 16:43:21 -0800 |
---|---|---|
committer | James Godfrey-Kittle <jamesgk@google.com> | 2015-04-16 12:16:28 -0700 |
commit | 3b5e819a1428c9a5525cb8ee5125f6d25638bd91 (patch) | |
tree | 7217efe827309b227e731ed2d1709cafd447dfa6 /scripts/lib | |
parent | be9e3102a3be630e2593c594a64e598f00256548 (diff) |
Ensure font conforms to AGL before OTF conversion
Diffstat (limited to 'scripts/lib')
-rw-r--r-- | scripts/lib/fontbuild/Build.py | 28 | ||||
-rw-r--r-- | scripts/lib/fontbuild/saveOTF.py | 34 |
2 files changed, 45 insertions, 17 deletions
diff --git a/scripts/lib/fontbuild/Build.py b/scripts/lib/fontbuild/Build.py index 94c2031..1646a8b 100644 --- a/scripts/lib/fontbuild/Build.py +++ b/scripts/lib/fontbuild/Build.py @@ -12,7 +12,7 @@ from fontbuild.markFeature import GenerateFeature_mark from fontbuild.mkmkFeature import GenerateFeature_mkmk from fontbuild.decomposeGlyph import decomposeGlyph from fontbuild.removeGlyphOverlap import removeGlyphOverlap -from fontbuild.saveOTF import saveOTF +from fontbuild.saveOTF import saveOTF, conformToAGL from fontbuild.sortGlyphs import sortGlyphsByUnicode import ConfigParser import os @@ -33,6 +33,8 @@ class FontProject: self.ot_classes = open(self.basedir + "/" + self.config.get("res","ot_classesfile")).read() self.ot_kerningclasses = open(self.basedir + "/" + self.config.get("res","ot_kerningclassesfile")).read() self.ot_features = open(self.basedir + "/" + self.config.get("res","ot_featuresfile")).read() + adobeGlyphList = open(self.basedir + "/" + self.config.get("res", "agl_glyphlistfile")).readlines() + self.adobeGlyphList = set([line.split(";")[0] for line in adobeGlyphList if not line.startswith("#")]) self.builddir = "out" self.decompose = self.config.get("glyphs","decompose").split() @@ -141,17 +143,18 @@ class FontProject: cleanCurves(f) deleteGlyphs(f, self.deleteList) -# if kern: -# log(">> Generating kern classes") -# generateFLKernClassesFromOTString(f, self.ot_kerningclasses) -# kern = f.MakeKernFeature() -# kern_exist = False -# for fea_id in range (len(f.features)): -# if "kern" == f.features[fea_id].tag: -# f.features[fea_id] = kern -# kern_exist = True -# if False == kern_exist: -# f.features.append(kern) + #TODO(jamesgk) create a system for generating RFont features and classes + #if kern: + # log(">> Generating kern classes") + # generateFLKernClassesFromOTString(f, self.ot_kerningclasses) + # kern = f.MakeKernFeature() + # kern_exist = False + # for fea_id in range (len(f.features)): + # if "kern" == f.features[fea_id].tag: + # f.features[fea_id] = kern + # kern_exist = True + # if False == kern_exist: + # f.features.append(kern) directoryName = n[0].replace(" ", "") fontName = "%s-%s" % (f.info.familyName.replace(" ", ""), @@ -167,6 +170,7 @@ class FontProject: if self.buildOTF: log(">> Generating OTF file") newFont = OpenFont(ufoName) + conformToAGL(newFont, self.adobeGlyphList) directoryPath = "%s/%s/%sOTF" % (self.basedir, self.builddir, directoryName) if not os.path.exists(directoryPath): 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. |