How to use the afdko.fdkutils function in afdko

To help you get started, we’ve selected a few afdko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adobe-type-tools / afdko / python / afdko / stemhist.py View on Github external
bp.write(bezString)

		if options.doAlign:
			doAlign = "-ra"
		else:
			doAlign = "-rs"

		if options.allStems:
			allStems = "-a"
		else:
			allStems = ""

		command = AUTOHINTEXE + " -q %s %s  -f \"%s\" \"%s\" 2>&1" % (doAlign, allStems, tempFI, tempBez)
		if options.debug:
			print(command)
		log = fdkutils.runShellCmd(command)
		if log:
			print(log)
			if "number terminator while" in log:
				print(tempBez)
				sys.exit()

		if os.path.exists(tempReport):
			with open(tempReport, "r", encoding='utf-8') as bp:
				report = bp.read()
			if options.debug:
				print("Wrote AC fontinfo data file to", tempFI)
				print("Wrote AC output rpt file to", tempReport)
			report.strip()
			if report:
				glyphReports.addGlyphReport(report)
				if options.debug:
github adobe-type-tools / afdko / python / afdko / convertfonttocid.py View on Github external
def merge_fonts(inputFontPath, outputPath, fontList, glyphList, fontDictList,
                fdGlyphDict):
    cidfontinfoPath = fdkutils.get_temp_file_path()
    makeCIDFontInfo(inputFontPath, cidfontinfoPath)
    lastFont = ""
    dstPath = ''

    for i, fontPath in enumerate(fontList):
        gaPath = fdkutils.get_temp_file_path()
        dstPath = fdkutils.get_temp_file_path()
        removeNotdef = i != 0
        makeGAFile(gaPath, fontPath, glyphList, fontDictList, fdGlyphDict,
                   removeNotdef)
        if lastFont:
            command = 'mergefonts -std -cid "%s" "%s" "%s" "%s" "%s" 2>&1' % (
                cidfontinfoPath, dstPath, lastFont, gaPath, fontPath)
        else:
            command = 'mergefonts -std -cid "%s" "%s" "%s" "%s" 2>&1' % (
                cidfontinfoPath, dstPath, gaPath, fontPath)
        log = fdkutils.runShellCmd(command)
        if "rror" in log:
            raise FontInfoParseError(
                "Error running command '%s'\nLog: %s" % (command, log))

        lastFont = dstPath
github adobe-type-tools / afdko / python / afdko / convertfonttocid.py View on Github external
def fixFontDict(tempPath, fdDict):
    txtPath = fdkutils.get_temp_file_path()
    command = "detype1 \"%s\" \"%s\" 2>&1" % (tempPath, txtPath)
    log = fdkutils.runShellCmd(command)
    if log:
        print(log)

    with open(txtPath, "r", encoding='utf-8') as fp:
        data = fp.read()

    # fix font name. We always search for 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:
github adobe-type-tools / afdko / python / afdko / autohint.py View on Github external
def openOpenTypeFile(path, outFilePath):
	# If input font is  CFF or PS, build a dummy ttFont in memory..
	# return ttFont, and flag if is a real OTF font Return flag is 0 if OTF, 1 if CFF, and 2 if PS/
	fontType  = 0 # OTF
	tempPathCFF = fdkutils.get_temp_file_path()
	try:
		with open(path, "rb") as ff:
			head = ff.read(4)
	except (IOError, OSError):
		logMsg("Failed to open and read font file %s." % path)

	if head == b"OTTO": # it is an OTF font, can process file directly
		try:
			ttFont = TTFont(path)
		except (IOError, OSError):
			raise ACFontError("Error opening or reading from font file <%s>." % path)
		except TTLibError:
			raise ACFontError("Error parsing font file <%s>." % path)

		try:
			cffTable = ttFont["CFF "]
github adobe-type-tools / afdko / python / afdko / makeotf.py View on Github external
needsSEACRemoval = True

    if needsConversion:
        fontPath = fdkutils.get_temp_file_path()

        if isTextPS:
            tempTxtPath = fdkutils.get_temp_file_path()

            # convert PS decrypted to PS encrypted with 'type1'
            if not fdkutils.run_shell_command([
                    'type1', filePath, tempTxtPath]):
                raise MakeOTFShellError
            filePath = tempTxtPath

        if needsSEACRemoval:
            tempSeacPath = fdkutils.get_temp_file_path()

            # convert to CFF using 'tx'
            if not fdkutils.run_shell_command([
                    'tx', '-cff', '-Z', '+b', filePath, tempSeacPath]):
                raise MakeOTFShellError
            filePath = tempSeacPath

        psName = get_font_psname(filePath, makeOTFParams.srcIsUFO)

        # Now convert to Type 1
        # (it's the only font format that makeotfexe can consume)
        if not fdkutils.run_shell_command(['tx', '-t1', filePath, fontPath]):
            raise MakeOTFShellError

        makeOTFParams.tempFontPath = fontPath
