How to use the gftools.util.filter_lists.translate_name 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 / bin / gftools-namelist.py View on Github external
def generate_filter_lists(filename):
    # 'GF-{script}-rest.nam' => {script}-rest
    basename = os.path.basename(filename).split('.', 1)[0].split('-', 2)[-1]
    filerListFileName = '{0}.txt'.format(basename)
    dirname =  os.path.dirname(filename)
    nice_names_filename = os.path.join(dirname, 'filter lists', 'nice names', filerListFileName)
    prod_names_filename = os.path.join(dirname, 'filter lists', 'uni names', filerListFileName)

    _mkdir(os.path.dirname(nice_names_filename))
    _mkdir(os.path.dirname(prod_names_filename))

    with codecs.open(nice_names_filename, 'w', encoding='utf-8') as niceNamesFile, \
            codecs.open(prod_names_filename, 'w', encoding='utf-8') as prodNamesFile:
        for name in _names_generator(filename):
            print(filter_lists.translate_name(name, production_name=False), file=niceNamesFile)
            print(filter_lists.translate_name(name, production_name=True), file=prodNamesFile)
github googlefonts / gftools / bin / gftools-namelist.py View on Github external
entries = []
    before = []
    header = []
    for line in f:
        line = line.rstrip()
        if (not entries and not before) and line.startswith('#'):
            header.append(line)
            continue
        entry = None
        if line.startswith('0x'):
            # uni chr
            codepoint = google_fonts.get_codepoint_from_line(line)
            entry = (codepoint, None, line)
        elif line.startswith('      '):
            # unencoded name
            name = filter_lists.translate_name(line.rsplit(' ', 1)[1])
            entry = (None, name, line)

        if entry is not None:
            entry += (before, )
            before = []
            entries.append(entry)
        else:
            # these lines will stick before the next entry
            before.append(line)

    entries.sort(key=_sortkey_namelist_entries)
    _print = lambda *args: print(*args,file=out)
    map(_print, header)
    for codepoint, name, original, item_before in entries:
        map(_print, item_before)
        if codepoint is not None: