def _getTempOTF(self, path, report=None, preserveTTFhints=False): if not hasattr(self, "_tempOTFPath"): _, ext = os.path.splitext(path) ext = ext.lower() self._tempOTFPath = tempfile.mkstemp(suffix=".otf")[1] if ext == ".otf": report.write("Source is binary a OTF file.") shutil.copyfile(path, self._tempOTFPath) if not preserveTTFhints: report.write("Auto hint the existing OTF file.") report.indent() result = OTFAutohint(self._tempOTFPath) report.writeItems(result) report.dedent() elif ext == ".ttf": report.write("Source is binary a TTF file. Convert to OTF.") report.indent() convertToOTF(path, self._tempOTFPath, report) report.dedent() else: if ext == ".ufo": report.write("Source is a UFO file. Generate OTF.") else: report.write( "Source is a %s file. Import the file. Generate OTF." % (ext[1:])) report.indent() generateOTF(path, self._tempOTFPath, report) report.dedent() return self._tempOTFPath
def convertToOTF(ttfPath, dest, report): temp = tempfile.mkstemp(suffix=".otf")[1] font = RFont(ttfPath, document=False, showInterface=False) font.kerning.clear() for attr in font.info.asDict().keys(): if attr not in defaultFontInfoAttributes: setattr(font.info, attr, None) result = font.generate(path=temp, format="otf", decompose=False, checkOutlines=False, autohint=False, releaseMode=True, glyphOrder=font.glyphOrder) if not font.hasInterface(): font.close() report.write(result) sourceFont = TTFont(temp) sourceFontWithTables = TTFont(ttfPath) for table in [ "loca", "OS/2", "cmap", "name", "GSUB", "GPOS", "GDEF", "kern" ]: if table in sourceFontWithTables: sourceFont[table] = sourceFontWithTables[table] sourceFont.save(dest) result = OTFAutohint(dest) report.writeItems(result) os.remove(temp)
def generateOTF(ufoPath, dest, report): font = OpenFont(ufoPath, showUI=False) result = font.generate(path=dest, format="otf", decompose=False, checkOutlines=True, autohint=False, releaseMode=True, glyphOrder=font.glyphOrder) font.close() report.write(result) result = OTFAutohint(dest) report.writeItems(result)
def generateOTF(ufoPath, dest, report): font = RFont(ufoPath, document=False, showInterface=False) result = font.generate(path=dest, format="otf", decompose=False, checkOutlines=True, autohint=False, releaseMode=True, glyphOrder=font.glyphOrder) if not font.hasInterface(): font.close() report.write(result) result = OTFAutohint(dest) report.writeItems(result)