X-Git-Url: https://git.kianting.info/?a=blobdiff_plain;f=%E5%8F%83%E8%80%83%E8%B3%87%E6%96%99-Harfbuzz%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8.py;fp=%E5%8F%83%E8%80%83%E8%B3%87%E6%96%99-Harfbuzz%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8.py;h=128ade27c72695743b2d73cdef0db6c03671ee8e;hb=c3dc58d74afa6b298d84bad90d63c027a32a954a;hp=0000000000000000000000000000000000000000;hpb=796e0c20c767e214b104fa3d17e754ce58da6e73;p=clo diff --git "a/\345\217\203\350\200\203\350\263\207\346\226\231-Harfbuzz\345\246\202\344\275\225\344\275\277\347\224\250.py" "b/\345\217\203\350\200\203\350\263\207\346\226\231-Harfbuzz\345\246\202\344\275\225\344\275\277\347\224\250.py" new file mode 100644 index 0000000..128ade2 --- /dev/null +++ "b/\345\217\203\350\200\203\350\263\207\346\226\231-Harfbuzz\345\246\202\344\275\225\344\275\277\347\224\250.py" @@ -0,0 +1,34 @@ +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) + +px = 96 +scale = 1000000.0/952997 +font.scale = (px *scale* 1024, px*scale * 1024) + +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 + cluster = info.cluster + x_advance = pos.x_advance / 1024 + y_advance = pos.y_advance / 1024 + x_offset = pos.x_offset / 1024 + y_offset = pos.y_offset /1024 + print(f"gid{gid}={cluster}@{x_advance},{y_offset}+{x_advance},{y_advance}") \ No newline at end of file