github adobe-type-tools / afdko / python / afdko / beztools.py View on Github external
tf.write(data)
					tf.close()
				else:
					tf = open(outFilePath, "wb")
					tf.write(data)
					tf.close()

			elif  2 <= fontType <= 3: # PS (PFA or PFB)
				tf = open(tempPath, "wb")
				tf.write(data)
				tf.close()
				finalPath = outFilePath
				command="tx  -t1 -std \"%s\" \"%s\" 2>&1" % (tempPath, outFilePath)
				if fontType == 3:  # PFB
					command = command.replace(" -t1 ", " -t1 -pfb ")
				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. %s" % (tempPath, outFilePath, report))

			if os.path.exists(tempPath):
				os.remove(tempPath)
	def close(self):
github adobe-type-tools / afdko / python / afdko / proofpdf.py View on Github external
def CheckEnvironment():
	tx_path = 'tx'
	txError = 0

	command = "%s -u 2>&1" % tx_path
	report = fdkutils.runShellCmd(command)
	if "options" not in report:
		txError = 1

	if txError:
		logMsg("Please check PATH and/or re-install the afdko. Cannot find: "
									"< %s >." % (tx_path))
		logMsg("or the files referenced by the shell script is missing.")
		raise FDKEnvironmentError

	return tx_path
github adobe-type-tools / afdko / python / afdko / pdflib / fontpdf.py View on Github external
self.Flags = (1<<2) # mark it as a symbolic font, so that  glyph names outside the PDF Std set will be recognized.

		# We need to get the widths for all the glyphs, so we can do basic layout.
		self.widthDict = {}
		txreport = None
		if self.pdfFont.clientFont.has_key('hmtx'):
			hmtx = self.pdfFont.clientFont['hmtx']
			for name in self.glyphList:
				self.widthDict[name] = hmtx[name][0]
		else:
			# have to use tx.
			### glyph[tag] {gname,enc,width,{left,bottom,right,top}}
			# glyph[1] {space,0x0020,250,{0,0,0,0}}
			command = "tx -mtx \"%s\"" % (self.pdfFont.path)
			txreport = fdkutils.runShellCmd(command)
			widths = re.findall(r"glyph\S+\s+{([^,]+),[^,]+,([^,]+),{[-0-9]+,[-0-9]+,[-0-9]+,[-0-9]+}}", txreport)
			if pdfFont.isCID:
				for name, width in widths:
					self.widthDict["cid%s" % (name.zfill(5))] = eval(width)
			else:
				for name, width in widths:
					self.widthDict[name] = eval(width)

		if pdfFont.clientFont.has_key('OS/2'):
			os2 = pdfFont.clientFont['OS/2']
			if os2.fsSelection & 1:
				self.Flags +=1<<7
			self.CapHeight = os2.sCapHeight
			self.Ascent = os2.sTypoAscender
			self.Descent = os2.sTypoDescender
			self.Leading = os2.sTypoLineGap
github adobe-type-tools / afdko / python / afdko / autohint.py View on Github external
numOptions = len(sys.argv)
	while i < numOptions:
		arg = sys.argv[i]
		if options.inputPath:
			raise ACOptionParseError("Option Error: All options must preceed the  input font path <%s>." % arg)

		if arg == "-h":
			print(__help__)
			command = '"%s" -v' % AUTOHINTEXE
			report = fdkutils.runShellCmd(command)
			logMsg( report)
			raise ACOptionParseError
		elif arg == "-u":
			print(__usage__)
			command = '"%s" -v' % AUTOHINTEXE
			report = fdkutils.runShellCmd(command)
			logMsg( report)
			raise ACOptionParseError
		elif arg == "-hfd":
			print(__FDDoc__)
			raise ACOptionParseError
		elif arg == "-pfd":
			options.printDefaultFDDict = 1
		elif arg == "-pfdl":
			options.printFDDictList = 1
		elif arg == "-hf":
			options.usePlistFile = 1
		elif arg == "-a":
			options.hintAll = 1
		elif arg == "-all":
			options.hintAll = 1
		elif arg == "-r":