]>
git.kianting.info Git - uann/blob - src/harfbuzz.ts
437558d4af75b493c9ee4ee1f197ca0772fc62e9
1 var hb
= require('harfbuzzjs/hbjs');
2 var fs
= require('fs');
4 export function harfbuzzTest(inputString
: string){
5 WebAssembly
.instantiate(fs
.readFileSync(__dirname
+"/../3rdparty/harfbuzzjs/hb.wasm"))
11 let fontdata
= fs
.readFileSync("/usr/share/fonts/truetype/freefont/FreeSerif.ttf");
13 //hbjs(fontdata.instance);
17 var blob
= hb
.createBlob(fontdata
); // Load the font data into something Harfbuzz can use
18 var face
= hb
.createFace(blob
, 0); // Select the first font in the file (there's normally only one!)
19 var font
= hb
.createFont(face
); // Create a Harfbuzz font object from the face
20 var buffer
= hb
.createBuffer(); // Make a buffer to hold some text
21 buffer
.addText(inputString
); // Fill it with some stuff
22 buffer
.guessSegmentProperties(); // Set script, language and direction
23 hb
.shape(font
, buffer
); // Shape the text, determining glyph IDs and positions
24 var output
: Array<{g
: number,
27 dy
: number}> = buffer
.json();
29 // Enumerate the glyphs
30 console
.log("id\tax\tdx\tdy");
34 for (var glyph
of output
) {
35 var glyphId
= glyph
.g
;
36 var xAdvance
= glyph
.ax
;
37 var xDisplacement
= glyph
.dx
;
38 var yDisplacement
= glyph
.dy
;
40 var svgPath
= font
.glyphToPath(glyphId
);
42 console
.log(glyphId
+ "\t" + xAdvance
+ "\t" + xDisplacement
+ "\t" + yDisplacement
);
44 // You need to supply this bit
45 //drawAGlyph(svgPath, xCursor + xDisplacement, yDisplacement);
47 // xCursor += xAdvance;