Пример #1
0
def runHB(direction, script, language, features, text, fontname, positions):
    font = getHbFont(fontname)
    buf = HarfBuzz.buffer_create()
    text = toUnicode(text)
    HarfBuzz.buffer_add_utf8(buf, text.encode('utf-8'), 0, -1)
    HarfBuzz.buffer_set_direction(buf, HarfBuzz.direction_from_string(toBytes(direction)))
    HarfBuzz.buffer_set_script(buf, HarfBuzz.script_from_string(toBytes(script)))
    if language:
        HarfBuzz.buffer_set_language(buf, HarfBuzz.language_from_string(toBytes(language)))

    if features:
        features = [HarfBuzz.feature_from_string(toBytes(fea))[1] for fea in features.split(',')]
    else:
        features = []
    HarfBuzz.shape(font, buf, features)

    info = HarfBuzz.buffer_get_glyph_infos(buf)
    ttfont = getTtFont(fontname)
    if positions:
        pos = HarfBuzz.buffer_get_glyph_positions(buf)
        glyphs = []
        for i, p in zip(info, pos):
            glyph = ttfont.getGlyphName(i.codepoint)
            if p.x_offset or p.y_offset:
                glyph += "@%d,%d" % (p.x_offset, p.y_offset)
            glyph += "+%d" % p.x_advance
            if p.y_advance:
                glyph += ",%d" % p.y_advance
            glyphs.append(glyph)
        out = "|".join(glyphs)
    else:
        out = "|".join([ttfont.getGlyphName(i.codepoint) for i in info])

    return "[%s]" % out