DefinitelyTyped/types/fontkit/fontkit-tests.ts
Teodor Tanasoaia 6a2c72f79b [fontkit] add definitions (#40527)
* add fontkit declaration file

* add tslint

* add tsconfig

* fix linting issues

* add dom lib

* add test file

* include test file

* fix test file

* fix linting issues

* add default export

* fix export

* use a module

* new way of exporting

* fix linting issues
2019-11-22 08:43:50 -08:00

20 lines
435 B
TypeScript

import fontkit from 'fontkit';
const f = fontkit.openSync('fonts/a-font.ttf');
const { glyphs, positions } = f.layout('Hello World!');
const res = [];
for (let i = 0; i < glyphs.length; i++) {
const glyph = glyphs[i];
const pos = positions[i];
let x = `${glyph.id}`;
if (pos.xOffset || pos.yOffset) {
x += `@${pos.xOffset},${pos.yOffset}`;
}
x += `+${pos.xAdvance}`;
res.push(x);
}
res.join('|');