#font #true-type #webfonts #split #turning #subsets #path

bin+lib mkwebfont

A simple tool for turning .ttf/.otf files into webfonts

2 releases

0.1.1 Apr 8, 2024
0.1.0 Apr 8, 2024

#955 in Command line utilities

Download history 157/week @ 2024-04-02 78/week @ 2024-04-09

235 downloads per month

Apache-2.0

10MB
29K SLoC

C 20K SLoC // 0.1% comments C++ 6K SLoC // 0.1% comments Python 2K SLoC // 0.4% comments Rust 1K SLoC // 0.0% comments Bazel 275 SLoC // 0.1% comments Lua 62 SLoC Automake 26 SLoC // 0.1% comments Shell 24 SLoC Forge Config 4 SLoC

Contains (obscure autoconf code, 1KB) contrib/woff2/brotli/configure.ac

mkwebfont

mkwebfont is a simple tool for turning .ttf/.otf files into webfonts for self-hosting, without the complication or lack of flexibility that prepackaged webfonts or hosted webfonts have. It's designed to be an easy one-command solution that doesn't require complicated scripts or specific understanding of .woff2 or fonts to make work.

Like Google Fonts, it splits the fonts into subsets that allows only part of the font to be loaded as needed, usually based on the languages used.

Usage

To install it, simply run the following command:

cargo install mkwebfont

Then, run the following command to create a webfont:

# Assumes that you serve `https://example.com/` from a directory of `/srv/http/root`.
# Adjust these paths for your use case
mkdir -p /srv/http/webroot/static/webfonts
mkwebfont \
    --store /srv/http/webroot/static/webfonts --store-uri "https://example.com/static/webfonts/" \
    -o /srv/http/webroot/static/fonts.css fonts/* 

After this, you can simply include the stylesheet at https://example.com/static/fonts.css, and then you can use any fonts that you included in the command line (e.g. with the fonts/* in the example) in your website.

License

This project is licensed under the Apache License Version 2.0.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in mkwebfont by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

Dependencies

~18MB
~493K SLoC