Crates.io | build_pbf_glyphs |
lib.rs | build_pbf_glyphs |
version | 1.4.2 |
source | src |
created_at | 2021-02-18 18:08:16.048533 |
updated_at | 2024-02-13 01:35:44.652896 |
description | A CLI utility for generating protobuf-encoded SDF font glyphs from original source fonts. |
homepage | |
repository | https://github.com/stadiamaps/sdf_font_tools |
max_upload_size | |
id | 357158 |
size | 37,463 |
This binary crate provides a CLI utility for batch converting a directory of fonts into signed distance fields, encoded in a protocol buffer for renderers such as Mapbox GL. This isn't really anything novel; it's just a frontend to pbf_font_tools that behaves similar to node-fontnik, but is faster and (in our opinion) a bit easier to use since it doesn't depend on node and all its headaches, or C++ libraries that need to be built from scratch (this depends on FreeType, but that's widely available on nearly any *nix-based system).
Check out sdf_glyph_renderer for more technical details on how this works.
NOTE: This has requires you to have FreeType installed on your system. We recommend using FreeType 2.10 or newer. Everything will still work against many older 2.x versions, but the glyph generation improves over time so things will generally look better with newer versions.
This tool will create out_dir
if necessary, and will put each range (of 256 glyphs, for
compatibility with MapLibre/Mapbox fontstack convention) in a new subdirectory bearing the font name.
You can install the released version from crates.io, or grab the latest git version by
running cargo install build_pbf_glyphs
.
$ build_pbf_glyphs /path/to/font_dir /path/to/out_dir
By default, existing glyphs will not be overwritten as this is normally a waste of CPU.
You can change this by adding the --overwrite
flag.
For some applications, it may be desirable to combine glyphs upfront. While this is a cheap operation, computationally speaking, this may be convenient if you want to keep your server logic simple. If you only use one font in the list, simple static file serving of a directory will suffice.
This tool can pre-combine the glyphs for you using the -c <spec.json>
command line switch.
The file should contain a JSON dictionary having a format like so:
{
"New Font Name": ["Font 1", "Font 2"]
}
This is run as a separate pass after all glyphs have been generated, so all fonts are assumed to
have valid glyphs already in out_dir
.