]> git.kianting.info Git - clo/blob - src/harfbuzz.js
initial commit
[clo] / src / harfbuzz.js
1 "use strict";
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"))
8 .then(function (wsm) {
9 hb = hb(wsm.instance);
10 let fontdata = fs.readFileSync("/usr/share/fonts/truetype/freefont/FreeSerif.ttf");
11 //hbjs(fontdata.instance);
12 //console.log(a);
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");
23 var xCursor = 0;
24 var yCursor = 0;
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;
35 }
36 // Release memory
37 buffer.destroy();
38 font.destroy();
39 face.destroy();
40 blob.destroy();
41 });
42 }
43 exports.harfbuzzTest = harfbuzzTest;