packed_font_structs/
lib.rs1#![no_std]
2
3use bytemuck::{AnyBitPattern, NoUninit};
4use embedded_graphics_core::pixelcolor::Gray4;
5
6pub const AA_BITS: u8 = 4;
7pub type AaColor = Gray4;
8
9#[derive(Debug, Clone)]
10pub struct FontMetrics {
11 pub ascent: i8,
12 pub descent: i8,
13 pub leading: u8,
14}
15
16#[derive(Debug, NoUninit, AnyBitPattern, Clone, Copy)]
17#[repr(C)]
18pub struct Metrics {
19 pub left_bearing: i8,
20 pub top_bearing: i8,
21 pub width: u8,
22 pub advance: u8,
23}
24
25pub fn all_chars() -> impl Iterator<Item = char> {
26 ('\x20'..='\x7e').into_iter().chain(['°'])
27}
28
29pub const fn map_character(chr: char) -> Option<u8> {
30 const BASE: u8 = 0x20;
31 match chr {
32 '\x20'..='\x7e' => Some(chr as u8 - BASE),
33 '°' => Some(0x7f - BASE),
34 _ => None,
35 }
36}