]>
git.kianting.info Git - uann/blob - src/harfbuzz.js
7b9fa59d2ef4848ee5388dc3fddd4683d3b3edfb
2 Object
.defineProperty(exports
, "__esModule", { value
: true });
3 exports
.harfbuzzTest
= void 0;
4 var hb
= require('harfbuzzjs/hbjs');
5 var fs
= require('fs');
6 // some part of code derived from that by Ebrahim Byagowi,
8 function harfbuzzTest(inputString
) {
9 WebAssembly
.instantiate(fs
.readFileSync(__dirname
+ "/../3rdparty/harfbuzzjs/hb.wasm"))
10 .then(function (wsm
) {
11 hb
= hb(wsm
.instance
);
12 let fontdata
= fs
.readFileSync("/usr/share/fonts/truetype/freefont/FreeSerif.ttf");
13 //hbjs(fontdata.instance);
15 var blob
= hb
.createBlob(fontdata
); // Load the font data into something Harfbuzz can use
16 var face
= hb
.createFace(blob
, 0); // Select the first font in the file (there's normally only one!)
17 var font
= hb
.createFont(face
); // Create a Harfbuzz font object from the face
18 var buffer
= hb
.createBuffer(); // Make a buffer to hold some text
19 buffer
.addText(inputString
); // Fill it with some stuff
20 buffer
.guessSegmentProperties(); // Set script, language and direction
21 hb
.shape(font
, buffer
); // Shape the text, determining glyph IDs and positions
22 var output
= buffer
.json();
23 // Enumerate the glyphs
24 console
.log("id\tax\tdx\tdy");
27 for (var glyph
of output
) {
28 var glyphId
= glyph
.g
;
29 var xAdvance
= glyph
.ax
;
30 var xDisplacement
= glyph
.dx
;
31 var yDisplacement
= glyph
.dy
;
32 var svgPath
= font
.glyphToPath(glyphId
);
33 console
.log(glyphId
+ "\t" + xAdvance
+ "\t" + xDisplacement
+ "\t" + yDisplacement
);
34 // You need to supply this bit
35 //drawAGlyph(svgPath, xCursor + xDisplacement, yDisplacement);
36 // xCursor += xAdvance;
45 exports
.harfbuzzTest
= harfbuzzTest
;