UNPKG

2.42 kBMarkdownView Raw
1# node-fontnik
2
3[![NPM](https://nodei.co/npm/fontnik.png?compact=true)](https://nodei.co/npm/fontnik/)
4[![Build Status](https://travis-ci.org/mapbox/node-fontnik.svg?branch=master)](https://travis-ci.org/mapbox/node-fontnik)
5[![codecov](https://codecov.io/gh/mapbox/node-fontnik/branch/master/graph/badge.svg)](https://codecov.io/gh/mapbox/node-fontnik)
6
7A 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.
8
9The 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.
10
11See also [TinySDF](https://github.com/mapbox/tiny-sdf), which is a faster but less precise approach to generating SDFs for fonts.
12
13## [API](API.md)
14
15## Installing
16
17By default, installs binaries. On these platforms no external dependencies are needed.
18
19- 64 bit OS X or 64 bit Linux
20- Node.js v8-v14
21
22Just run:
23
24```
25npm install
26```
27
28However, other platforms will fall back to a source compile: see [building from source](#building-from-source) for details.
29
30## Building from source
31
32```
33npm install --build-from-source
34```
35Building from source should automatically install `boost`, `freetype` and `protozero` locally using [mason](https://github.com/mapbox/mason). These dependencies can be installed manually by running `./scripts/install_deps.sh`.
36
37## Local testing
38
39Run tests with
40
41```
42npm test
43```
44
45If you make any changes to the C++ files in the `src/` directory, you'll need to recompile the node bindings (`fontnik.node`) before testing locally:
46
47```
48make
49```
50
51See the `Makefile` for additional tasks you can run, such as `make coverage`.
52
53## Background reading
54- [Drawing Text with Signed Distance Fields in Mapbox GL](https://www.mapbox.com/blog/text-signed-distance-fields/)
55- [State of Text Rendering](http://behdad.org/text/)
56- [Pango vs HarfBuzz](http://mces.blogspot.com/2009/11/pango-vs-harfbuzz.html)
57- [An Introduction to Writing Systems & Unicode](http://rishida.net/docs/unicode-tutorial/)