当前位置: 首页>>代码示例>>Python>>正文


Python FDKUtils类代码示例

本文整理汇总了Python中FDKUtils的典型用法代码示例。如果您正苦于以下问题:Python FDKUtils类的具体用法?Python FDKUtils怎么用?Python FDKUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FDKUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mergeFonts

def mergeFonts(inputFontPath, outputPath, fontList, glyphList, fontDictList, fdGlyphDict):
	cidfontinfoPath = "%s.temp.cidfontinfo" % (inputFontPath)
	makeCIDFontInfo(inputFontPath, cidfontinfoPath)
	lastFont =""
	tempfileList = []
	i = 0
	print "Merging temp fonts:", 
	for fontPath in fontList:
		print ".",
		sys.stdout.flush()
		gaPath = fontPath + ".ga"
		dstPath = "%s.temp.merge.%s" % (inputFontPath, i)
		removeNotdef = i != 0
		makeGAFile(gaPath, fontPath, glyphList, fontDictList, fdGlyphDict, removeNotdef)
		command = "mergeFonts -std -cid \"%s\" \"%s\" %s %s  %s 2>&1"  % (cidfontinfoPath, dstPath, lastFont, gaPath, fontPath)
		log = FDKUtils.runShellCmd(command)
		if debug:
			print command
			print log
		if "rror" in log:
			msg = "Error merging font %s. Log: %s." % (fontPath, log)
			raise FontInfoParseError(msg)
		i += 1
		lastFont = dstPath
		tempfileList.append(gaPath)
		tempfileList.append(dstPath)
		
	print ""		
	os.rename(dstPath, outputPath)
	if not debug:
		for path in tempfileList:
			if os.path.exists(path):
				os.remove(path)
		os.remove(cidfontinfoPath)
	return
开发者ID:NuttShell,项目名称:afdko,代码行数:35,代码来源:ConvertFontToCID.py

示例2: CheckEnvironment

def CheckEnvironment():
	txPath = 'tx'
	txError = 0
	command = "%s -u 2>&1" % (txPath)
	report = FDKUtils.runShellCmd(command)
	if "options" not in report:
			txError = 1
	
	if  txError:
		logMsg("Please re-install the FDK. The path to the program 'tx' is not in the environment variable PATH.")
		raise FDKEnvironmentError

	command = "checkoutlinesexe -u 2>&1"
	report = FDKUtils.runShellCmd(command)
	if "version" not in report:
		logMsg("Please re-install the FDK. The path to the program 'checkoutlinesexe' is not in the environment variable PATH.")
		raise FDKEnvironmentError

	return
开发者ID:shannpersand,项目名称:cooper-type,代码行数:19,代码来源:CheckOutlines.py

示例3: getBlueFuzz

def getBlueFuzz(fPath):
	blueFuzz = 1.0
	command = "tx -dump -0 %s 2>&1" % (fPath)
	data = FDKUtils.runShellCmd(command)
	if not data:
		raise FontInfoParseError("Error: Failed getting  log from tx from %, when trying to get FontName." % (fPath))
		
	m = re.search(r"BlueFuzz\s+(\d+(?:\.\d+)*)", data) 
	if m:
		blueFuzz = int(m.group(1))
	return blueFuzz
开发者ID:NuttShell,项目名称:afdko,代码行数:11,代码来源:ConvertFontToCID.py

示例4: getFontName

def getFontName(fPath):
	command = "tx -dump -0 %s 2>&1" % (fPath)
	data = FDKUtils.runShellCmd(command)
	if not data:
		raise FontInfoParseError("Error: Failed getting  log from tx from %, when tryin to get FontName." % (fPath))
		
	m = re.search(r"FontName\s+\"([^\"]+)", data) 
	if not m:
		print data
		raise FontInfoParseError("Error: Failed finding FontName in tx log from  %s." % (fPath))
	return m.group(1)
开发者ID:NuttShell,项目名称:afdko,代码行数:11,代码来源:ConvertFontToCID.py

示例5: CheckEnvironment

def CheckEnvironment():
	txPath = 'tx'
	txError = 0

	try:
		exe_dir, fdkSharedDataDir = FDKUtils.findFDKDirs()
	except FDKUtils.FDKEnvError:
		logMsg("Please re-install the FDK. Cannot find the FDK/Tools/SharedData directory.")
		raise FDKEnvironmentError

	command = "%s -u 2>&1" % (txPath)
	report = FDKUtils.runShellCmd(command)
	if "options" not in report:
			txError = 1
	
	if  txError:
		logMsg("Please re-install the FDK. The executable directory \"%s\" is missing the tool: < %s >." % (exe_dir, txPath ))
		logMsg("or the files referenced by the shell script is missing.")
		raise FDKEnvironmentError

	return txPath, fdkSharedDataDir
开发者ID:brawer,项目名称:afdko,代码行数:21,代码来源:ProofPDF.py

示例6: saveChanges

	def saveChanges(self):
		ttFont = self.ttFont
		fontType = self.fontType
		inputPath = self.inputPath
		outFilePath = self.outFilePath

		overwriteOriginal = 0
		if inputPath == outFilePath:
			overwriteOriginal = 1
		tempPath = inputPath +  ".temp.ac"
	
		if fontType == 0: # OTF
			if overwriteOriginal:
				ttFont.save(tempPath)
				ttFont.close()
				if os.path.exists(inputPath):
					try:
						os.remove(inputPath)
						os.rename(tempPath, inputPath)
					except (OSError, IOError):
						self.logMsg( "\t%s" %(traceback.format_exception_only(sys.exc_type, sys.exc_value)[-1]))
						self.logMsg("Error: could not overwrite original font file path '%s'. Hinted font file path is '%s'." % (inputPath, tempPath))
			else:
				ttFont.save(outFilePath)
				ttFont.close()
	
		else:
			data = ttFont["CFF "].compile(ttFont)
			if fontType == 1: # CFF
				if overwriteOriginal:
					tf = file(tempPath, "wb")
					tf.write(data)
					tf.close()
					os.rename(tempPath, inputPath)
				else:
					tf = file(outFilePath, "wb")
					tf.write(data)
					tf.close()
	
			elif  fontType == 2: # PS.
				tf = file(tempPath, "wb")
				tf.write(data)
				tf.close()
				finalPath = outFilePath
				command="tx  -t1 -std \"%s\" \"%s\" 2>&1" % (tempPath, outFilePath)
				report = FDKUtils.runShellCmd(command)
				self.logMsg(report)
				if "fatal" in report:
					raise IOError("Failed to convert hinted font temp file with tx %s. Maybe target font font file '%s' is set to read-only." % (tempPath, outFilePath))
	
			if os.path.exists(tempPath):
				os.remove(tempPath)
开发者ID:pradnyanaik17,项目名称:afdko,代码行数:52,代码来源:BezTools.py

示例7: mergeFontToCFF

def mergeFontToCFF(srcPath, outputPath, doSubr):
	# We assume that srcPath is a type 1 font,and outputPath is an OTF font.
	
	# First, convert src font to cff, and subroutinize it if so requested.
	tempPath = srcPath + ".temp.cff"
	subrArg = ""
	if doSubr:
		subrArg=" +S"
	command="tx -cff +b%s \"%s\" \"%s\" 2>&1" % (subrArg, srcPath, tempPath)
	report = FDKUtils.runShellCmd(command)
	if ("fatal" in report) or ("error" in report):
		print report
		raise FontInfoParseError("Failed to convert font '%s' to CFF." % (fontPath))
		
	# Now merge it into the output file.
	command="sfntedit -a CFF=\"%s\" \"%s\" 2>&1" % (tempPath, outputPath)
	report = FDKUtils.runShellCmd(command)
	if not debug:
		if os.path.exists(tempPath):
			os.remove(tempPath)
	if ("fatal" in report) or ("error" in report):
		print report
		raise FontInfoParseError("Failed to convert font '%s' to CFF." % (fontPath))
开发者ID:NuttShell,项目名称:afdko,代码行数:23,代码来源:ConvertFontToCID.py

示例8: getFontBBox

def getFontBBox(fPath):
	fontBBox = [-200, -200,1000,100]
	command = "tx -dump -0 %s 2>&1" % (fPath)
	data = FDKUtils.runShellCmd(command)
	if not data:
		raise FontInfoParseError("Error: Failed getting  log from tx from %, when tryingg to get FontBBox." % (fPath))
	
	m = re.search(r"FontBBox[^{]+{([^}]+)}", data) 
	if not m:
		print data
		raise FontInfoParseError("Error: Failed finding FontBBox in tx log from  %s." % (fPath))
	fontBBox = m.group(1).split(",")
	fontBBox = map(int, fontBBox)
	return fontBBox
开发者ID:NuttShell,项目名称:afdko,代码行数:14,代码来源:ConvertFontToCID.py

示例9: CheckEnvironment

def CheckEnvironment():
	txPath = 'tx'
	txError = 0
	command = "%s -u 2>&1" % (txPath)
	report = FDKUtils.runShellCmd(command)
	if "options" not in report:
			txError = 1
	
	if  txError:
		logMsg("Please re-install the FDK. The executable directory \"%s\" is missing the tool: < %s >." % (exe_dir, txPath ))
		logMsg("or the files referenced by the shell script is missing.")
		raise FDKEnvironmentError

	return txPath
开发者ID:blakejia,项目名称:afdko,代码行数:14,代码来源:StemHist.py

示例10: getGlyphList

def getGlyphList(fPath, removeNotdef = 0):
	command = "tx -dump -4 %s 2>&1" % (fPath)
	data = FDKUtils.runShellCmd(command)
	if not data:
		print "Error: Failed getting glyph names from  %s with tx." % (fPath)
		return []
	
	nameList = re.findall(r"[\r\n]glyph.+?{([^,]+),", data) # initial newline keeps us from picking up the first column header  line
	if not nameList:
		print "Error: Failed getting glyph names from  %s with tx." % (fPath)
		print data
		return []
	if removeNotdef:
		nameList.remove(".notdef")
	return nameList
开发者ID:NuttShell,项目名称:afdko,代码行数:15,代码来源:ConvertFontToCID.py

示例11: makeCIDFontInfo

def makeCIDFontInfo(fontPath, cidfontinfoPath):
	cfiDict = {}
	for key in kRequiredCIDFontInfoFields + kOptionalFields:
		cfiDict[key] = None
	cfiDict["Weight"] = "(Regular)"
	cfiDict["AdobeCopyright"] = "0"

	# get regular FontDict.
	command="tx -0 \"%s\" 2>&1" % (fontPath)
	report = FDKUtils.runShellCmd(command)
	if ("fatal" in report) or ("error" in report):
		print report
		raise FontInfoParseError("Failed to dump font dict using tx from font '%s'" % (fontPath))

	for entry in txFields:
		match = re.search(entry[0]+ "\s+(.+?)[\r\n]", report)
		if match:
			entry[2] = match.group(1)

	cfiDict["Registry"] = "Adobe"
	cfiDict["Ordering"] = "Identity"
	cfiDict["Supplement"] = "0"
	
	for entry in txFields:
		if entry[2]:
			cfiDict[entry[1]] = entry[2]
		elif entry[1] in kRequiredCIDFontInfoFields:
			haveError = 1
			print "Error: did not find required info '%s' in tx dump of font '%s'." % (entry[1], fontPath) 
	

	try:
		fp = open(cidfontinfoPath, "wt")
		for key in kCIDFontInfokeyList:
			value = cfiDict[key]
			if value == None:
				continue
			if value[0] == "\"":
				value = "(" + value[1:-1] + ")"
			string = "%s\t%s" % (key, value)
			fp.write(string + os.linesep)
			fp.write(os.linesep)
		fp.close()
	except (IOError, OSError):
		msg = "Error. Could not open and write file '%s'" % (cidfontinfoPath)
		raise FontInfoParseError(msg)
	return
开发者ID:blakejia,项目名称:afdko,代码行数:47,代码来源:ConvertFontToCID.py

示例12: proofMakePDF

def proofMakePDF(pathList, params, txPath):
	#    use fontTools library to open font and extract CFF table. 
	#    If error, skip font and report error.
	if params.rt_doFontSet:
		pdfFontList = []
		logMsg("")
		logMsg( "Collecting font data from:")
		fontCount = 0
		for path in pathList:
			fontFileName = os.path.basename(path)
			params.rt_filePath = os.path.abspath(path)
			logMsg( "\t%s." % (path))
			try:
				ttFont, tempPathCFF = openFile(path, txPath)
			except FontError:
				print traceback.format_exception_only(sys.exc_type, sys.exc_value)[-1]
				return
			try:
				fontGlyphList = ttFont.getGlyphOrder()
			except FontError:
				print traceback.format_exception_only(sys.exc_type, sys.exc_value)[-1]
				return
		
		
			#   filter specified list, if any, with font list.
			glyphList = filterGlyphList(params, fontGlyphList, fontFileName)
			if not glyphList:
				raise FontError("Error: selected glyph list is empty for font <%s>." % fontFileName)
			params.rt_reporter = logMsg
		
			if ttFont.has_key("CFF "):
				pdfFont = otfPDF.txPDFFont(ttFont, params)
			elif ttFont.has_key("glyf"):
				pdfFont = ttfPDF.txPDFFont(ttFont, params)
			else:
				logMsg( "Quitting. Font type is not recognized. %s.." % (path))
				break
			if tempPathCFF:
				pdfFont.path = tempPathCFF
			pdfFontList.append([glyphList, pdfFont, tempPathCFF])
			
		pdfFilePath = makeFontSetPDF(pdfFontList,  params)
		for entry in pdfFontList:
			tempPathCFF =  entry[2]
			pdfFont = entry[1]
			pdfFont.clientFont.close()
			if tempPathCFF:
				os.remove(tempPathCFF)
		
			
		logMsg( "Wrote proof file %s. End time: %s." % (pdfFilePath, time.asctime()))
		if pdfFilePath and params.openPDFWhenDone:
			if curSystem == "Windows":
				curdir = os.getcwdu()
				basedir, pdfName = os.path.split(pdfFilePath)
				os.chdir(basedir)
				command = "start %s" % (pdfName)
				print command
				FDKUtils.runShellCmdLogging(command)
				os.chdir(curdir)
			elif os.name == "Linux":
				command = "xdg-open \"" + pdfFilePath  + "\"" + " &"
				FDKUtils.runShellCmdLogging(command)
			else:
				command = "open \"" + pdfFilePath  + "\"" + " &"
				FDKUtils.runShellCmdLogging(command)
	else:
		tmpList = []
		for path in pathList:
			fontFileName = os.path.basename(path)
			params.rt_filePath = os.path.abspath(path)
			logMsg("")
			logMsg( "Proofing font %s. Start time: %s." % (path, time.asctime()))
			try:
				ttFont, tempPathCFF = openFile(path, txPath)
				fontGlyphList = ttFont.getGlyphOrder()
			except FontError:
				print traceback.format_exception_only(sys.exc_type, sys.exc_value)[-1]
				return
		
		
			#   filter specified list, if any, with font list.
			params.rt_glyphList = filterGlyphList(params, fontGlyphList, fontFileName)
			if not params.rt_glyphList:
				raise FontError("Error: selected glyph list is empty for font <%s>." % fontFileName)
			params.rt_reporter = logMsg
		
			if ttFont.has_key("CFF "):
				pdfFont = otfPDF.txPDFFont(ttFont, params)
			elif ttFont.has_key("glyf"):
				pdfFont = ttfPDF.txPDFFont(ttFont, params)
			else:
				logMsg( "Quitting. Font type is not recognized. %s.." % (path))
				return
			
			if tempPathCFF:
				pdfFont.path = tempPathCFF
			pdfFilePath = makePDF(pdfFont,  params)
			ttFont.close()
			if tempPathCFF:
#.........这里部分代码省略.........
开发者ID:brawer,项目名称:afdko,代码行数:101,代码来源:ProofPDF.py

示例13: openFile

