glyphr-macros

Crates.ioglyphr-macros
lib.rsglyphr-macros
version0.1.2
created_at2025-06-13 23:35:26.600481+00
updated_at2025-09-09 11:34:04.27028+00
descriptionSet of proc-macros used to generate fonts for glyphr
homepage
repositoryhttps://github.com/Bridiro/glyphr
max_upload_size
id1711978
size73,676
Alessandro Bridi (Bridiro)

documentation

README

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.

Commit count: 110

cargo fmt