Crate embedded_ttf

Crate embedded_ttf 

Source
Expand description

Font rendering (ttf and otf) with embedded-graphics.

Embedded graphics provides static mono font rendering directly from the code. But it can render any font if the proper trait is implemented.

This is an implementation that uses the rusttype crate to parse ttf and otf fonts before rendering them on a DrawTarget

§Usage

Use FontTextStyleBuilder to easily create a FontTextStyle object.

This style can then be directly used with embedded graphics’ [Text] struct.

let mut display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(350, 200));

let style = FontTextStyleBuilder::new(
    Font::try_from_bytes(include_bytes!("../assets/Roboto-Regular.ttf")).unwrap())
    .font_size(16)
    .text_color(Rgb565::WHITE)
    .build();

Text::new("Hello World!", Point::new(15, 30), style).draw(&mut display)?;

§Antialiasing

TrueType fonts are much nicer with antialiasing. However, embedded_graphics does not support retrieving current pixel while drawing, which prevents alpha blending and antialiasing.

If you have a background color, the color is known and antialiasing is applied. Otherwise, you can use the AntiAliasing enum either to disable antialiasing or to define an antialiasing background color.

Structs§

FontTextStyle
Style properties for text using a ttf and otf font.
FontTextStyleBuilder
Text style builder for ttf and otf fonts.

Enums§

AntiAliasing
Antialiasing can be challenging with embedded graphics since the background pixel is not known during the drawing process.