Native bindings to
fonttools
to decompile and compile fonts.
fonttools
(also known as TTX) is a library for manipulating fonts,
written in Python. It supports TrueType, OpenType, AFM and to an extent Type 1,
and some Mac-specific formats. Using Addons it's possible to bridge Python
to Node, natively, using C++ and Python's Python/C APIโwhich is
exactly what node-fontools
does.
So far, the only functions that have been bridged are the abilities to decompile fonts to XML and compile XML to font binary.
Python 2.7 is the only supported version at the moment.
import fonttools from 'fonttools';
import { readFileSync } from 'fs';
// Get the `decompile` and `compile` methods
const { decompile, compile } = fonttools();
// Read a font file as a buffer
const fontBuffer = readFileSync('font.ttf');
// Decompile the font to another buffer
const fontXMLBuffer = decompile(fontBuffer);
// Insert logic here to manipulate font
// Compile font from an XML file as a buffer
const fontBinaryBuffer = compile(fontXMLBuffer);
// Insert logic to save font file buffer here
A function that takes a path to fonttools/Lib
and returns an object with
two methods: decompile
and compile
. By default it uses the included
submodule.
Takes a font file buffer and returns another buffer with the XML of the decompiled font.
Takes an XML file buffer and returns another buffer with the compiled font file binary.
More on Node Buffers