Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dfrankland/node-fonttools
π Native bindings to `fonttools` to decompile and compile fonts.
https://github.com/dfrankland/node-fonttools
Last synced: 28 days ago
JSON representation
π Native bindings to `fonttools` to decompile and compile fonts.
- Host: GitHub
- URL: https://github.com/dfrankland/node-fonttools
- Owner: dfrankland
- Created: 2017-02-06T02:33:47.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-03T16:08:35.000Z (over 6 years ago)
- Last Synced: 2024-11-08T00:52:06.402Z (about 1 month ago)
- Language: C++
- Homepage: https://www.npmjs.com/package/fonttools
- Size: 177 KB
- Stars: 10
- Watchers: 5
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-typography - node-fonttools - Native bindings to fonttools to decompile and compile fonts. (JavaScript)
README
# `node-fonttools`
> Native bindings to [`fonttools`][1] to decompile and compile fonts.
## How It Works
[`fonttools`][1] (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][2] it's possible to bridge Python
to Node, natively, using C++ and Python's [Python/C API][3]βwhich is
exactly what `node-fontools` does.## Current Status
So far, the only functions that have been bridged are the abilities to decompile
fonts to XML and compile XML to font binary.### Requirements
Python 2.7 is the only supported version at the moment.
## How To Use
```js
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
```### `fonttools`
A function that takes a path to [`fonttools/Lib`][4] and returns an object with
two methods: `decompile` and `compile`. By default it uses the [included
submodule][5].#### `decompile`
Takes a font file buffer and returns another buffer with the XML of the
decompiled font.#### `compile`
Takes an XML file buffer and returns another buffer with the compiled font file
binary.> More on [Node Buffers][6]
[1]: https://github.com/fonttools/fonttools
[2]: https://nodejs.org/api/addons.html
[3]: https://docs.python.org/2/c-api/
[4]: https://github.com/fonttools/fonttools/tree/master/Lib
[5]: https://github.com/dfrankland/node-fonttools/blob/master/.gitmodules
[6]: https://nodejs.org/api/buffer.html