Improve font rendering
This commit is contained in:
parent
0806f9803e
commit
9bb7af612c
17
src/font.rs
17
src/font.rs
@ -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,7 +137,8 @@ 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') {
|
||||||
|
for word in line.split(' ') {
|
||||||
let word_length = word.len() as u16 * kerning;
|
let word_length = word.len() as u16 * kerning;
|
||||||
if curr_pos.x + word_length > 240 {
|
if curr_pos.x + word_length > 240 {
|
||||||
curr_pos.x = original_x;
|
curr_pos.x = original_x;
|
||||||
@ -145,10 +146,6 @@ pub fn draw_text<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for c in word.chars() {
|
for c in word.chars() {
|
||||||
if c == '\n' {
|
|
||||||
curr_pos.y += kerning;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if curr_pos.x + kerning > 240 {
|
if curr_pos.x + kerning > 240 {
|
||||||
curr_pos.x = original_x;
|
curr_pos.x = original_x;
|
||||||
curr_pos.y += kerning;
|
curr_pos.y += kerning;
|
||||||
@ -165,6 +162,8 @@ pub fn draw_text<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
|
|||||||
|
|
||||||
curr_pos.x += kerning;
|
curr_pos.x += kerning;
|
||||||
}
|
}
|
||||||
|
curr_pos.y += kerning;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Letter {
|
pub struct Letter {
|
||||||
|
@ -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,
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user