How to use the gftools.util.filter_lists 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
def _get_basechar_unicode(name):
    codepoint = filter_lists.get_unicode_by_name(name)
    if codepoint is not None:
        return codepoint;
    if '_' in name:
        # use the first ligature component as base char
        return _get_basechar_unicode(name.split('_')[0])
    if '.' in name:
        return _get_basechar_unicode(name.split('.')[0])
    return None
github googlefonts / gftools / bin / gftools-namelist.py View on Github external
def _names_generator(filename):
    with codecs.open(filename, 'r', encoding='utf-8') as f:
        for line in f:
            line = line.rstrip()
            if line.startswith('0x'):
                # uni chr
                codepoint = google_fonts.get_codepoint_from_line(line)
                name = filter_lists.get_name_by_unicode(codepoint)
                if name is None:
                    prefix = 'u' if codepoint > 0xFFFF else 'uni'
                    name = '{0}{1:04X}'.format(prefix, codepoint)
                yield name
            elif line.startswith(' ' * 6):
                # unencoded name
                yield line.rsplit(' ', 1)[1]