How to use the afdko.fdkutils.runShellCmd 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 / autohint.py View on Github external
raise ACFontError("Error: font is not a CFF font <%s>." % fontFileName)

	else:
		# It is not an OTF file.
		if head[0:2] == b'\x01\x00': # CFF file
			fontType = 1
			tempPathCFF = path
		else:  # It is a PS file. Convert to CFF.
			if head[0:2] == b'\x80\x01':  # PFB
				fontType = 3
			else:  # PFA
				fontType = 2

			print("Converting Type1 font to temp CFF font file...")
			command="tx  -cff +b -std \"%s\" \"%s\" 2>&1" % (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 ACFontError("Failed to convert PS font %s to a temp CFF font." % path)

		# now package the CFF font as an OTF font.
		with open(tempPathCFF, "rb") as ff:
			data = ff.read()
		try:
			ttFont = TTFont()
			cffModule = getTableModule('CFF ')
			cffTable = cffModule.table_C_F_F_('CFF ')
			ttFont['CFF '] = cffTable
			cffTable.decompile(data, ttFont)
		except:
			logMsg( "\t%s" %(traceback.format_exception_only(sys.exc_info()[0], sys.exc_info()[1])[-1]))
github adobe-type-tools / afdko / python / afdko / convertfonttocid.py View on Github external
def getGlyphList(fPath, removeNotdef=False, original_font=False):
    command = "tx -dump -4 \"%s\" 2>&1" % fPath
    data = fdkutils.runShellCmd(command)
    if not data:
        raise FontParseError("Error: Failed running 'tx -dump -4' on file "
                             "%s" % fPath)

    # initial newline keeps us from picking up the first column header line
    nameList = re.findall(r"[\r\n]glyph.+?{([^,]+),", data)
    if not nameList:
        raise FontParseError("Error: Failed getting glyph names from file %s "
                             "using tx." % fPath)

    if original_font:
        # make sure the original font has a .notdef glyph
        # and that it's the first glyph
        if '.notdef' not in nameList:
            raise FontParseError("Error: The font file %s does not have a "
                                 "'.notdef'." % fPath)
github adobe-type-tools / afdko / python / afdko / pdflib / fontpdf.py View on Github external
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
			self.avgWidth = os2.xAvgCharWidth
		else:
			if txreport == None:
				command = "tx -mtx \"%s\"" % (self.pdfFont.path)
				txreport = fdkutils.runShellCmd(command)
			# try for "H"
			match = re.search(r"glyph\S+\s+{H,[^,]+,[^,]+,{[-0-9]+,[-0-9]+,[-0-9]+,([-0-9]+)}}", txreport)
			if match:
				self.CapHeight = eval(match.group(1))
			else:
				self.CapHeight = 750 # real hack, but this doesn;t make much difference in this PDF.
			# try for "d"
			match = re.search(r"glyph\S+\s+{d,[^,]+,[^,]+,{[-0-9]+,[-0-9]+,[-0-9]+,([-0-9]+)}}", txreport)
			if match:
				self.Ascent = eval(match.group(1))
			else:
				self.Ascent = 750 # real hack, but this doesn;t make much difference in this PDF.
			# try for "p"
			match = re.search(r"glyph\S+\s+{p,[^,]+,[^,]+,{[-0-9]+,([-0-9]+),[-0-9]+,[-0-9]+}}", txreport)
			if match:
				self.Descent = eval(match.group(1))
github adobe-type-tools / afdko / python / afdko / convertfonttocid.py View on Github external
def makeCIDFontInfo(fontPath, cidfontinfoPath):
    cfiDict = {}
    for key in kCIDFontInfokeyList:
        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 TX_FIELDS:
        match = re.search(entry[0] + r"\s+(.+?)[\r\n]", report)
        if match:
            entry[2] = match.group(1)

    cfiDict["Registry"] = "Adobe"
    cfiDict["Ordering"] = "Identity"
    cfiDict["Supplement"] = "0"

    for entry in TX_FIELDS:
        if entry[2]:
github adobe-type-tools / afdko / python / afdko / convertfonttocid.py View on Github external
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

    if os.path.exists(outputPath):
        os.remove(outputPath)
        os.rename(dstPath, outputPath)
github adobe-type-tools / afdko / python / afdko / convertfonttocid.py View on Github external
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 %s, "
                                 "when trying 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)