]> git.kianting.info Git - clo/blob - 參考資料-Harfbuzz如何使用.py
add readme and todo
[clo] / 參考資料-Harfbuzz如何使用.py
1 import sys
2
3 import uharfbuzz as hb
4
5
6 fontfile = sys.argv[1]
7 text = sys.argv[2]
8
9 blob = hb.Blob.from_file_path(fontfile)
10 face = hb.Face(blob)
11 font = hb.Font(face)
12
13 px = 96
14 scale = 1000000.0/952997
15 font.scale = (px *scale* 1024, px*scale * 1024)
16
17 buf = hb.Buffer()
18 buf.add_str(text)
19 buf.guess_segment_properties()
20
21 features = {"kern": True, "liga": True}
22 hb.shape(font, buf, features)
23
24 infos = buf.glyph_infos
25 positions = buf.glyph_positions
26
27 for info, pos in zip(infos, positions):
28 gid = info.codepoint
29 cluster = info.cluster
30 x_advance = pos.x_advance / 1024
31 y_advance = pos.y_advance / 1024
32 x_offset = pos.x_offset / 1024
33 y_offset = pos.y_offset /1024
34 print(f"gid{gid}={cluster}@{x_advance},{y_offset}+{x_advance},{y_advance}")