Skip to content

Commit

Permalink
nicer font rendering into framebuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
phip1611 committed Jan 19, 2022
1 parent 6423165 commit 6ba97ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
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
24 changes: 11 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::{BitmapChar, BitmapHeight, FontWeight, get_bitmap, get_bitmap_width};
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,23 @@ 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

0 comments on commit 6ba97ed

Please sign in to comment.