From 5bf5f5cbe5ea126867fbc1ffb9d88dec36e94931 Mon Sep 17 00:00:00 2001 From: Tan Kian-ting Date: Fri, 3 Nov 2023 00:35:17 +0800 Subject: [PATCH] add personal notes for measuring text --- ...7\346\270\254\346\226\207\345\255\227.txt" | 62 +++++++++++++++++++ ...02\344\275\225\344\275\277\347\224\250.py" | 34 ---------- 2 files changed, 62 insertions(+), 34 deletions(-) create mode 100644 "src/\351\207\217\346\270\254\346\226\207\345\255\227.txt" delete mode 100644 "\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" diff --git "a/src/\351\207\217\346\270\254\346\226\207\345\255\227.txt" "b/src/\351\207\217\346\270\254\346\226\207\345\255\227.txt" new file mode 100644 index 0000000..0e80d38 --- /dev/null +++ "b/src/\351\207\217\346\270\254\346\226\207\345\255\227.txt" @@ -0,0 +1,62 @@ +import * as fontkit from "fontkit"; +var font = await fontkit.openSync('/home/yoxem/桌面/TMP/ts-playground/aliputtat/LinLibertine_DR.otf'); +var run = font.layout('a̍h',undefined, undefined, undefined, "ltr"); + +for (var i=0;i<=2;i++){ +console.log(run.glyphs[i]._metrics); +console.log(run.glyphs[i].bbox); // bounding box +console.log(run.glyphs[i].advanceWidth); +} + + +/*結果: + +假設文字大小為16(px)(=12pt),則下面的數字單位為 +16/1000 px = [文字pt值]*(4/3)/1000 px +454 即 454*16/1000 px;1140即1140*16/1000 px等等。 +*/ + +{ + advanceWidth: 454, // 游標前進的長度 + advanceHeight: 1140, // 游標往下的長度 + leftBearing: 42, + topBearing: 475 +} +$f34600ab9d7f70d8$export$2e2bcd8739ae039 { + minX: 42, // 文字最左邊的x座標 + minY: -10, // 文字最下邊的y座標 + maxX: 441, // 文字最右邊的座標 + maxY: 419 // 文字最上的座標 + +} +//文字glyph字圖寬度 = (441-42)*16/1000 px +//文字glyph字圖高度 = (419-(-10))*16/1000 px + + +454 +{ + advanceWidth: 0, + advanceHeight: 1140, + leftBearing: -181, + topBearing: 184 +} +$f34600ab9d7f70d8$export$2e2bcd8739ae039 { + minX: -181, + minY: 548, + maxX: -127, + maxY: 710 +} +0 +{ + advanceWidth: 511, + advanceHeight: 1140, + leftBearing: 18, + topBearing: 196 +} +$f34600ab9d7f70d8$export$2e2bcd8739ae039 { + minX: 18.5, + minY: -5, + maxX: 499.75, + maxY: 698 +} +511 \ No newline at end of file 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" deleted file mode 100644 index 128ade2..0000000 --- "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" +++ /dev/null @@ -1,34 +0,0 @@ -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 -- 2.39.2