How to use the uharfbuzz.shape function in uharfbuzz

To help you get started, we’ve selected a few uharfbuzz 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 harfbuzz / uharfbuzz / tests / test_uharfbuzz.py View on Github external
buf.add_str(string)
        buf.guess_segment_properties()
        buf.direction = "TTB"

        def v_advance_func(font, gid, data):
            return 456

        def v_origin_func(font, gid, data):
            return (True, 345, 567)

        funcs = hb.FontFuncs.create()
        funcs.set_glyph_v_advance_func(v_advance_func, None)
        funcs.set_glyph_v_origin_func(v_origin_func, None)
        blankfont.funcs = funcs

        hb.shape(blankfont, buf)
        infos = [(pos.y_advance, pos.x_offset, pos.y_offset) for pos in buf.glyph_positions]
        assert infos == expected
github harfbuzz / uharfbuzz / tests / test_uharfbuzz.py View on Github external
string = "edcba"
        buf = hb.Buffer()
        buf.add_str(string)
        buf.guess_segment_properties()

        messages = []
        infos_trace = []
        positions_trace = []

        def message(msg):
            messages.append(msg)
            infos_trace.append(buf.glyph_infos)
            positions_trace.append(buf.glyph_positions)

        buf.set_message_func(message)
        hb.shape(blankfont, buf)
        gids = [g.codepoint for g in buf.glyph_infos]
        assert gids == [5, 4, 1, 2, 1]
        pos = [g.x_advance for g in buf.glyph_positions]
        assert pos == [0, 0, 0, 100, 0]
        expected_messages = [
            'start table GSUB',
            'start lookup 0',
            'end lookup 0',
            'end table GSUB',
            'start table GPOS',
            'start lookup 0',
            'end lookup 0',
            'end table GPOS',
        ]
        assert messages == expected_messages
        gids_trace = [[g.codepoint for g in infos] for infos in infos_trace]
github googlefonts / fontdiffenator / Lib / diffenator / visualize.py View on Github external
# Draw glyphs
    x, y, baseline = 20, 200, 0
    x_pos = 20
    y_pos = 200
    for row in diff_table[:item_limit]:

        buf = hb.Buffer.create()
        buf.add_str(row['string'])

        buf.guess_segment_properties()
        try:
            features = {f: True for f in row['features']}
            hb.shape(hb_font, buf, features)
        except KeyError:
            hb.shape(hb_font, buf)

        char_info = buf.glyph_infos
        char_pos = buf.glyph_positions
        for info, pos in zip(char_info, char_pos):
            gid = info.codepoint            
            ft_font.load_glyph(gid, flags=6)
            bitmap = slot.bitmap

            if bitmap.width > 0:
                ctx.set_source_rgb(0, 0, 0)
                glyph_surface = _make_image_surface(ft_font.glyph.bitmap, copy=False)
                ctx.set_source_surface(glyph_surface,
                                       x_pos + slot.bitmap_left + (pos.x_offset / 64.),
                                       y_pos - slot.bitmap_top - (pos.y_offset / 64.))
                glyph_surface.flush()
                ctx.paint()
github googlefonts / fontdiffenator / Lib / diffenator / __init__.py View on Github external
def _shape_string(self, font, string, ot_features):
        buf = hb.Buffer.create()
        buf.add_str(string)
        buf.guess_segment_properties()
        try:
            features = {f: True for f in ot_features}
            hb.shape(font.hbfont, buf, features)
        except KeyError:
            hb.shape(font.hbfont, buf)
        return buf
github googlefonts / fontdiffenator / Lib / diffenator / visualize.py View on Github external
hb_font.set_variations(font.axis_locations)
    hb.ot_font_set_funcs(hb_font)

    # Draw glyphs
    x, y, baseline = 20, 200, 0
    x_pos = 20
    y_pos = 200
    for row in diff_table[:item_limit]:

        buf = hb.Buffer.create()
        buf.add_str(row['string'])

        buf.guess_segment_properties()
        try:
            features = {f: True for f in row['features']}
            hb.shape(hb_font, buf, features)
        except KeyError:
            hb.shape(hb_font, buf)

        char_info = buf.glyph_infos
        char_pos = buf.glyph_positions
        for info, pos in zip(char_info, char_pos):
            gid = info.codepoint            
            ft_font.load_glyph(gid, flags=6)
            bitmap = slot.bitmap

            if bitmap.width > 0:
                ctx.set_source_rgb(0, 0, 0)
                glyph_surface = _make_image_surface(ft_font.glyph.bitmap, copy=False)
                ctx.set_source_surface(glyph_surface,
                                       x_pos + slot.bitmap_left + (pos.x_offset / 64.),
                                       y_pos - slot.bitmap_top - (pos.y_offset / 64.))
github trufont / trufont / src / trufont / objects / layoutEngine.py View on Github external
if escape:
                        elem = "/"
                    uni = ord(elem)
                unicodes.append(uni)
            buf.add_codepoints(unicodes)
        else:
            buf.add_str(text)

        buf.guess_segment_properties()
        if direction is not None:
            buf.direction = direction
        if script is not None:
            buf.script = script
        if language is not None:
            buf.language = language
        hb.shape(self._hbFont, buf, features)

        return buf