diff --git a/src/font.rs b/src/font.rs index db160fa..9ade7da 100644 --- a/src/font.rs +++ b/src/font.rs @@ -1,18 +1,20 @@ +use std::sync::Arc; + use font_kit::canvas::{Canvas, Format, RasterizationOptions}; +use font_kit::font::Font; use font_kit::hinting::HintingOptions; use pathfinder_geometry::transform2d::Transform2F; use pathfinder_geometry::vector::{vec2f, vec2i}; use servicepoint2::{PixelGrid, TILE_SIZE}; +const DEFAULT_FONT_FILE: &[u8] = include_bytes!("../Web437_IBM_BIOS.woff"); + pub struct BitmapFont { bitmaps: [PixelGrid; u8::MAX as usize], } impl BitmapFont { - pub fn load_file(file: &str) -> BitmapFont { - let font = font_kit::font::Font::from_path(file, 0) - .expect("could not load font"); - + pub fn load(font: Font) -> BitmapFont { let mut bitmaps = core::array::from_fn(|_| { PixelGrid::new(TILE_SIZE as usize, TILE_SIZE as usize) }); @@ -57,3 +59,11 @@ impl BitmapFont { &self.bitmaps[char_code as usize] } } + +impl Default for BitmapFont { + fn default() -> Self { + let font = Font::from_bytes(Arc::new(DEFAULT_FONT_FILE.to_vec()), 0) + .expect("could not load included font"); + Self::load(font) + } +} diff --git a/src/main.rs b/src/main.rs index e62ec47..751ebec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use std::sync::{mpsc, RwLock}; use std::time::Duration; use clap::Parser; -use log::{info, warn}; +use log::{info, LevelFilter, warn}; use servicepoint2::{ ByteGrid, Command, PIXEL_HEIGHT, PIXEL_WIDTH, PixelGrid, TILE_HEIGHT, TILE_WIDTH, @@ -36,7 +36,10 @@ struct Cli { } fn main() { - env_logger::init(); + env_logger::builder() + .filter_level(LevelFilter::Info) + .parse_default_env() + .init(); let mut cli = Cli::parse(); if !(cli.red || cli.blue || cli.green) { @@ -49,8 +52,6 @@ fn main() { .set_nonblocking(true) .expect("could not enter non blocking mode"); - let font = BitmapFont::load_file("Web437_IBM_BIOS.woff"); - let display = RwLock::new(PixelGrid::new( PIXEL_WIDTH as usize, PIXEL_HEIGHT as usize, @@ -60,7 +61,7 @@ fn main() { luma.fill(u8::MAX); let luma = RwLock::new(luma); - run(&display, &luma, socket, font, &cli); + run(&display, &luma, socket, BitmapFont::default(), &cli); } fn run(