How to use the afdko.fdkutils.get_shell_command_output 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 / makeotf.py View on Github external
def getSourceGOADBData(inputFilePath):
    # First, get the Unicode mapping from the TTF cmap table.
    success, output = fdkutils.get_shell_command_output([
        'spot', '-t', 'cmap=7', inputFilePath])
    if not success:
        raise MakeOTFShellError

    spotGlyphList = re.findall(r"[\n\t]\[(....+)\]=<([^>]+)>", output)

    # Because this dumps all the Unicode map tables, there are a number
    # of duplicates; weed them out, and strip out gid part of spot name
    gDict = {}
    for entry in sorted(set(spotGlyphList)):
        uni = entry[0]
        gname, gid_str = entry[1].split('@')
        gid = int(gid_str)
        if gid in gDict:
            print("makeotf [Warning] Source TTF font contains multiple "
                  "Unicode values for glyph '%s'. Only the first ('%s') "
github adobe-type-tools / afdko / python / afdko / makeotf.py View on Github external
gname, gid_str = entry[1].split('@')
        gid = int(gid_str)
        if gid in gDict:
            print("makeotf [Warning] Source TTF font contains multiple "
                  "Unicode values for glyph '%s'. Only the first ('%s') "
                  "will be used. Additional Unicode value: %s" %
                  (gname, gDict[gid], uni))
        else:
            gDict[gid] = uni

    # Now get the font glyph name list, so as to get the glyphs with
    # no unicode mapping. We'll also use this to set the glyph order.
    # I use tx so as to get the same names as tx for the TTF glyphs;
    # this can differ from spot. I don't use tx for Unicode values.
    # as tx doesn't check 32 bit UV's, and doesn't report double-encodings.
    success, output = fdkutils.get_shell_command_output([
        'tx', '-mtx', inputFilePath])
    if not success:
        raise MakeOTFShellError

    txGlyphList = re.findall(r"[\n\r]glyph\[(\d+)\]\s+{([^,]+)", output)

    gnameDict = {}
    for gid_str, gname in txGlyphList:
        gid = int(gid_str)
        gnameDict[gid] = gname
        if gid not in gDict:
            gDict[gid] = None

    # Now flatten this to a GOADB list.
    goadbList = []
    for gid, uni_val in sorted(gDict.items()):
github adobe-type-tools / afdko / python / afdko / makeotf.py View on Github external
with open(filePath, "rb") as fp:
                data = fp.read(1024)
            if (b"%" not in data[:4]) and (b'/FontName' not in data):
                needsConversion = True
            else:
                if b"/Private" in data:
                    isTextPS = True
                    needsConversion = True
        except (IOError, OSError):
            print("makeotf [Error] Could not read font file at '%s'." %
                  filePath)
            raise MakeOTFShellError

    # Warn if there are any seac operators in the input file.
    if not (makeOTFParams.srcIsTTF or isTextPS or makeOTFParams.srcIsUFO):
        success, output = fdkutils.get_shell_command_output([
            'tx', '-dump', '-5', '-n', filePath])
        if not success:
            raise MakeOTFShellError

        glyphList = re.findall(r"glyph[^{]+?{([^,]+),[^[\]]+\sseac\s",
                               output)
        if glyphList:
            glyphList = ", ".join(glyphList)
            print("makeotf [Warning] Font at '%s' contains deprecated "
                  "SEAC operator. These composite glyphs will be "
                  "decomposed by makeOTF:\n%s" % (filePath, glyphList))
            needsConversion = True
            needsSEACRemoval = True

    if needsConversion:
        fontPath = fdkutils.get_temp_file_path()
github adobe-type-tools / afdko / python / afdko / makeotf.py View on Github external
def copyTTFGlyphTables(inputFilePath, tempOutputPath, outputPath):
    # tempOutputPath exists and is an OTF/CFF font.
    # outputPath does not yet exist, or is the same as inputFilePath.

    # Get the final glyph name list.
    success, output = fdkutils.get_shell_command_output([
        'tx', '-mtx', tempOutputPath])
    if not success:
        raise MakeOTFShellError

    glyphList = re.findall(r"[\n\r]glyph\[\d+\]\s+{([^,]+)", output)

    font = TTFont(inputFilePath)
    temp_font = TTFont(tempOutputPath)

    print("Fixing output font 'post' table...")
    fixPost(glyphList, font)

    print("Fixing output font 'head' table...")
    fixHead(temp_font, font)

    print("Fixing output font 'hhea' table...")
github adobe-type-tools / afdko / python / afdko / makeotf.py View on Github external
def get_font_psname(font_path, is_ufo=False):
    # Figure out PS name in order to derive default output path.
    success, output = fdkutils.get_shell_command_output([
        'tx', '-dump', '-0', font_path], std_error=True)
    if not success:
        raise MakeOTFShellError

    match = re.search(r"(?:CID)?FontName\s+\"(\S+)\"", output)
    if not match:
        if is_ufo:
            print(f"makeotf [Error] Could not find 'postscriptFontName' "
                  f"in file '{font_path}'")
        else:
            print(f"makeotf [Error] Could not find FontName (a.k.a. "
                  f"PostScript name) in FontDict of file "
                  f"'{font_path}'")
        raise MakeOTFShellError

    return match.group(1)
github adobe-type-tools / afdko / python / afdko / makeotf.py View on Github external
def CheckEnvironment():
    missingTools = []
    for name in ['tx', 'makeotfexe', 'spot']:
        if not fdkutils.get_shell_command_output([name, '-h'])[0]:
            missingTools.append(name)

    if missingTools:
        print("Please check your PATH, and if necessary re-install the AFDKO. "
              "Unable to find these tools: %s." % missingTools)
        raise FDKEnvironmentError
github adobe-type-tools / afdko / python / afdko / makeotf.py View on Github external
def checkFSTypeValue(FSType, outputPath):
    success, output = fdkutils.get_shell_command_output([
        'spot', '-t', 'OS/2', outputPath])
    if not success:
        raise MakeOTFShellError

    match = re.search(r"type\s+=(\S+)", output)
    if not match:
        print("makeotf [Error] Could not find 'type' in spot dump of OS/2 "
              "table of file at '%s'." % outputPath)
        return
    fsTypeTxt = match.group(1)
    fsType = fsTypeTxt.lstrip("0")
    if (len(fsType) == 0) and (len(fsTypeTxt) > 0):
        fsType = "0"
    fsType = str(fsType)
    if fsType != FSType:
        print("makeotf [Error] FSType value '%s' from (cid)fontinfo file does "