How to use the gftools.util.google_fonts.ReadNameList function in gftools

To help you get started, we’ve selected a few gftools 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 googlefonts / gftools / Lib / gftools / util / filter_lists.py View on Github external
def check_filterlist_equals_namelist(filterlist, namelistFilename, namelistCache=None):
    codepoints, noncodes = read_filterlist(filterlist)
    namelist = fonts.ReadNameList(namelistFilename, cache=namelistCache)
    message = []
    codepoints_set = set(c for c, _ in codepoints)
    if codepoints_set != namelist['ownCharset']:
        formatCodePoints = '0x{0:04X}'.format
        codepoints_not_in_namelist = codepoints_set - namelist['ownCharset']
        if len(codepoints_not_in_namelist):
            message.append('Unicode in filter list missing in Namelist:\n{0}'\
                        .format(', '.join(formatCodePoints(c) for c
                                    in sorted(codepoints_not_in_namelist))))
        codepoints_not_in_filterlist = namelist['ownCharset'] - codepoints_set
        if len(codepoints_not_in_filterlist):
            message.append('Unicode in Namelist missing in filter list:\n{0}'\
                        .format(', '.join(formatCodePoints(c) for c
                                    in sorted(codepoints_not_in_filterlist))))

    noncodes_set = set(noncodes)
github googlefonts / gftools / Lib / gftools / util / filter_lists.py View on Github external
def check_filterlist_in_namelist(filterListFileName, namelistCache=None):
    namelistFilename = get_namelist_for_filterlist(filterListFileName)
    if not namelistFilename:
        return False, 'No Namelist file found for {filterlist}'.format(filterlist=filterListFileName), None

    codepoints, noncodes = read_filterlist(filterListFileName)
    useProductionNames = 'uni names' in filterListFileName or 'uni-names' in filterListFileName
    if useProductionNames:
        prod_noncodes = noncodes;
        noncodes = [translate_name(name) for name in noncodes]
        noncodes2prodcodes = dict(zip(noncodes, prod_noncodes))

    namelist = fonts.ReadNameList(namelistFilename, cache=namelistCache)

    message = []

    missingChars = []
    for codepoint in codepoints:
        if codepoint[0] not in namelist['charset']:
            missingChars.append(codepoint)
    if len(missingChars):
        names = ', '.join(['0x{0:04X} {1}'.format(c, name)
                                        for c, name in missingChars])
        message.append('Unicode chars not in Namelist but in filter list:' \
                       '\n[{names}]'.format(names=names))

    missingNoncodes = []
    namelistNoCharcode = set(translate_name(name) for name in namelist['noCharcode'])
    for noncode in noncodes: