#font #sdf #codegen #proc-macro #graphics

macro glyphr-macros

Set of proc-macros used to generate fonts for glyphr

3 releases

Uses new Rust 2024

0.1.2 Sep 9, 2025
0.1.1 Jun 17, 2025
0.1.0 Jun 13, 2025

#56 in #sdf

Download history

257 downloads per month
Used in glyphr

Apache-2.0

57KB
1.5K SLoC

glyphr-macros

This crate contains proc-macros used to generate code at compile time easily. glyphr is an indirect dependency of this crate, as it generates types that are present only there.

generate_font!

glyphr_macros::generate_font! {
    name: POPPINS,
    path: "fonts/Poppins-Regular.ttf",
    size: 64,
    characters: "A-Za-z0-9 !$£%&",
    format: SDF {
        spread: 20.0,
        padding: 0,
    },
}

generate_font_from_toml!

glyphr_macros::generate_font_from_toml!("fonts/fonts.toml");

with the toml looking like this:

[[font]]
name = "POPPINS"
path = "Poppins-Regular.ttf"
size = 64
characters = "A-Za-z0-9 !$£%&"
format = { SDF = { spread = 20.0, padding = 0}}

The TOML functionality is behind a feature called toml that is enabled by default in glyphr itself.

Format can either be SDF or Bitmap.

Differences between the 2 formats:

SDF

SDF is the prettier format, as it enables the user to resize the generated code at runtime. As resizing and calculating positions require computation, it's suggested to use this option for text that needs to be pretty, but at the same time not with the fastest refresh rate (only if you're on an MCU or similar).

Bitmap

This is the fast and memory efficient way. Font generated this way can't be rescaled at runtime, but it's generally 8x smaller than an SDF generated font. This means that if you only need from 1 to 4 sizes, you can use this to save space.

Dependencies

~3MB
~61K SLoC