def open(self, use_hash_map): font_path = self.font_path if self.font_format == 'UFO': self.font_type = UFO_FONT_TYPE ufotools.validateLayers(font_path) self.defcon_font = defcon.Font(font_path) self.ufo_format = self.defcon_font.ufoFormatVersionTuple self.use_hash_map = use_hash_map self.ufo_font_hash_data = ufotools.UFOFontData( font_path, self.use_hash_map, programName=ufotools.kCheckOutlineName) self.ufo_font_hash_data.readHashMap() else: print("Converting to temp UFO font...") self.temp_ufo_path = temp_path = get_temp_dir_path('font.ufo') if not run_shell_command(['tx', '-ufo', font_path, temp_path]): raise FocusFontError('Failed to convert input font to UFO.') try: self.defcon_font = defcon.Font(temp_path) except UFOLibError: raise if self.font_format == 'OTF': self.font_type = OTF_FONT_TYPE elif self.font_format == 'CFF': self.font_type = CFF_FONT_TYPE else: self.font_type = TYPE1_FONT_TYPE return self.defcon_font
def open(self, use_hash_map): font_path = self.font_path try: ufotools.validateLayers(font_path) self.defcon_font = defcon.Font(font_path) self.ufo_format = self.defcon_font.ufoFormatVersion if self.ufo_format < 2: self.ufo_format = 2 self.font_type = UFO_FONT_TYPE self.use_hash_map = use_hash_map self.ufo_font_hash_data = ufotools.UFOFontData( font_path, self.use_hash_map, programName=ufotools.kCheckOutlineName) self.ufo_font_hash_data.readHashMap() except ufoLib.UFOLibError as e: if (not os.path.isdir(font_path)) \ and "metainfo.plist is missing" in e.message: # It was a file, but not a UFO font. # Try converting to UFO font, and try again. print("converting to temp UFO font...") self.temp_ufo_path = temp_path = font_path + ".temp.ufo" if os.path.exists(temp_path): shutil.rmtree(temp_path) cmd = "tx -ufo \"%s\" \"%s\"" % (font_path, temp_path) subprocess.call(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if os.path.exists(temp_path): try: self.defcon_font = defcon.Font(temp_path) except ufoLib.UFOLibError: return # It must be a font file! self.temp_ufo_path = temp_path # figure out font type. try: ff = open(font_path, "rb") data = ff.read(10) ff.close() except (IOError, OSError): return if data[:4] == "OTTO": # it is an OTF font. self.font_type = OPENTYPE_CFF_FONT_TYPE elif (data[0] == '\1') and (data[1] == '\0'): # CFF file self.font_type = CFF_FONT_TYPE elif "%" in data: self.font_type = TYPE1_FONT_TYPE else: print('Font type is unknown: ' 'will not be able to save changes') else: raise e return self.defcon_font
def openUFOFile(path, outFilePath, useHashMap): # Check if has glyphs/contents.plist contentsPath = os.path.join(path, "glyphs", "contents.plist") if not os.path.exists(contentsPath): msg = "Font file must be a PS, CFF, OTF, or ufo font file: %s." % (path) logMsg(msg) raise ACFontError(msg) # If user has specified a path other than the source font path, then copy the entire # ufo font, and operate on the copy. if (outFilePath != None) and (os.path.abspath(path) != os.path.abspath(outFilePath)): msg = "Copying from source UFO font to output UFO font before processing..." logMsg(msg) if os.path.exists(outFilePath): shutil.rmtree(outFilePath) shutil.copytree(path , outFilePath) path = outFilePath font = ufotools.UFOFontData(path, useHashMap, ufotools.kAutohintName) font.useProcessedLayer = True font.requiredHistory.append(ufotools.kCheckOutlineName) # Programs in this list must be run before autohint, if the outlines have been edited. return font