Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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
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