Пример #1
0
    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
Пример #2
0
    def open(self, useHashMap):
        fontPath = self.fontPath
        try:
            ufoTools.validateLayers(fontPath)
            self.dFont = dFont = defcon.Font(fontPath)
            self.ufoFormat = dFont.ufoFormatVersion
            if self.ufoFormat < 2:
                self.ufoFormat = 2
            self.fontType = kUFOFontType
            self.useHashMap = useHashMap
            self.ufoFontHashData = ufoTools.UFOFontData(
                fontPath,
                self.useHashMap,
                programName=ufoTools.kCheckOutlineName)
            self.ufoFontHashData.readHashMap()

        except ufoLib.UFOLibError, e:
            if (not os.path.isdir(fontPath)
                ) 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.tempUFOPath = tempPath = fontPath + ".temp.ufo"
                if os.path.exists(tempPath):
                    shutil.rmtree(tempPath)
                cmd = "tx -ufo \"%s\" \"%s\"" % (fontPath, tempPath)
                p = subprocess.Popen(cmd,
                                     shell=True,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT).stdout
                log = p.read()
                if os.path.exists(tempPath):
                    try:
                        self.dFont = dFont = defcon.Font(tempPath)
                    except ufoLib.UFOLibError, e:
                        return
                    # It must be a font file!
                    self.tempUFOPath = tempPath
                    # figure out font type.
                    try:
                        ff = file(fontPath, "rb")
                        data = ff.read(10)
                        ff.close()
                    except (IOError, OSError):
                        return
                    if data[:4] == "OTTO":  # it is an OTF font.
                        self.fontType = kOpenTypeCFFFontType
                    elif (data[0] == '\1') and (data[1] == '\0'):  # CFF file
                        self.fontType = kCFFFontType
                    elif "%" in data:
                        self.fontType = kType1FontType
                    else:
                        print "Font type is unknown: will not be able to save changes"
Пример #3
0
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 fot before processing..."
        logMsg(msg)
        path = outFilePath
    font = ufoTools.UFOFontData(path, useHashMap, ufoTools.kAutohintName)
    return font
Пример #4
0
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