Node bindings to font-kit(Rust crate)
APACHE-2.0 License
Node.js wrapper for font-kit (Rust crate).
This library works like font-manager.
You cannot get the correct properties with variable fonts.
Check this document if you use this with Electron.
npm install node-font-kit
const { getPathAll, getProps } = require('node-font-kit');
// Get the path of installed fonts
getPathAll().then(list => {
list.forEach((path, i) => console.log(i, path));
});
/*
0 C:\\WINDOWS\\FONTS\\ROBOTO-THIN.TTF
1 C:\\WINDOWS\\FONTS\\CANDARAB.TTF
2 C:\\WINDOWS\\FONTS\\COURBI.TTF
3 C:\\WINDOWS\\FONTS\\UBUNTU-LIGHT.TTF
4 C:\\WINDOWS\\FONTS\\PALA.TTF
5 C:\\WINDOWS\\FONTS\\COMIC.TTF
:
:
*/
getProps('path/to/font.otf').then(props => {
props.forEach((prop) => console.log(prop));
});
/*
{
fullname: 'Mplus 1p',
family: 'Mplus 1p',
postscriptName: 'Mplus1p-Regular',
monospace: false,
weight: 400,
strech: 1,
style: 'Normal'
}
*/
getPathAll() => Promise<string>
Returns a list of font paths as a Promise.
getProps(path: string) => Promise<FontProperty[]>
Returns a list of font properties as a Promise.
FontProperty
type FontProperty = {
fullname: string;
family: string;
postscriptName: string;
monospace: boolean;
weight: number;
strech: number;
style: 'Normal' | 'Italic' | 'Oblique';
};