Add basic text rendering
This commit is contained in:
parent
064cdc5ba0
commit
22b6ee1136
16 changed files with 43620 additions and 6 deletions
39
src/print.c
Normal file
39
src/print.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "print.h"
|
||||
#include "ltp1245.h"
|
||||
|
||||
static uint8_t Print_Buffer[64 * LTP1245_LINE_BYTES];
|
||||
|
||||
void Print_Text(const char *text, const Font_t *font)
|
||||
{
|
||||
int height = font->height;
|
||||
memset(Print_Buffer, 0, LTP1245_LINE_BYTES * height);
|
||||
char c;
|
||||
int xpos = 0;
|
||||
while((c = *text++) != 0)
|
||||
{
|
||||
if(c > font->glyphcount + font->charoffset
|
||||
|| c < font->charoffset)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int width = font->glyphs[c - font->charoffset].width;
|
||||
const uint8_t *bitmap = font->glyphs[c - font->charoffset].bitmap;
|
||||
|
||||
for(int i = 0; i < width * height; i++)
|
||||
{
|
||||
int x = i / height + xpos;
|
||||
int y = i % height;
|
||||
if(bitmap[i / 8] & (0x80 >> (i % 8)))
|
||||
{
|
||||
// Pixel is black
|
||||
Print_Buffer[y * LTP1245_LINE_BYTES + x / 8] |=
|
||||
0x80 >> (x % 8);
|
||||
}
|
||||
}
|
||||
|
||||
xpos += width;
|
||||
}
|
||||
|
||||
LTP1245_Print(Print_Buffer, height);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue