Skip to content

iriswebb/femtofont

Repository files navigation

FemtoFont - Fast, featured, embedded friendly TTF renderer

FemtoFont is a no_std rasterizer for scalable fonts (.ttf, .otf, .ttc), it includes variable fonts, configurable caching, pixel and subpixlel anti-aliasing, and a basic layout engine. It attempts to limit stack and heap usage to a point where it is usable in embedded projects while retaining speed.

Although its layout engine doesn't shape glyphs, rustybuzz (or harfrust) could be used to do so in conjunction with it.

FemtoFont can run in extremely low amounts of memory, rendering small fonts in as little as 4KB of stack space and less than 64KB of heap space.

FemtoFont is a fork of fontdue, which itself is a fork of font-rs. And is based off the ttf_parser API

Quickstart

Using eg-femtofont on embedded-graphics:

// load the font from raw data
let font = include_bytes!("assets/path_to_font.ttf") as &[u8];
let font = femtofont::Font::from_bytes_with_weight(font, 600.0, femtofont::FontSettings::default()).unwrap();

// Red text anti-aliased as if it were on a blue background
let style = eg_femtofont::FemtoFontTextStyle::with_aa_color(&font, Rgb888::RED, Rgb888::BLUE, 20);
let rendered_text = Text::new("FemtoFont", Point::new(100, 100), style);

// Draw
rendered_text.draw(&mut display).unwrap();

Goals

  1. Keeping the stack and heap intact (<4K stack, <64k heap)
  2. Ease of use
  3. Portability
  4. Features
  5. Speed

Changes from fontdue

  • Using the portable implementations of simd and floating point math inside core instead of manually optimizing them
  • Removing most pre-render caching and replacing it with optional render-time caching
  • Adding support for variable fonts by coupling the API closer to ttf_parser's
  • Arc-ing font faces to preserve stack space and to allow multiple Font's to use the same Face

Other font rendering crates

Non-shaping rasterizers:

License

Licensed under either Apache, MIT, or zlib

About

A fast, featured, embedded friendly TTF renderer for rust

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages