How to use the uharfbuzz.FontFuncs.create 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
def test_glyph_h_advance_func(self, blankfont):
        string = "abcde"
        expected = [456, 456, 456, 456, 456]
        buf = hb.Buffer()
        buf.add_str(string)
        buf.guess_segment_properties()

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

        funcs = hb.FontFuncs.create()
        funcs.set_glyph_h_advance_func(h_advance_func, None)
        blankfont.funcs = funcs

        hb.shape(blankfont, buf)
        infos = [pos.x_advance for pos in buf.glyph_positions]
        assert infos == expected
github harfbuzz / uharfbuzz / tests / test_uharfbuzz.py View on Github external
def test_glyph_v_metrics_funcs(self, blankfont):
        string = "abcde"
        expected = [(456, -345, -567)] * 5
        buf = hb.Buffer()
        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
def test_nominal_glyph_func(self, blankfont):
        string = "abcde"
        expected = [97, 98, 99, 100, 101]
        buf = hb.Buffer()
        buf.add_str(string)
        buf.guess_segment_properties()

        def nominal_glyph_func(font, code_point, data):
            return code_point

        funcs = hb.FontFuncs.create()
        funcs.set_nominal_glyph_func(nominal_glyph_func, None)
        blankfont.funcs = funcs

        hb.shape(blankfont, buf)
        infos = [g.codepoint for g in buf.glyph_infos]
        assert infos == expected
github trufont / trufont / src / trufont / objects / layoutEngine.py View on Github external
def __init__(self, font, tables):
        self._font = font
        self._tables = tables
        upem = font.unitsPerEm

        face = hb.Face.create_for_tables(_get_layout_table, tables)
        face.upem = upem
        font = hb.Font.create(face)
        font.scale = (upem, upem)

        funcs = hb.FontFuncs.create()
        funcs.set_nominal_glyph_func(_get_nominal_glyph, self)
        funcs.set_glyph_h_advance_func(_get_glyph_h_advance, self)
        # TODO: vertical advance
        funcs.set_glyph_name_func(_get_glyph_name_func, self)
        font.funcs = funcs

        self._hbFont = font