glyphr 0.6.0

A no_std, lightweight and simple font rasterizing library
Documentation

Glyphr

License Crates.io Downloads Docs CI

This library focus is not to be the fastest, but one of the most beautiful in the embedded world.

Features

  • Completely intuitive
  • You decide how pixel are written on the screen
  • No heap allocation
  • Compile time font bitmaps generation
  • Full Unicode support

How To Build

To get started visit glyphr-macros for detailed instructions on how to generate fonts, then proceed in this page.

How To Use

The renderer is callback-first. You provide dimensions and closures; glyphr does not store your framebuffer.

Create Glyphr with a builder-style config:

use glyphr::{Callbacks, Glyphr, RenderConfig, SdfConfig};

let conf = RenderConfig::default()
    .with_color(0x00ff_ffff)
    .with_sdf(SdfConfig::default().with_size(64).with_smoothing(0.5));
let renderer = Glyphr::with_config(conf);

let mut target = Callbacks::new(800, 480, |x, y, argb| {
    // Your callback decides how to write pixels.
    let _ = (x, y, argb);
    true
});

Render text with draw_text:

use glyphr::{ TextAlign, AlignV, AlignH };

renderer
    .draw_text(
        &mut target,
        "Hello World!",
        POPPINS,
        100,
        50,
        TextAlign::new(AlignH::Left, AlignV::Baseline),
    )
    .unwrap();

For DMA-style pipelines, use draw_text_bulk to get one ARGB tile per glyph:

use glyphr::{AlignH, AlignV, BulkCallbacks, TextAlign};

let mut scratch = [0u32; 4096];
let mut bulk = BulkCallbacks::new(800, 480, &mut scratch, |x, y, w, h, pixels| {
    // Example: queue one DMA2D blit for this glyph tile.
    let _ = (x, y, w, h, pixels);
    true
});

renderer
    .draw_text_bulk(
        &mut bulk,
        "Hello DMA2D!",
        POPPINS,
        100,
        50,
        TextAlign::new(AlignH::Left, AlignV::Baseline),
    )
    .unwrap();

[!TIP] If you want to run an example on your machine you can just do:

cargo run --example glyphr_test --features "toml window"

Bulk callback example:

cargo run --example glyphr_bulk --features "window"