You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.7 KiB
96 lines
2.7 KiB
/**
|
|
* TODO file description
|
|
*/
|
|
|
|
#include "ufb/fb_text.h"
|
|
#include "ufb/framebuffer.h"
|
|
#include "ufb/utf8.h"
|
|
#include "ufb/font.h"
|
|
|
|
void fb_text_P_or_RAM(fbpos_t x, fbpos_t y, const char *text, uint8_t flags, fbcolor_t color, bool is_pgmem) {
|
|
struct Utf8Iterator iter;
|
|
Utf8Iterator_Init(&iter, text);
|
|
iter.is_progmem = is_pgmem;
|
|
|
|
struct Utf8Char uchar;
|
|
|
|
uint8_t symw;
|
|
uint8_t symh;
|
|
if (flags & FONT_4X5) {
|
|
symw = 4;
|
|
symh = 5;
|
|
} else if (flags & FONT_3X5) {
|
|
symw = 3;
|
|
symh = 5;
|
|
} else {
|
|
symw = 5;
|
|
symh = 7;
|
|
}
|
|
|
|
while ((uchar = Utf8Iterator_Next(&iter)).uint) {
|
|
const uint8_t *data;
|
|
if (flags & FONT_4X5) {
|
|
const font4x_bitmap_t *sym = font45_getsym(&uchar);
|
|
data = sym->data;
|
|
} else if (flags & FONT_3X5) {
|
|
const font3x_bitmap_t *sym = font35_getsym(&uchar);
|
|
data = sym->data;
|
|
} else{
|
|
const font5x_bitmap_t *sym = font57_getsym(&uchar);
|
|
data = sym->data;
|
|
}
|
|
|
|
if (0 == (flags & FONT_DOUBLE)) {
|
|
// no double, using normal format
|
|
|
|
#if IS_AVR
|
|
fb_bitmap_ex_P(x, y, symw, symh, data, color);
|
|
#else
|
|
fb_bitmap_ex(x, y, symw, symh, data, color);
|
|
#endif
|
|
|
|
if (flags & FONT_BOLD) {
|
|
x++;
|
|
|
|
#if IS_AVR
|
|
fb_bitmap_ex_P(x, y, symw, symh, data, color);
|
|
#else
|
|
fb_bitmap_ex(x, y, symw, symh, data, color);
|
|
#endif
|
|
|
|
x += symw+2;
|
|
} else {
|
|
x += symw+1;
|
|
}
|
|
} else {
|
|
// slow, pixel-by-pixel drawing
|
|
const uint8_t pxw = (flags & FONT_DOUBLEW) ? 2 : 1;
|
|
const uint8_t pxh = (flags & FONT_DOUBLEH) ? 2 : 1;
|
|
for(fbpos_t xx = 0; xx < symw; xx++) {
|
|
uint8_t column = pgm_read_byte(&data[xx]);
|
|
for(fbpos_t yy = 0; yy < symh; yy++) {
|
|
if (column & (1 << yy)) {
|
|
fb_rect(x + xx * pxw, y + yy * pxh, pxw, pxh, color);
|
|
if (flags & FONT_BOLD) {
|
|
fb_rect(x + (xx + 1) * pxw, y + yy * pxh, pxw, pxh, color);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (flags & FONT_BOLD) {
|
|
x += (symw+2) * pxw;
|
|
} else {
|
|
x += (symw+1) * pxw;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void fb_text_P(fbpos_t x, fbpos_t y, const char *text, uint8_t flags, fbcolor_t color)
|
|
{
|
|
fb_text_P_or_RAM(x, y, text, flags, color, true);
|
|
}
|
|
|
|
void fb_text(fbpos_t x, fbpos_t y, const char *text, uint8_t flags, fbcolor_t color) {
|
|
fb_text_P_or_RAM(x, y, text, flags, color, false);
|
|
}
|
|
|