os_terminal/font/
bitmap.rs

1use noto_sans_mono_bitmap::{get_raster, get_raster_width};
2use noto_sans_mono_bitmap::{FontWeight, RasterHeight};
3
4use super::{ContentInfo, FontManager, Rasterized};
5
6const FONT_WIDTH: usize = get_raster_width(FontWeight::Regular, FONT_HEIGHT);
7const FONT_HEIGHT: RasterHeight = RasterHeight::Size20;
8
9pub struct BitmapFont;
10
11impl FontManager for BitmapFont {
12    fn size(&self) -> (usize, usize) {
13        (FONT_WIDTH, FONT_HEIGHT as usize)
14    }
15
16    fn rasterize(&mut self, info: ContentInfo) -> Rasterized {
17        let font_weight = if info.bold {
18            FontWeight::Bold
19        } else {
20            FontWeight::Regular
21        };
22
23        let char_raster = get_raster(info.content, font_weight, FONT_HEIGHT)
24            .unwrap_or(get_raster('\u{fffd}', font_weight, FONT_HEIGHT).unwrap());
25
26        Rasterized::Slice(char_raster.raster())
27    }
28}