Skip to content

Logger: nicer font rendering into framebuffer #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ rsdp = { version = "1.0.0", optional = true }
fatfs = { version = "0.3.4", optional = true }
gpt = { version = "2.0.0", optional = true }

[dependencies.font8x8]
version = "0.2.5"
[dependencies.noto-sans-mono-bitmap]
version = "0.1.2"
default-features = false
features = ["unicode"]
features = ["regular", "size_14"]
optional = true

[build-dependencies]
Expand All @@ -72,7 +72,7 @@ bios_bin = ["binary", "rsdp"]
uefi_bin = ["binary", "uefi"]
binary = [
"llvm-tools-build", "x86_64", "toml", "xmas-elf", "usize_conversions", "log", "conquer-once",
"spinning_top", "serde", "font8x8", "quote", "proc-macro2",
"spinning_top", "serde", "noto-sans-mono-bitmap", "quote", "proc-macro2",
]

[profile.dev]
Expand Down
25 changes: 12 additions & 13 deletions src/binary/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::{
fmt::{self, Write},
ptr,
};
use font8x8::UnicodeFonts;
use noto_sans_mono_bitmap::{get_bitmap, get_bitmap_width, BitmapChar, BitmapHeight, FontWeight};
use spinning_top::Spinlock;

/// The global logger instance used for the `log` crate.
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Logger {
}

fn newline(&mut self) {
self.y_pos += 8 + LINE_SPACING;
self.y_pos += 14 + LINE_SPACING;
self.carriage_return()
}

Expand Down Expand Up @@ -103,25 +103,24 @@ impl Logger {
if self.x_pos >= self.width() {
self.newline();
}
if self.y_pos >= (self.height() - 8) {
const BITMAP_LETTER_WIDTH: usize =
get_bitmap_width(FontWeight::Regular, BitmapHeight::Size14);
if self.y_pos >= (self.height() - BITMAP_LETTER_WIDTH) {
self.clear();
}
let rendered = font8x8::BASIC_FONTS
.get(c)
.expect("character not found in basic font");
self.write_rendered_char(rendered);
let bitmap_char = get_bitmap(c, FontWeight::Regular, BitmapHeight::Size14).unwrap();
self.write_rendered_char(bitmap_char);
}
}
}

fn write_rendered_char(&mut self, rendered_char: [u8; 8]) {
for (y, byte) in rendered_char.iter().enumerate() {
for (x, bit) in (0..8).enumerate() {
let alpha = if *byte & (1 << bit) == 0 { 0 } else { 255 };
self.write_pixel(self.x_pos + x, self.y_pos + y, alpha);
fn write_rendered_char(&mut self, rendered_char: BitmapChar) {
for (y, row) in rendered_char.bitmap().iter().enumerate() {
for (x, byte) in row.iter().enumerate() {
self.write_pixel(self.x_pos + x, self.y_pos + y, *byte);
}
}
self.x_pos += 8;
self.x_pos += rendered_char.width();
}

fn write_pixel(&mut self, x: usize, y: usize, intensity: u8) {
Expand Down