def openFile(path, txPath):
	# If input font is  CFF or PS, build a dummy ttFont.
	tempPathCFF = None
	cffPath = None

	# If it is CID-keyed font, we need to convert it to a name-keyed font. This is a hack, but I really don't want to add CID support to
	# the very simple-minded PDF library.
	command="%s   -dump -0  \"%s\" 2>&1" % (txPath, path)
	report = FDKUtils.runShellCmd(command)
	if "CIDFontName" in report:
		tfd,tempPath1 = tempfile.mkstemp()
		os.close(tfd)
		command="%s   -t1 -decid -usefd 0  \"%s\" \"%s\" 2>&1" % (txPath, path, tempPath1)
		report = FDKUtils.runShellCmd(command)
		if "fatal" in report:
			logMsg(report)
			logMsg("Failed to convert CID-keyed font %s to a temporary Typ1 data file." % path)

		tfd,tempPathCFF = tempfile.mkstemp()
		os.close(tfd)
		command="%s   -cff +b  \"%s\" \"%s\" 2>&1" % (txPath, tempPath1, tempPathCFF)
		report = FDKUtils.runShellCmd(command)
		if "fatal" in report:
			logMsg(report)
			logMsg("Failed to convert CID-keyed font %s to a temporary CFF data file." % path)
		cffPath = tempPathCFF
		os.remove(tempPath1)
	elif os.path.isdir(path):
		# See if it is a UFO font by truing to dump it.
		command="%s   -dump -0  \"%s\" 2>&1" % (txPath, path)
		report = FDKUtils.runShellCmd(command)
		if not "sup.srcFontType" in report:
			logMsg(report)
			logMsg("Failed to open directory %s as a UFO font." % path)
			
		tfd,tempPathCFF = tempfile.mkstemp()
		os.close(tfd)
		command="%s   -cff +b  \"%s\" \"%s\" 2>&1" % (txPath, path, tempPathCFF)
		report = FDKUtils.runShellCmd(command)
		if "fatal" in report:
			logMsg(report)
			logMsg("Failed to convert ufo font %s to a temporary CFF data file." % path)
		cffPath = tempPathCFF
	else:
		try:
			ff = file(path, "rb")
			data = ff.read(10)
			ff.close()
		except (IOError, OSError):
			import traceback
			traceback.print_exc()
			raise FontError("Failed to open and read font file %s. Check file/directory permissions." % path)
		
		if len(data) < 10:
			raise FontError("Error: font file was zero size: may be a resource fork font, which this program does not process. <%s>." % path)
		if (data[:4] == "OTTO") or (data[:4] == "true") or (data[:4] == "\0\1\0\0"): # it is an OTF/TTF font, can process file directly
			try:
				ttFont = ttLib.TTFont(path)
			except (IOError, OSError):
				raise FontError("Error opening or reading from font file <%s>." % path)
			except TTLibError:
				raise FontError("Error parsing font file 333 <%s>." % path)
	
			if not (ttFont.has_key('CFF ') or ttFont.has_key('glyf')):
				raise FontError("Error: font is not a CFF or TrueType font <%s>." % path)
	
			return ttFont, tempPathCFF
	
		# It is not an OTF file.
		if (data[0] == '\1') and (data[1] == '\0'): # CFF file
			cffPath = path
		elif not "%" in data:
			#not a PS file either
			logMsg("Font file must be a PS, CFF or OTF  fontfile: %s." % path)
			raise FontError("Font file must be PS, CFF or OTF file: %s." % path)
	
		else:  # It is a PS file. Convert to CFF.	
			tfd,tempPathCFF = tempfile.mkstemp()
			os.close(tfd)
			cffPath = tempPathCFF
			command="%s   -cff +b  \"%s\" \"%s\" 2>&1" % (txPath, path, tempPathCFF)
			report = FDKUtils.runShellCmd(command)
			if "fatal" in report:
				logMsg("Attempted to convert font %s  from PS to a temporary CFF data file." % path)
				logMsg(report)
				raise FontError("Failed to convert PS font %s to a temp CFF font." % path)

	# now package the CFF font as an OTF font
	ff = file(cffPath, "rb")
	data = ff.read()
	ff.close()
	try:
		ttFont = ttLib.TTFont()
		cffModule = ttLib.getTableModule('CFF ')
		cffTable = cffModule.table_C_F_F_('CFF ')
		ttFont['CFF '] = cffTable
		cffTable.decompile(data, ttFont)
	except:
		import traceback
		traceback.print_exc()
#.........这里部分代码省略.........
开发者ID:brawer,项目名称:afdko,代码行数:101,代码来源:ProofPDF.py

