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

View File

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