32 lines
1.4 KiB
C
32 lines
1.4 KiB
C
#include <psf.h>
|
|
|
|
// c is a unicode character, cx and cy are cursor position in characters
|
|
void draw_psf_char(framebuffer_t *framebuffer, uint32_t c, uint16_t cx, uint16_t cy, uint32_t fg, uint32_t bg) {
|
|
PSF_font *font = (PSF_font*)&_binary_font_psfu_start;
|
|
// we need to know how many bytes encode one row
|
|
int bytesperline = (font->width + 7) / 8;
|
|
// get the glyph for the character. If there's no
|
|
// glyph for a given character, we'll display the first glyph.
|
|
uint8_t *glyph = (uint8_t*)&_binary_font_psfu_start + font->headersize +
|
|
(c > 0 && c < font->numglyph ? c : 0) * font->bytesperglyph;
|
|
// calculate the upper left corner on screen where we want to display.
|
|
// we only do this once, and adjust the whereet later. This is faster.
|
|
int where = (cy * font->height * framebuffer->pitch) + (cx * (font->width + 1) * 4);
|
|
// finally display pixels according to the bitmap
|
|
int x, y, line, mask;
|
|
for (y = 0; y < font->height; y++) {
|
|
// save the starting position of the line
|
|
line = where;
|
|
mask = 1 << (font->width - 1);
|
|
// display a row
|
|
for (x = 0; x < font->width; x++) {
|
|
*((uint32_t*)(framebuffer->address + line)) = *((uint32_t*)glyph) & mask ? fg : bg;
|
|
// adjust to the next pixel
|
|
mask >>= 1;
|
|
line += 4;
|
|
}
|
|
// adjust to the next line
|
|
glyph += bytesperline;
|
|
where += framebuffer->pitch;
|
|
}
|
|
} |