Parametrized bitmap fonts for embedded-graphics, with font rasterization powered by swash.
Adds an optimal subset of M+ FONTS to your next embedded Rust project.1
| 0.42″ OLED | 1.28″ TFT-LCD |
|---|---|
![]() |
![]() |
- A family of variable-width and monospaced fonts -
mplusfontsallows you to choose between three typefaces, with font properties that you will want to specify. Using this crate, you can have font anti-aliasing and font-based kerning on embedded devices, in ano_stdenvironment. - No font files needed in your project - The
mplus!macro generates Rust code for your bitmap font. After expanding the macro and compiling your code, the TrueType fonts that come with this crate are no longer used. - Includes only the glyphs that you want - The
stringsattribute helps you find and add characters and character clusters to your bitmap font. You can also specify ranges of characters to include as parameters for themplus!macro. - Japanese scripts - Designed by Coji Morishita and licensed under the SIL Open Fonts License (LICENSE), M+ FONTS has support for over 5 700 kanji glyphs.2 Since this crate is based on M+ FONTS, you gain access to all of its features.
- Box-drawing characters -
mplusfontsincludes a set of characters for terminal emulation and semigraphics. These come in the form of scalable vector graphics aligned to the pixel grid and then converted to bitmap images.
- Make sure you have added
mplusfontsas a dependency. - Enable static text rendering by applying an attribute to your function with string definitions.
- Create a bitmap font inside your function so that
#[strings]can find its helper attributes. - Apply
#[strings::emit]to the bitmap font definition. - Include any additional character ranges in the bitmap font that you need.
- Have a character style use the bitmap font.
- You can now start drawing text.
- Exclude any string literals in your function that are not drawn by using
#[strings::skip].
[dependencies]
mplusfonts = "0.3.2"#[mplusfonts::strings]
pub fn main() -> Result<(), Infallible> {
let text = format!("{} KB OK", 16 * 40);
let mut display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(320, 240));
#[strings::emit]
let bitmap_font = mplus!(code(115), BOLD, code_line_height(24), true, 1, 4, '0'..='9');
let character_style = BitmapFontStyle::new(&bitmap_font, Rgb565::GREEN);
Text::new(&text, Point::new(20, 20), character_style).draw(&mut display)?;
let output_settings = OutputSettingsBuilder::new().scale(3).build();
#[strings::skip]
Window::new("Simulator", &output_settings).show_static(&display);
Ok(())
}For more examples, see the examples folder.
The minimum supported Rust version for mplusfonts is 1.85.
The source code of mplusfonts is dual-licensed under:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Footnotes
-
Rust 2024 is required to build this crate ↩

