mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* 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
20 lines
435 B
TypeScript
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('|');
|