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_cluster_level(self):
buf = hb.Buffer()
assert buf.cluster_level == hb.BufferClusterLevel.DEFAULT
buf.cluster_level = hb.BufferClusterLevel.MONOTONE_CHARACTERS
assert buf.cluster_level == hb.BufferClusterLevel.MONOTONE_CHARACTERS
buf.cluster_level = hb.BufferClusterLevel.MONOTONE_GRAPHEMES
assert buf.cluster_level == hb.BufferClusterLevel.MONOTONE_GRAPHEMES
buf.cluster_level = hb.BufferClusterLevel.CHARACTERS
assert buf.cluster_level == hb.BufferClusterLevel.CHARACTERS
buf.cluster_level = hb.BufferClusterLevel.DEFAULT
assert buf.cluster_level == hb.BufferClusterLevel.DEFAULT
def test_glyh_name_no_features(self, blankfont, string, expected):
buf = hb.Buffer()
buf.add_str(string)
buf.guess_segment_properties()
hb.shape(blankfont, buf)
# font.get_glyph_name() returns None if the font does not contain glyph names
# or if the glyph ID does not exist.
glyph_names = [blankfont.get_glyph_name(g.codepoint) for g in buf.glyph_infos]
assert glyph_names == expected
assert blankfont.get_glyph_name(1000) is None
# font.glyph_to_string() return "gidN" if the font does not contain glyph names
# or if the glyph ID does not exist.
glyph_names = [blankfont.glyph_to_string(g.codepoint) for g in buf.glyph_infos]
assert glyph_names == expected
assert blankfont.glyph_to_string(1000) == 'gid1000'
def test_gid_and_cluster_no_features(self, blankfont, string, expected):
buf = hb.Buffer()
buf.add_str(string)
buf.guess_segment_properties()
hb.shape(blankfont, buf)
infos = [(g.codepoint, g.cluster) for g in buf.glyph_infos]
assert infos == expected
def test_add_utf8(self):
buf = hb.Buffer()
buf.add_utf8("aбç💩e".encode("utf-8"))
infos = [(g.codepoint, g.cluster) for g in buf.glyph_infos]
assert infos == [(0x61, 0), (0x431, 1), (0xE7, 3), (0x1F4A9, 5), (0x65, 9)]
def test_message_func_crash(self, blankfont):
string = "edcba"
buf = hb.Buffer()
buf.add_str(string)
buf.guess_segment_properties()
message_collector = MessageCollector()
buf.set_message_func(message_collector.message)
hb.shape(blankfont, buf)
def shapeHB(text, font_name, font_size, features: Dict[str, bool] = None):
font = pdfmetrics.getFont(font_name)
if not isinstance(font, TTFont):
# TODO make valid for all types of fonts
raise RLKerningError("Not a TTF font")
fontdata = font.face._ttf_data
face = hb.Face(fontdata)
font = hb.Font(face)
# HB scales to integers in offset and advance so very big scale
# will divide by SCALE_MULT to get the actual size in fractional points
font.scale = (font_size * SCALE_MULT, font_size * SCALE_MULT)
hb.ot_font_set_funcs(font)
buf = hb.Buffer()
buf.add_str(text)
buf.guess_segment_properties()
hb.shape(font, buf, features)
return buf