From 3206cfd2bc7408db24eacca14c16c3a6e0dd7222 Mon Sep 17 00:00:00 2001 From: Elfein Landers Date: Wed, 26 Jan 2022 23:00:25 -0800 Subject: [PATCH] Simplify range check for font --- ableos/.cargo/config.toml | 4 ---- ableos/src/vga_e.rs | 40 ++++++++++++++++++----------------- shadeable/src/pixel_format.rs | 1 - 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/ableos/.cargo/config.toml b/ableos/.cargo/config.toml index f450ff4..06f0486 100644 --- a/ableos/.cargo/config.toml +++ b/ableos/.cargo/config.toml @@ -7,10 +7,6 @@ build-std-features = ["compiler-builtins-mem"] [target.'cfg(target_arch = "x86_64")'] -<<<<<<< HEAD -# --quiet suppresses warning messages from the bootimage crate -======= ->>>>>>> 9bba5ae0fa0b592727d97ff033f639e3e07b2a74 runner = "bootimage runner" [target.riscv64gc-unknown-none-elf] diff --git a/ableos/src/vga_e.rs b/ableos/src/vga_e.rs index 02ed149..8b39667 100644 --- a/ableos/src/vga_e.rs +++ b/ableos/src/vga_e.rs @@ -20,6 +20,8 @@ lazy_static::lazy_static! { pub static ref VGAE_BUFF_OFFSET_Y: spin::Mutex = spin::Mutex::new(0); } +const FONT_SCALE: f32 = 1.6; + /// Draw a glyph on the screen at the given position /// /// # Arguments @@ -31,41 +33,40 @@ pub fn draw_char(x: u8, y: u8, character: char, color: Rgba64) { // let mode = *VGAE.lock(); let mut mode = SCREEN_BUFFER.lock(); - let font = FontRef::try_from_slice(include_bytes!( + let basic_multingual_plane = FontRef::try_from_slice(include_bytes!( "../../ableos/assets/fonts/unifont-14.0.01.ttf" )) .unwrap(); - let font2 = FontRef::try_from_slice(include_bytes!( + let supplementary_multilingual_plane = FontRef::try_from_slice(include_bytes!( "../../ableos/assets/fonts/unifont_upper-14.0.01.ttf" )) .unwrap(); - let mut has_char = false; - for x in font.codepoint_ids() { - if x.1 == character { - has_char = true; - break; - } - } + // let mut has_char = false; + // for x in font.codepoint_ids() { + // if x.1 == character { + // has_char = true; + // break; + // } + // } - let used_font; - match has_char { - true => used_font = font, - false => used_font = font2, - } + let is_in_basic_multilingual_plane = character as u32 <= 0xffff; - let font_scale = 1.6; + let plane = match is_in_basic_multilingual_plane { + true => basic_multingual_plane, + false => supplementary_multilingual_plane, + }; match character { '\n' => {} _ => { - let mut q_glyph: Glyph = used_font.glyph_id(character).with_scale_and_position( - 20.0 * font_scale, - ab_glyph::point(10.0 * font_scale, 18.0 * font_scale), + let q_glyph: Glyph = plane.glyph_id(character).with_scale_and_position( + 20.0 * FONT_SCALE, + ab_glyph::point(10.0 * FONT_SCALE, 18.0 * FONT_SCALE), ); - if let Some(q) = used_font.outline_glyph(q_glyph) { + if let Some(q) = plane.outline_glyph(q_glyph) { q.draw(|x, y, c| { if c > 0.015 { let corner = q.px_bounds().min; @@ -80,6 +81,7 @@ pub fn draw_char(x: u8, y: u8, character: char, color: Rgba64) { } } } + /// Converts a number to ... i forgor 💀 pub fn num_to_vga16(num: u8) -> Color16 { use Color16::*; diff --git a/shadeable/src/pixel_format.rs b/shadeable/src/pixel_format.rs index bd9fad2..b14c051 100644 --- a/shadeable/src/pixel_format.rs +++ b/shadeable/src/pixel_format.rs @@ -1,4 +1,3 @@ -#![feature(exclusive_range_pattern)] use vga::colors::Color16; pub type Rgba64 = u64;