forked from AbleOS/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")']
|
[target.'cfg(target_arch = "x86_64")']
|
||||||
<<<<<<< HEAD
|
|
||||||
# --quiet suppresses warning messages from the bootimage crate
|
|
||||||
=======
|
|
||||||
>>>>>>> 9bba5ae0fa0b592727d97ff033f639e3e07b2a74
|
|
||||||
runner = "bootimage runner"
|
runner = "bootimage runner"
|
||||||
|
|
||||||
[target.riscv64gc-unknown-none-elf]
|
[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);
|
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
|
/// Draw a glyph on the screen at the given position
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
@ -31,41 +33,40 @@ pub fn draw_char(x: u8, y: u8, character: char, color: Rgba64) {
|
||||||
// let mode = *VGAE.lock();
|
// let mode = *VGAE.lock();
|
||||||
let mut mode = SCREEN_BUFFER.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"
|
"../../ableos/assets/fonts/unifont-14.0.01.ttf"
|
||||||
))
|
))
|
||||||
.unwrap();
|
.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"
|
"../../ableos/assets/fonts/unifont_upper-14.0.01.ttf"
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut has_char = false;
|
// let mut has_char = false;
|
||||||
for x in font.codepoint_ids() {
|
// for x in font.codepoint_ids() {
|
||||||
if x.1 == character {
|
// if x.1 == character {
|
||||||
has_char = true;
|
// has_char = true;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
let used_font;
|
let is_in_basic_multilingual_plane = character as u32 <= 0xffff;
|
||||||
match has_char {
|
|
||||||
true => used_font = font,
|
|
||||||
false => used_font = font2,
|
|
||||||
}
|
|
||||||
|
|
||||||
let font_scale = 1.6;
|
let plane = match is_in_basic_multilingual_plane {
|
||||||
|
true => basic_multingual_plane,
|
||||||
|
false => supplementary_multilingual_plane,
|
||||||
|
};
|
||||||
|
|
||||||
match character {
|
match character {
|
||||||
'\n' => {}
|
'\n' => {}
|
||||||
_ => {
|
_ => {
|
||||||
let mut q_glyph: Glyph = used_font.glyph_id(character).with_scale_and_position(
|
let q_glyph: Glyph = plane.glyph_id(character).with_scale_and_position(
|
||||||
20.0 * font_scale,
|
20.0 * FONT_SCALE,
|
||||||
ab_glyph::point(10.0 * font_scale, 18.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| {
|
q.draw(|x, y, c| {
|
||||||
if c > 0.015 {
|
if c > 0.015 {
|
||||||
let corner = q.px_bounds().min;
|
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 💀
|
/// Converts a number to ... i forgor 💀
|
||||||
pub fn num_to_vga16(num: u8) -> Color16 {
|
pub fn num_to_vga16(num: u8) -> Color16 {
|
||||||
use Color16::*;
|
use Color16::*;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#![feature(exclusive_range_pattern)]
|
|
||||||
use vga::colors::Color16;
|
use vga::colors::Color16;
|
||||||
pub type Rgba64 = u64;
|
pub type Rgba64 = u64;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue