def compileDecompileCompareDumps(features, expectedDump): # make the font font = Font() font.info.unitsPerEm = 1000 font.info.ascender = 750 font.info.descender = -250 font.info.xHeight = 500 font.info.capHeight = 750 font.info.familyName = "Test" font.info.styleName = "Regular" glyphNames = [i for i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"] for glyphName in glyphNames: font.newGlyph(glyphName) glyph = font[glyphName] glyph.unicode = AGL2UV.get(glyphName) font.features.text = features # compile to OTF handle, path = tempfile.mkstemp() compiler = OTFCompiler() errors = compiler.compile(font, path)["makeotf"] # extract the features try: tables = decompileBinaryToObject(path, compress=True) # print compiler errors except TTLibError: print errors # get rid of the temp file finally: os.remove(path) # dump writer = DumpWriter() tables["GSUB"].write(writer) dump = writer.dump() # compare compareDumps(expectedDump, dump)
def saveOTF(font, destFile, autohint=False): """Save a RoboFab font as an OTF binary using ufo2fdk. Returns True on success, False otherwise. """ 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: print reports["autohint"] print reports["makeotf"] successMsg = "makeotfexe [NOTE] Wrote new font file '%s'." % os.path.basename(destFile) return successMsg in reports["makeotf"]
def saveOTF(font, destFile, autohint=False): """Save a RoboFab font as an OTF binary using ufo2fdk. Returns True on success, False otherwise. """ 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: print reports["autohint"] print reports["makeotf"] successMsg = ("makeotfexe [NOTE] Wrote new font file '%s'." % os.path.basename(destFile)) return successMsg in reports["makeotf"]
def compile_otf(font, release_mode=False, autohint=False, debug=False): """Compile UFO into a CFF TTFont instance.""" compiler = OTFCompiler(savePartsNextToUFO=debug) fd, tmpfile = tempfile.mkstemp() try: os.close(fd) report = compiler.compile( font, tmpfile, releaseMode=release_mode, autohint=autohint, glyphOrder=font.glyphOrder) ttFont = TTFont(tmpfile) finally: os.remove(tmpfile) if autohint: logging.info(report["autohint"]) logging.info(report["makeotf"]) return ttFont
def writeOtf(rffont, otfFile): rffont.update() rffont.autoUnicodes() rffont.update() from ufo2fdk import haveFDK from ufo2fdk import OTFCompiler if haveFDK(): print "I found the FDK!" else: print "I'm sorry, I could not find the FDK." compiler = OTFCompiler() reports = compiler.compile(rffont, otfFile, checkOutlines=True, autohint=True) # reports = compiler.compile(font, dstFile, checkOutlines=True, autohint=False) print reports["checkOutlines"] print reports["autohint"] print reports["makeotf"]