Tiny framebuffer for SSD1306 and similar displays.
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.
 
 
ufb/fb_text.c

78 lines
2.3 KiB

/**
* TODO file description
*/
#include "fb_text.h"
#include "framebuffer.h"
#include "utf8.h"
#include "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_TINY) {
symw = 4;
symh = 5;
} else {
symw = 5;
symh = 7;
}
while ((uchar = Utf8Iterator_Next(&iter)).uint) {
const uint8_t *data;
if (flags & FONT_TINY) {
const font4x_bitmap_t *sym = font45_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
fb_bitmap_P(x, y, symw, symh, data, color);
if (flags & FONT_BOLD) {
x++;
fb_bitmap_P(x, y, symw, symh, data, color);
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);
}