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