forked from AbleOS/ableos
Font rendering semi-done
This commit is contained in:
parent
f884200eb2
commit
7d66a64b33
|
@ -34,8 +34,6 @@ vga = "*"
|
||||||
pretty-hex = "0.2.1"
|
pretty-hex = "0.2.1"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies.ab_glyph]
|
[dependencies.ab_glyph]
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["libm"]
|
features = ["libm"]
|
||||||
|
|
BIN
ableos/assets/fonts/MesloLGS NF Regular.ttf
Normal file
BIN
ableos/assets/fonts/MesloLGS NF Regular.ttf
Normal file
Binary file not shown.
BIN
ableos/assets/fonts/Untitled1.ttf
Normal file
BIN
ableos/assets/fonts/Untitled1.ttf
Normal file
Binary file not shown.
|
@ -1,8 +1,11 @@
|
||||||
#![allow(clippy::empty_loop)]
|
#![allow(clippy::empty_loop)]
|
||||||
|
|
||||||
use alloc::format;
|
use vga::{colors::Color16, writers::GraphicsWriter};
|
||||||
|
|
||||||
use crate::relib::network::socket::Socket;
|
use crate::{
|
||||||
|
relib::network::socket::SocketReturns,
|
||||||
|
vga_e::{self, VGAE},
|
||||||
|
};
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
|
@ -12,10 +15,10 @@ use {
|
||||||
info::master,
|
info::master,
|
||||||
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
||||||
},
|
},
|
||||||
log::LOG_STATE,
|
// log::LOG_STATE,
|
||||||
relib::math::rand::RAND_HANDLE,
|
relib::math::rand::RAND_HANDLE,
|
||||||
|
relib::network::socket::{Socket, SOCKETS},
|
||||||
scheduler::{test_fn, Thread, ThreadList},
|
scheduler::{test_fn, Thread, ThreadList},
|
||||||
vga_e,
|
|
||||||
},
|
},
|
||||||
alloc::{
|
alloc::{
|
||||||
string::{String, ToString},
|
string::{String, ToString},
|
||||||
|
@ -40,12 +43,6 @@ lazy_static! {
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn kernel_main() -> ! {
|
pub fn kernel_main() -> ! {
|
||||||
if false {
|
|
||||||
LOG_STATE.lock().info = false;
|
|
||||||
LOG_STATE.lock().trace = false;
|
|
||||||
LOG_STATE.lock().debug = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
init::init();
|
init::init();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -59,7 +56,6 @@ pub fn kernel_main() -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::wasm::evaluate();
|
crate::wasm::evaluate();
|
||||||
|
|
||||||
{
|
{
|
||||||
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
|
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
|
||||||
info!(
|
info!(
|
||||||
|
@ -71,35 +67,42 @@ pub fn kernel_main() -> ! {
|
||||||
println!("$RED$hi$RESET$");
|
println!("$RED$hi$RESET$");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
use crate::relib::network::socket::SimpleSock;
|
use crate::relib::network::socket::SimpleSock;
|
||||||
use crate::utils::type_of;
|
|
||||||
let mut xyz = SimpleSock::new();
|
let mut xyz = SimpleSock::new();
|
||||||
xyz.write(vec![0, 0, 1, 0]);
|
|
||||||
xyz.close();
|
|
||||||
|
|
||||||
println!("type of socket: {:?}", type_of(&xyz));
|
xyz.peek();
|
||||||
println!("contents: {:?}", &xyz.read());
|
|
||||||
|
|
||||||
println!("length: {:?}", xyz.read().len());
|
xyz.write(vec![0, 1, 2, 3]);
|
||||||
drop(xyz);
|
|
||||||
|
let x = "simple 🧦".to_string().into_bytes();
|
||||||
|
xyz.write(x);
|
||||||
|
|
||||||
|
info!("{:?}", &xyz.read(4).unwrap());
|
||||||
|
|
||||||
|
println!("{:?}", &xyz.peek().unwrap());
|
||||||
|
|
||||||
|
match &xyz.peek() {
|
||||||
|
SocketReturns::ReadOk(strr) => {
|
||||||
|
let out = String::from_utf8_lossy(strr);
|
||||||
|
|
||||||
|
info!("{}", out);
|
||||||
|
}
|
||||||
|
SocketReturns::ReadIndexOutOfBounds => todo!(),
|
||||||
|
SocketReturns::WriteOk => todo!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
println!("$GREEN$able$RESET$@$LIGHTBLUE$stAble$ $RED$->$RESET$");
|
||||||
use pretty_hex::*;
|
|
||||||
|
|
||||||
let v = vec![222, 173, 190, 239, 202, 254, 32, 24];
|
VGAE.lock().clear_screen(Color16::Black);
|
||||||
assert_eq!(simple_hex(&v), format!("{}", v.hex_dump()));
|
|
||||||
|
|
||||||
println!("{}", v.hex_dump());
|
for x in "μkernel".chars().enumerate() {
|
||||||
|
vga_e::draw_char(x.1, x.0);
|
||||||
}
|
}
|
||||||
|
// vga_e::test_it_fucko();
|
||||||
//
|
|
||||||
|
|
||||||
info!("新着情報");
|
|
||||||
|
|
||||||
print!("$GREEN$able$RESET$@$LIGHTBLUE$stAble$ $RED$->$RESET$");
|
|
||||||
vga_e::draw_q();
|
|
||||||
// stack_overflow();
|
// stack_overflow();
|
||||||
|
|
||||||
sloop()
|
sloop()
|
||||||
|
|
|
@ -27,6 +27,7 @@ pub mod arch;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod print;
|
pub mod print;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod log;
|
pub mod log;
|
||||||
|
|
||||||
|
|
|
@ -3,36 +3,97 @@ use alloc::vec::Vec;
|
||||||
|
|
||||||
pub type Stream = Vec<u8>;
|
pub type Stream = Vec<u8>;
|
||||||
|
|
||||||
|
pub struct SocketID {
|
||||||
|
pub id: usize,
|
||||||
|
}
|
||||||
|
impl Socket for SocketID {
|
||||||
|
fn peek(&mut self) -> SocketReturns {
|
||||||
|
SOCKETS.lock()[self.id].peek()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read(&mut self, length: usize) -> SocketReturns {
|
||||||
|
SOCKETS.lock()[self.id].read(length)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write(&mut self, stream: Stream) -> SocketReturns {
|
||||||
|
SOCKETS.lock()[self.id].write(stream)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type SocketState = Vec<SimpleSock>;
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
pub static ref SOCKETS: spin::Mutex<SocketState> = spin::Mutex::new(vec![]);
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Socket {
|
pub trait Socket {
|
||||||
fn new() {}
|
fn peek(&mut self) -> SocketReturns;
|
||||||
fn read(&mut self) -> Vec<u8>;
|
|
||||||
fn write(&mut self, stream: Stream);
|
/// Reads from the socket and removes read bytes from the socket
|
||||||
|
fn read(&mut self, length: usize) -> SocketReturns;
|
||||||
|
|
||||||
|
fn write(&mut self, stream: Stream) -> SocketReturns;
|
||||||
fn close(&mut self) {}
|
fn close(&mut self) {}
|
||||||
}
|
}
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum SocketReturns {
|
||||||
|
ReadOk(Stream),
|
||||||
|
ReadIndexOutOfBounds,
|
||||||
|
WriteOk,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SocketReturns {
|
||||||
|
pub fn unwrap(self) -> Stream {
|
||||||
|
match self {
|
||||||
|
SocketReturns::ReadOk(stream) => stream,
|
||||||
|
SocketReturns::ReadIndexOutOfBounds => panic!("Read Index Out Of Bounds"),
|
||||||
|
SocketReturns::WriteOk => vec![1],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct SimpleSock {
|
pub struct SimpleSock {
|
||||||
stream: Vec<u8>,
|
stream: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SimpleSock {
|
impl SimpleSock {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> SocketID {
|
||||||
Self { stream: vec![] }
|
let sock = SimpleSock { stream: vec![] };
|
||||||
|
let mut sock_lock = SOCKETS.lock();
|
||||||
|
sock_lock.push(sock);
|
||||||
|
|
||||||
|
SocketID {
|
||||||
|
id: sock_lock.len() - 1,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Socket for SimpleSock {
|
impl Socket for SimpleSock {
|
||||||
fn new() {}
|
fn peek(&mut self) -> SocketReturns {
|
||||||
fn read(&mut self) -> Vec<u8> {
|
|
||||||
let mut return_vec = vec![];
|
let mut return_vec = vec![];
|
||||||
|
|
||||||
for x in &self.stream {
|
for x in &self.stream {
|
||||||
return_vec.push(x.clone());
|
return_vec.push(x.clone());
|
||||||
}
|
}
|
||||||
return_vec
|
SocketReturns::ReadOk(return_vec)
|
||||||
}
|
}
|
||||||
fn write(&mut self, stream: Stream) {
|
fn read(&mut self, length: usize) -> SocketReturns {
|
||||||
|
let mut return_vec = vec![];
|
||||||
|
if length > self.stream.len() {
|
||||||
|
SocketReturns::ReadIndexOutOfBounds
|
||||||
|
} else {
|
||||||
|
for _ in 0..length {
|
||||||
|
return_vec.push(self.stream[0]);
|
||||||
|
self.stream.remove(0);
|
||||||
|
}
|
||||||
|
SocketReturns::ReadOk(return_vec)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn write(&mut self, stream: Stream) -> SocketReturns {
|
||||||
for byte in stream {
|
for byte in stream {
|
||||||
self.stream.push(byte);
|
self.stream.push(byte);
|
||||||
}
|
}
|
||||||
|
SocketReturns::WriteOk
|
||||||
}
|
}
|
||||||
fn close(&mut self) {}
|
fn close(&mut self) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use ab_glyph::{Font, FontRef, Glyph};
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
|
|
||||||
use vga::{
|
use vga::{
|
||||||
|
@ -5,6 +6,18 @@ use vga::{
|
||||||
writers::{Graphics640x480x16, GraphicsWriter},
|
writers::{Graphics640x480x16, GraphicsWriter},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
|
||||||
|
pub static ref VGAE: spin::Mutex<Graphics640x480x16> = {
|
||||||
|
let xyz = Graphics640x480x16::new();
|
||||||
|
xyz.set_mode();
|
||||||
|
spin::Mutex::new(xyz)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const FONT: &[u8; 1279380] =
|
||||||
|
include_bytes!("../../ableos/assets/fonts/MesloLGS NF Regular.ttf");
|
||||||
|
|
||||||
pub fn test_it_fucko() {
|
pub fn test_it_fucko() {
|
||||||
let mode = Graphics640x480x16::new();
|
let mode = Graphics640x480x16::new();
|
||||||
mode.set_mode();
|
mode.set_mode();
|
||||||
|
@ -31,10 +44,6 @@ pub fn test_it_fucko() {
|
||||||
for (offset, character) in "ableOS".chars().enumerate() {
|
for (offset, character) in "ableOS".chars().enumerate() {
|
||||||
mode.draw_character(270 + offset * 8, 72, character, Color16::White)
|
mode.draw_character(270 + offset * 8, 72, character, Color16::White)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (offset, character) in "S".chars().enumerate() {
|
|
||||||
mode.draw_character(270 + offset * 8, 50, character, Color16::White)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait GraphicsAPI {
|
pub trait GraphicsAPI {
|
||||||
|
@ -44,29 +53,31 @@ pub trait GraphicsAPI {
|
||||||
pub struct Buffer {
|
pub struct Buffer {
|
||||||
label: String,
|
label: String,
|
||||||
resolution: (u64, u64),
|
resolution: (u64, u64),
|
||||||
// pointer
|
|
||||||
}
|
}
|
||||||
pub fn draw_q() {
|
|
||||||
let mode = Graphics640x480x16::new();
|
|
||||||
mode.set_mode();
|
|
||||||
mode.clear_screen(Color16::Black);
|
|
||||||
|
|
||||||
use ab_glyph::{point, Font, FontRef, Glyph};
|
// #[deprecated(note = "Deprecated because you should use the damn graphics api")]
|
||||||
|
pub fn draw_char(character: char, offset: usize) {
|
||||||
|
let mode = *VGAE.lock();
|
||||||
|
|
||||||
let font =
|
let font = FontRef::try_from_slice(FONT).unwrap();
|
||||||
FontRef::try_from_slice(include_bytes!("../../ableos/assets/fonts/Roboto-Black.ttf"))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Get a glyph for 'q' with a scale & position.
|
// Get a glyph for 'q' with a scale & position.
|
||||||
let q_glyph: Glyph = font
|
let q_glyph: Glyph = font.glyph_id(character).with_scale(100.0);
|
||||||
.glyph_id('q')
|
|
||||||
.with_scale_and_position(24.0, point(100.0, 0.0));
|
|
||||||
|
|
||||||
// Draw it.
|
// Draw it.
|
||||||
|
|
||||||
if let Some(q) = font.outline_glyph(q_glyph) {
|
if let Some(q) = font.outline_glyph(q_glyph) {
|
||||||
q.draw(|x, y, _c| {
|
q.draw(|x, y, c| {
|
||||||
mode.set_pixel(x as usize, y as usize, Color16::LightBlue);
|
// info!("{}", c);
|
||||||
|
|
||||||
|
if c > 0.2 {
|
||||||
|
mode.set_pixel(
|
||||||
|
x as usize + (offset * 50),
|
||||||
|
//
|
||||||
|
y as usize,
|
||||||
|
Color16::LightBlue,
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue