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