예제 #1
0
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]
예제 #2
0
def _reformat_namelist(f, out=None):
    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:
            _print(format_codepoint(codepoint))
        elif name is not None:
            _print((' ' * 9 + name))
    # output left over lines at the end of the file
    map(_print, before)