forked from koniifer/ableos
Simplify range check for font
This commit is contained in:
parent
fd9c18c744
commit
3206cfd2bc
|
@ -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]
|
||||
|
|
|
@ -20,6 +20,8 @@ lazy_static::lazy_static! {
|
|||
pub static ref VGAE_BUFF_OFFSET_Y: spin::Mutex<u8> = 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::*;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(exclusive_range_pattern)]
|
||||
use vga::colors::Color16;
|
||||
pub type Rgba64 = u64;
|
||||
|
||||
|
|
Loading…
Reference in a new issue