示例14: fixFontDict

def fixFontDict(tempPath, fdDict):
	
	txtPath = tempPath + ".txt"
	command = "detype1 %s %s 2>&1" % (tempPath, txtPath)
	log = FDKUtils.runShellCmd(command)
	if log:
		print log
	fp = open(txtPath, "rt")
	data = fp.read()
	fp.close()
	
	# fix font name.
	# We always search of it, as it is always present, and we can use the following
	# white space to get the file new line.
	m = re.search(r"(/FontName\s+/\S+\s+def)(\s+)", data)
	newLine = m.group(2)
	if not m:
		raise FontParseError("Failed to find FontName in input font!. %s" % (tempPath))
	if fdDict.FontName:
		target = "/FontName /%s def" % (fdDict.FontName)
		data = data[:m.start(1)] + target +  data[m.end(1):]
	
	# fix em square
	if fdDict.OrigEmSqUnits:
		m = re.search(r"/FontMatrix\s+\[.+?\]\s+def", data)
		if not m:
			raise FontParseError("Failed to find FontMatrix in input font! %s" % (tempPath))
		emUnits = eval(fdDict.OrigEmSqUnits)
		a = 1.0/emUnits
		target = "/FontMatrix [%s 0 0 %s 0 0] def" % ( a, a)
		data = data[:m.start()] + target +  data[m.end():]

	# fix StemSnapH.  Remove StemSnapH if fdDict.StemSnapH is not defined, else set it.
	m = re.search(r"/StemSnapH\s+\[.+?\]\s+def", data)
	if fdDict.DominantH:
		target = "/StemSnapH %s def" % ( fdDict.DominantH)
		data = data[:m.start()] + target +  data[m.end():]
		insertIndex = m.start() + len(target)
	else:
		data = data[:m.start()] + data[m.end():]

	# fix StemSnapV.  Remove StemSnapV entry if fdDict.StemSnapV is not defined, else set it.
	m = re.search(r"/StemSnapV\s+\[.+?\]\s+def", data)
	if fdDict.DominantV:
		target = "/StemSnapV %s def" % ( fdDict.DominantV)
		data = data[:m.start()] + target +  data[m.end():]
		insertIndex = m.start() + len(target)
	else:
		data = data[:m.start()] + data[m.end():]
	
	# LanguageGroup. Remove LanguageGroup entry if fdDict.LanguageGroup is not defined, else set it.
	if fdDict.LanguageGroup:
		m = re.search(r"/LanguageGroup\s+\d+\s+def", data)
		if not m:
			target = "%s/LanguageGroup %s def" % (newLine, fdDict.LanguageGroup)
			data = data[:insertIndex] + data[insertIndex] + target +  data[insertIndex:]
		else:
			data = data[:m.start()] + target +  data[m.end():]
		target = "/LanguageGroup %s def" % (fdDict.LanguageGroup)
	else:
		m = re.search(r"/LanguageGroup\s+\d+\s+def", data)
		if m:
			data = data[:m.start()] +  data[m.end():]
	
	# Fix BlueValues. Must be present.
	m = re.search(r"/BlueValues\s+\[.+?\]\s+def", data)
	if not m:
		raise FontParseError("Failed to find BlueValues in input font! %s" % (tempPath))
	target = "/BlueValues %s def" % (fdDict.BlueValues)
	data = data[:m.start()] + target +  data[m.end():]
	insertIndex = m.start() + len(target)

	# Fix OtherBlues, if present. Remove if there are no OtherBlues entry.
	m = re.search(r"/OtherBlues\s+\[.+?\]\s+def", data)
	if fdDict.OtherBlues:
		if not m:
			target = "%s/OtherBlues %s def" % (newLine, fdDict.OtherBlues)
			data = data[:insertIndex] + target +  data[insertIndex:]
		else:
			target = "/OtherBlues %s def" % (fdDict.OtherBlues)
			data = data[:m.start()] + target +  data[m.end():]
	else:
			data = data[:m.start()] + data[m.end():]
		
	

	fp = open(txtPath, "wt")
	fp.write(data)
	fp.close()
	
	command = "type1 %s %s 2>&1" % (txtPath, tempPath)
	log = FDKUtils.runShellCmd(command)
	if log:
		print log
	
	if not debug:
		os.remove(txtPath)
	return
