diff options
Diffstat (limited to 'python/python3-uharfbuzz/example.py')
-rw-r--r-- | python/python3-uharfbuzz/example.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/python/python3-uharfbuzz/example.py b/python/python3-uharfbuzz/example.py new file mode 100644 index 0000000000..124b8644a1 --- /dev/null +++ b/python/python3-uharfbuzz/example.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 + +import sys + +import uharfbuzz as hb + + +fontfile = sys.argv[1] +text = sys.argv[2] + +blob = hb.Blob.from_file_path(fontfile) +face = hb.Face(blob) +font = hb.Font(face) + +buf = hb.Buffer() +buf.add_str(text) +buf.guess_segment_properties() + +features = {"kern": True, "liga": True} +hb.shape(font, buf, features) + +infos = buf.glyph_infos +positions = buf.glyph_positions + +for info, pos in zip(infos, positions): + gid = info.codepoint + glyph_name = font.glyph_to_string(gid) + cluster = info.cluster + x_advance = pos.x_advance + x_offset = pos.x_offset + y_offset = pos.y_offset + print(f"{glyph_name} gid{gid}={cluster}@{x_advance},{y_offset}+{x_advance}") |