# fontnik

> A library that delivers a range of glyphs rendered as SDFs (signed distance fields) in a protobuf.

Latest version **0.7.7** (published 2026-07-02) · 0 weekly downloads

## Install

```sh
npm install fontnik
pnpm add fontnik
yarn add fontnik
bun add fontnik
```

Provides the commands `build-glyphs`, `font-inspect`.

## Health

**Score 45/100 (D)** — status: active.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.7.7 |
| Published | 2026-07-02 |
| First published | 2014-06-10 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=20 |
| Dependencies | 3 |
| Unpacked size | 3.6 MB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 248 |
| Maintainers | mapbox-npm-01, mapbox-npm-02, mapbox-npm-07, mapbox-npm-03, mapbox-npm-04, mapbox-npm-09, mapbox-npm-05, mapbox-npm-06, mapbox-npm-08, mapbox-npm-advanced-actions, mapbox-npm-ci, mapbox-npm, mapbox-admin, mapbox-machine-user, mbx-npm-ci-staging, mbx-npm-ci-production, mbx-npm-01-production, mbx-npm-02-production, mbx-npm-03-production, mbx-npm-04-production, mbx-npm-05-production, mbx-npm-06-production, mbx-npm-07-production, mbx-npm-08-production, mbx-npm-09-production, mbx-npm-02-staging, mbx-npm-advanced-actions-staging, mbx-npm-advanced-actions-production |
| Keywords | font, text, glyph, freetype, sdf |

## Links

- npm: https://www.npmjs.com/package/fontnik
- Repository: https://github.com/mapbox/node-fontnik
- Homepage: https://github.com/mapbox/node-fontnik#readme
- Issues: https://github.com/mapbox/node-fontnik/issues
- npm.io page: https://npm.io/package/fontnik

## Dependencies (3)

- [glob](https://npm.io/package/glob.md) ^7.1.6
- [d3-queue](https://npm.io/package/d3-queue.md) ^3.0.7
- [minimist](https://npm.io/package/minimist.md) ^1.2.5

## Alternatives

- [@fortawesome/react-fontawesome](https://npm.io/package/@fortawesome/react-fontawesome.md) — 2.2M weekly downloads
- [roboto-fontface](https://npm.io/package/roboto-fontface.md) — 196.0K weekly downloads
- [@react-native-vector-icons/common](https://npm.io/package/@react-native-vector-icons/common.md) — 150.4K weekly downloads
- [stockfish](https://npm.io/package/stockfish.md) — 27.0K weekly downloads
- [@procore/core-icons](https://npm.io/package/@procore/core-icons.md) — 4.6K weekly downloads

## Recent versions

- 0.7.7 (latest) — 2026-07-02
- 0.7.4-dev.2 (dev) — 2025-07-04
- 0.7.6 — 2026-06-29
- 0.7.5 — 2026-06-29
- 0.7.4 — 2025-07-04
- 0.7.4-dev.1 — 2025-07-03
- 0.7.4-dev.0 — 2025-07-03
- 0.7.3 — 2025-07-02
- 0.7.2 — 2023-04-24
- 0.7.2-dev.4 — 2023-04-18
- 0.7.2-dev.3 — 2023-04-05
- 0.7.2-dev.2 — 2023-03-31
- 0.7.1 — 2023-02-23
- 0.7.1-dev.1 — 2023-01-30
- 0.7.0 — 2022-10-19
- … 28 more at https://npm.io/package/fontnik/versions

## README

# node-fontnik

A library that delivers a range of glyphs rendered as SDFs (signed distance fields) in a protocol buffer. We use these encoded glyphs as the basic blocks of font rendering in [Mapbox GL](https://github.com/mapbox/mapbox-gl-js). SDF encoding is superior to traditional fonts for our usecase in terms of scaling, rotation, and quickly deriving halos - WebGL doesn't have built-in font rendering, so the decision is between vectorization, which tends to be slow, and SDF generation.

The approach this library takes is to parse and rasterize the font with Freetype (hence the C++ requirement), and then generate a distance field from that rasterized image.

See also [TinySDF](https://github.com/mapbox/tiny-sdf), which is a faster but less precise approach to generating SDFs for fonts.

## [API](API.md)

## Installing

Prebuilt binaries are included in the npm package for:

- macOS arm64 (`darwin-arm64`)
- macOS x64 (`darwin-x64`)
- Linux x64 (`linux-x64`)
- Linux arm64 (`linux-arm64`)

```
npm install
```

On other platforms, or when no matching prebuild exists, `npm install` compiles from source via CMake (see below). Node.js 20 or later is required.

## Building from source

Install system dependencies:

**macOS**

```
brew install cmake ninja boost zlib
```

**Linux (Debian/Ubuntu)**

```
sudo apt-get install cmake ninja-build zlib1g-dev libboost-dev
```

Then build:

```
npm run rebuild
```

N-API headers (`node-addon-api`, `node-api-headers`), `protozero`, and FreeType are fetched automatically by CMake at configure time.

## Local testing

```
npm test
```

After changing C++ sources in `src/`, rebuild the native module:

```
make
```

See the `Makefile` for `coverage`, `sanitize`, `tidy`, `format`, and Linux Docker testing (`make test-linux`).

### Linux builds via Docker

To mirror CI on a Mac (or any host with Docker), build and test inside Ubuntu 22.04 containers matching GHA:

```
./scripts/docker-linux-test.sh              # linux-x64 + linux-arm64, Release
./scripts/docker-linux-test.sh x64 Debug    # single arch / build type
```

Release builds write `prebuilds/linux-<arch>/fontnik.node` directly (same as local `npm run rebuild`).

Or `make test-linux` / `make test-linux-x64`. Use `--rebuild-image` after changing `scripts/docker/Dockerfile`.

## Release

See [DEV.md](./DEV.md).

## Background reading
- [Drawing Text with Signed Distance Fields in Mapbox GL](https://www.mapbox.com/blog/text-signed-distance-fields/)
- [State of Text Rendering](http://behdad.org/text/)
- [Pango vs HarfBuzz](http://mces.blogspot.com/2009/11/pango-vs-harfbuzz.html)
- [An Introduction to Writing Systems & Unicode](http://rishida.net/docs/unicode-tutorial/)

---
_Source: https://npm.io/package/fontnik · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