开发者ID:NuttShell,项目名称:afdko,代码行数:98,代码来源:ConvertFontToCID.py

示例15: checkFile

def checkFile(path, options):
	#    use fontTools library to open font and extract CFF table. 
	#    If error, skip font and report error.
	seenChangedGlyph = 0
	fontFileName = os.path.basename(path)
	logMsg("Checking font %s. Start time: %s." % (path, time.asctime()))
	try:
		fontData = openFile(path, options.outFilePath, options.allowChanges)
		fontData.allowDecimalCoords = options.allowDecimalCoords
	except (IOError, OSError):
		logMsg( traceback.format_exception_only(sys.exc_type, sys.exc_value)[-1])
		raise focusFontError("Error opening or reading from font file <%s>." % fontFileName)
	except:
		logMsg( traceback.format_exception_only(sys.exc_type, sys.exc_value)[-1])
		raise focusFontError("Error parsing font file <%s>." % fontFileName)

	#   filter specified list, if any, with font list.
	fontGlyphList = fontData.getGlyphList()
	glyphList = filterGlyphList(options, fontGlyphList, fontFileName)
	if not glyphList:
		raise focusFontError("Error: selected glyph list is empty for font <%s>." % fontFileName)


	removeHints = 1
	reportCB = logMsg
	reportText = ""

	# If the user has not specified an em-square, and the font has am em-square other than 1000, supply it.
	if not options.emSquare:
		emSquare = fontData.getUnitsPerEm()
		if emSquare != "1000":
			options.emSquare = emSquare
			
	arg_string = buildArgString(options)
		
	dotCount = 0		
	seenGlyphCount = 0
	processedGlyphCount = 0
	for name in glyphList:
		seenGlyphCount +=1 
		if options.beVerbose:
			logMsg("Checking %s -- ," % ( aliasName(name) )) # output message when -v option is used
		else:
			logMsg(".,")
			dotCount += 1
			if dotCount > 40:
				dotCount = 0
				logMsg("") # I do this to never have more than 40 dots on a line.
				# This in turn give reasonable performance when calling checkOutlines in a subprocess
				# and getting output with std.readline()

		if os.path.exists(kTempFilepathOut):
			os.remove(kTempFilepathOut)
		
		# 	Convert to bez format
		bezString, width, hasHints = fontData.convertToBez(name, removeHints, options.beVerbose, options.checkAll)
		if bezString == None:
			continue
		processedGlyphCount += 1

		if "mt" not in bezString:
			# skip empty glyphs.
			continue
			
		# write bez file and run checkoutlinesexe
		fp = open(kTempFilepath, "wt")
		fp.write(bezString)
		fp.close()
		command = "checkoutlinesexe -o %s %s" % (arg_string, kTempFilepath)
		if debug:
			print "calling command", command
		log = FDKUtils.runShellCmd(command)
		# The suffix saying what bez file was written isn't useful here.
		log = re.sub(r"Wrote fixed file.+\s*", "", log)
		if log:
			if not options.beVerbose:
				dotCount = 0
				logMsg("")
				logMsg("Checking %s -- ," % (aliasName(name))) # output message when -v option is NOT used
				logMsg(log)
			else:
				logMsg(log)
		if  options.allowChanges and os.path.exists(kTempFilepathOut):
			fp = open(kTempFilepathOut, "rt")
			bezData = fp.read()
			fp.close()
			if bezData != bezString:
				fontData.updateFromBez(bezData, name, width, options.beVerbose)
				seenChangedGlyph = 1

	if not options.beVerbose:
		logMsg("")
	if seenChangedGlyph:
		# save fontFile.
		fontData.saveChanges()
	else:
		fontData.close()

	if processedGlyphCount != seenGlyphCount:
		logMsg("Skipped %s of %s glyphs." % (seenGlyphCount - processedGlyphCount, seenGlyphCount))
#.........这里部分代码省略.........
开发者ID:shannpersand,项目名称:cooper-type,代码行数:101,代码来源:CheckOutlines.py


注:本文中的FDKUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。