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, u32 c, u16 cx, u16 cy, u32 fg, u32 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.
|
|
u8 *glyph = (u8*)&_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++) {
|
|
*((u32*)(framebuffer->address + line)) = *((u32*)glyph) & mask ? fg : bg;
|
|
// adjust to the next pixel
|
|
mask >>= 1;
|
|
line += framebuffer->pixelwidth;
|
|
}
|
|
// adjust to the next line
|
|
glyph += bytesperline;
|
|
where += framebuffer->pitch;
|
|
}
|
|
} |