(font, max_glyphs)
return font
Create composed glyphs from combining up to `max_glyphs` glyphs.
Create composed glyphs from combining up to `max_glyphs` glyphs.
Create composed glyphs from combining up to max_glyphs glyphs .
def precompose(font, max_glyphs):
    """Create composed glyphs from combining up to `max_glyphs` glyphs."""
    composed_glyphs = {}
    codepoints = set(_glyph.char for _glyph in font.glyphs if _glyph.char)
    # run through all of plane 0
    for cp in range(0x10000):
        char = chr(cp)
        if char not in codepoints:
            # first see if an equivalent precomposed char is already there
            equiv = normalize('NFC', char)
            if equiv in codepoints:
                logging.info(f'Assigning {fullname(char)} == {fullname(equiv)}.')
                font = font.with_glyph(font.get_glyph(equiv).set_annotations(char=char))
            else:
                decomp = normalize('NFD', char)
                if len(decomp) <= max_glyphs and all(c in codepoints for c in decomp):
                    logging.info(f'Composing {fullname(char)} as {fullname(decomp)}.')
                    glyphs = (font.get_glyph(c) for c in decomp)
                    composed = monobit.Glyph.superimpose(glyphs).set_annotations(char=char)
                    font = font.with_glyph(composed)
    return font
def precompose ( font , max_glyphs ) : composed_glyphs = { } codepoints = set ( _glyph . char for _glyph in font . glyphs if _glyph . char ) # run through all of plane 0 for cp in range ( 0x10000 ) : char = chr ( cp ) if char not in codepoints : # first see if an equivalent precomposed char is already there equiv = normalize ( 'NFC' , char ) if equiv in codepoints : logging . info ( f'Assigning {fullname(char)} == {fullname(equiv)}.' ) font = font . with_glyph ( font . get_glyph ( equiv ) . set_annotations ( char = char ) ) else : decomp = normalize ( 'NFD' , char ) if len ( decomp ) <= max_glyphs and all ( c in codepoints for c in decomp ) : logging . info ( f'Composing {fullname(char)} as {fullname(decomp)}.' ) glyphs = ( font . get_glyph ( c ) for c in decomp ) composed = monobit . Glyph . superimpose ( glyphs ) . set_annotations ( char = char ) font = font . with_glyph ( composed ) return font