Files
Sylva/fonts/pixel_font.cpp
T
2026-05-31 20:03:46 +08:00

30 lines
1.1 KiB
C++

#include <fonts/hankaku.h>
#include <fonts/pixel_font.h>
#include <graphics/draw.h>
#include <common.h>
void pf_print_char(char c, uint16_t basex, uint16_t basey, COLOR_RGB color) {
for (unsigned int y = 0; y < 16; y++) {
unsigned char data = hankaku_pixels[c][y];
for (int x = 7; x >= 0; x--) {
// 解码Hankaku字体
/*
既然都在这了,就讲一下Hankaku字体是如何解码的
比如一个
{0x00, 0x82, 0x82, 0x44, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00}
每一个Hex代表一行,比如0x82就是一行,转换成Bin得到10000010,1代表有像素,0代表没像素
*/
unsigned int current = data & 1;
data >>= 1;
if (current)
draw_pixel(basex + x, basey + y, color);
}
}
}
void pf_print(const char* text, uint16_t basex, uint16_t basey, COLOR_RGB color) {
for (unsigned int i = 0; i < strlen(text); i++) {
char c = text[i];
pf_print_char(c, basex + i * 8, basey, color);
}
}