Improve font rendering

This commit is contained in:
Sofia 2025-09-13 15:11:53 +03:00
parent 0806f9803e
commit 9bb7af612c
2 changed files with 25 additions and 26 deletions

View File

@ -41,8 +41,8 @@ fn letter(character: char) -> [u8; 8] {
0b10000001,
],
'i' => [
0b00111000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000,
0b00111000,
0b00111100, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000,
0b00111100,
],
'j' => [
0b00001110, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b10000010, 0b10000010,
@ -57,7 +57,7 @@ fn letter(character: char) -> [u8; 8] {
0b11111111,
],
'm' => [
0b01100110, 0b10011001, 0b10010001, 0b10010001, 0b10010001, 0b10000001, 0b10000001,
0b00100100, 0b11011011, 0b10011001, 0b10011001, 0b10011001, 0b10000001, 0b10000001,
0b10000001,
],
'n' => [
@ -105,7 +105,7 @@ fn letter(character: char) -> [u8; 8] {
0b10000001,
],
'y' => [
0b10000001, 0b10000001, 0b01000010, 0b00111100, 0b00011000, 0b00011000, 0b00011000,
0b10000001, 0b01000010, 0b00100100, 0b00011000, 0b00011000, 0b00011000, 0b00011000,
0b00011000,
],
'z' => [
@ -137,33 +137,32 @@ pub fn draw_text<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
let kerning = 9 * scale;
let original_x = position.x;
for word in text.split(' ') {
let word_length = word.len() as u16 * kerning;
if curr_pos.x + word_length > 240 {
curr_pos.x = original_x;
curr_pos.y += kerning;
}
for c in word.chars() {
if c == '\n' {
curr_pos.y += kerning;
continue;
}
if curr_pos.x + kerning > 240 {
for line in text.split('\n') {
for word in line.split(' ') {
let word_length = word.len() as u16 * kerning;
if curr_pos.x + word_length > 240 {
curr_pos.x = original_x;
curr_pos.y += kerning;
}
if curr_pos.y + kerning > 240 {
curr_pos.y = 0;
for c in word.chars() {
if curr_pos.x + kerning > 240 {
curr_pos.x = original_x;
curr_pos.y += kerning;
}
if curr_pos.y + kerning > 240 {
curr_pos.y = 0;
}
Letter::from(c, fg, bg)
.iter()
.draw(display, curr_pos, scale);
curr_pos.x += kerning;
}
Letter::from(c, fg, bg)
.iter()
.draw(display, curr_pos, scale);
curr_pos.x += kerning;
}
curr_pos.x += kerning;
curr_pos.y += kerning;
}
}

View File

@ -96,9 +96,9 @@ fn main() -> ! {
draw_text(
&mut display,
"hello there!",
"hi,my name is adafruit!nice to meet you!",
Rgb565::white(),
Rgb565::red(),
Rgb565::black(),
Vec2 { x: 10, y: 10 },
3,
);