Skip to content

Instantly share code, notes, and snippets.

@lion328
Last active February 9, 2016 12:35
Show Gist options
  • Save lion328/29b4578b0c5e14d2e123 to your computer and use it in GitHub Desktop.
Save lion328/29b4578b0c5e14d2e123 to your computer and use it in GitHub Desktop.
Thai character render on IPST Microbox SE
//#include <ipst.h>
#define IPST_SCREEN_WIDTH 128
#define IPST_SCREEN_HEIGHT 160
const int GLCD_BLACK = 0;
const int GLCD_WHITE = 1;
const int GLCD_YELLOW = 2;
const int GLCD_RED = 3;
unsigned char screen[IPST_SCREEN_WIDTH][IPST_SCREEN_HEIGHT];
void glcdPixel(unsigned int x, unsigned int y, unsigned int color) {
screen[x][y] = color;
}
void glcdFillRect(unsigned int x, unsigned int y, unsigned width, unsigned int height, unsigned int color) {
for(int i = 0; i < width; i++) {
for(int j = 0; j < height; j++) {
glcdPixel(x + i, y + j, color);
}
}
}
void glcdFillScreen(unsigned int color) {
glcdFillRect(0, 0, IPST_SCREEN_WIDTH, IPST_SCREEN_HEIGHT, color);
}
static unsigned char thai_chars_pixels[];
unsigned char thaitext_get_raw_width(const unsigned char *raw);
void setup();
void loop();
#include <stdio.h>
#include <string.h>
int main() {
memset(screen, 0, sizeof(screen));
setup();
for(int i = 0; i < IPST_SCREEN_HEIGHT; i++) {
for(int j = 0; j < IPST_SCREEN_WIDTH; j++) {
putchar(screen[j][i] ? screen[j][i] + '0' : ' ');
}
putchar('\n');
}
return 0;
}
#define THAITEXT_CHAR unsigned char
#define THAITEXT_CHAR_NEWLINE 0xFF
#define THAITEXT_CHAR_WHITESPACE 0xFE
#define THAITEXT_CHAR_COLOR 0xFD
#define THAITEXT_CHAR_RAW_PIXEL 0xFC
#define THAITEXT_CHAR_ENDLINE THAITEXT_CHAR_NEWLINE
#define THAITEXT_CHAR_CTRL_RANGE_MIN THAITEXT_CHAR_RAW_PIXEL
#define THAITEXT_CHAR_CTRL_RANGE_MAX THAITEXT_CHAR_NEWLINE
#define THAITEXT_CHAR_LINE_HEIGHT 12
static unsigned char thai_chars_pixels[2048] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x09, 0x0A, 0x09, 0x09, 0x00,
0x00, 0x00, 0x0B, 0x0A, 0x09, 0x09, 0x06, 0x00,
0x00, 0x00, 0x12, 0x15, 0x14, 0x12, 0x0C, 0x00,
0x00, 0x00, 0x0E, 0x11, 0x1D, 0x15, 0x13, 0x00,
0x00, 0x00, 0x0A, 0x15, 0x13, 0x15, 0x11, 0x00,
0x00, 0x00, 0x12, 0x15, 0x14, 0x1E, 0x11, 0x00,
0x00, 0x00, 0x0C, 0x08, 0x09, 0x0A, 0x0C, 0x00,
0x00, 0x00, 0x07, 0x08, 0x0E, 0x08, 0x08, 0x00,
0x00, 0x00, 0x07, 0x08, 0x0B, 0x06, 0x0A, 0x00,
0x00, 0x00, 0x13, 0x0A, 0x12, 0x12, 0x0C, 0x00,
0x00, 0x00, 0x25, 0x16, 0x24, 0x24, 0x18, 0x00,
0x00, 0x00, 0x4E, 0x51, 0x52, 0x71, 0x4B, 0x00,
0x00, 0x00, 0x2E, 0x29, 0x3A, 0x21, 0x1B, 0x00,
0x00, 0x00, 0x0E, 0x11, 0x12, 0x12, 0x13, 0x1C,
0x00, 0x00, 0x0E, 0x11, 0x12, 0x12, 0x1B, 0x14,
0x00, 0x00, 0x0E, 0x07, 0x08, 0x0A, 0x0C, 0x03,
0x00, 0x00, 0x1A, 0x15, 0x14, 0x12, 0x12, 0x00,
0x00, 0x00, 0x4A, 0x55, 0x59, 0x75, 0x59, 0x00,
0x00, 0x00, 0x46, 0x49, 0x4A, 0x39, 0x4B, 0x00,
0x00, 0x00, 0x0E, 0x11, 0x17, 0x15, 0x13, 0x00,
0x00, 0x00, 0x0A, 0x15, 0x13, 0x15, 0x13, 0x00,
0x00, 0x00, 0x0E, 0x11, 0x12, 0x11, 0x13, 0x00,
0x00, 0x00, 0x1B, 0x16, 0x12, 0x12, 0x12, 0x00,
0x00, 0x00, 0x0F, 0x01, 0x0E, 0x09, 0x07, 0x00,
0x00, 0x00, 0x13, 0x12, 0x12, 0x0E, 0x12, 0x00,
0x00, 0x00, 0x13, 0x12, 0x12, 0x12, 0x0E, 0x00,
0x00, 0x10, 0x13, 0x12, 0x12, 0x12, 0x0E, 0x00,
0x00, 0x00, 0x13, 0x11, 0x15, 0x15, 0x0A, 0x00,
0x00, 0x10, 0x13, 0x11, 0x15, 0x15, 0x0A, 0x00,
0x00, 0x00, 0x13, 0x12, 0x11, 0x15, 0x0A, 0x00,
0x00, 0x10, 0x13, 0x12, 0x11, 0x15, 0x0A, 0x00,
0x00, 0x00, 0x0C, 0x12, 0x12, 0x12, 0x13, 0x00,
0x00, 0x00, 0x13, 0x12, 0x12, 0x1D, 0x13, 0x00,
0x00, 0x00, 0x0B, 0x09, 0x0A, 0x09, 0x06, 0x00,
0x00, 0x00, 0x0E, 0x01, 0x07, 0x08, 0x06, 0x00,
0x00, 0x00, 0x06, 0x09, 0x09, 0x09, 0x0A, 0x08,
0x00, 0x00, 0x07, 0x08, 0x0E, 0x09, 0x0B, 0x00,
0x00, 0x00, 0x0C, 0x12, 0x12, 0x12, 0x13, 0x10,
0x00, 0x00, 0x07, 0x08, 0x08, 0x08, 0x06, 0x00,
0x00, 0x10, 0x0E, 0x09, 0x0B, 0x09, 0x09, 0x00,
0x00, 0x00, 0x13, 0x16, 0x3A, 0x12, 0x0C, 0x00,
0x00, 0x10, 0x0F, 0x08, 0x0E, 0x09, 0x0B, 0x00,
0x00, 0x00, 0x1B, 0x1A, 0x0E, 0x12, 0x12, 0x00,
0x20, 0x58, 0x2B, 0x22, 0x2A, 0x2A, 0x14, 0x00,
0x00, 0x00, 0x07, 0x08, 0x0B, 0x09, 0x06, 0x00,
0x00, 0x08, 0x0F, 0x08, 0x0B, 0x09, 0x0E, 0x00,
0x00, 0x00, 0x0D, 0x0A, 0x08, 0x08, 0x08, 0x00,
0x00, 0x00, 0x01, 0x07, 0x00, 0x01, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0E,
0x00, 0x00, 0x06, 0x09, 0x08, 0x08, 0x08, 0x00,
0x03, 0x03, 0x18, 0x24, 0x20, 0x20, 0x20, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
0x00, 0x17, 0x32, 0x52, 0x52, 0x00, 0xD6, 0x00,
0x00, 0x80, 0xA2, 0xA5, 0xAB, 0x00, 0x2B, 0x00,
0x00, 0x01, 0x54, 0x25, 0x54, 0x00, 0x01, 0x00,
0x00, 0x03, 0x33, 0x09, 0x32, 0x20, 0x18, 0x00,
0x00, 0x04, 0x0F, 0x15, 0x1F, 0x15, 0x0F, 0x04,
0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00,
0x00, 0x00, 0x05, 0x05, 0x05, 0x05, 0x0A, 0x00,
0x06, 0x01, 0x02, 0x02, 0x02, 0x02, 0x04, 0x00,
0x02, 0x05, 0x06, 0x04, 0x04, 0x04, 0x08, 0x00,
0x05, 0x0A, 0x08, 0x08, 0x08, 0x08, 0x10, 0x00,
0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x04, 0x04,
0x00, 0x00, 0x0B, 0x0D, 0x08, 0x08, 0x08, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x06, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x06, 0x05,
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0E, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x06, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x06, 0x0C,
0x00, 0x00, 0x0E, 0x11, 0x15, 0x11, 0x0E, 0x00,
0x00, 0x00, 0x1E, 0x21, 0x21, 0x21, 0x1E, 0x00,
0x00, 0x00, 0x0E, 0x11, 0x16, 0x10, 0x0E, 0x00,
0x02, 0x05, 0xF5, 0xAC, 0xAC, 0x84, 0x78, 0x00,
0x00, 0x00, 0x0A, 0x15, 0x11, 0x11, 0x13, 0x00,
0x00, 0x10, 0x0E, 0x01, 0x0D, 0x05, 0x1A, 0x00,
0x00, 0x14, 0x0E, 0x01, 0x0D, 0x05, 0x1A, 0x00,
0x00, 0x01, 0x1E, 0x10, 0x14, 0x12, 0x0E, 0x00,
0x00, 0x00, 0x4A, 0x55, 0x51, 0x51, 0x33, 0x00,
0x00, 0x20, 0x1E, 0x01, 0x01, 0x2D, 0x3A, 0x00,
0x00, 0x20, 0x1E, 0x0D, 0x09, 0x11, 0x26, 0x00,
0x00, 0x00, 0x15, 0x16, 0x14, 0x14, 0x14, 0x00,
0x00, 0x00, 0x00, 0x06, 0x51, 0xA9, 0x06, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x3E, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
0x00, 0x00, 0x78, 0x0C, 0x04, 0x3C, 0x84, 0x04,
0x00, 0x00, 0x00, 0x00, 0xF9, 0x40, 0xA0, 0xB1,
0x00, 0x00, 0xF0, 0x90, 0x70, 0x30, 0xE0, 0x01,
0x00, 0xE0, 0xA0, 0x60, 0xC8, 0x88, 0xFB, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
0x06, 0x06, 0x05, 0x0D, 0x09, 0x08, 0x08, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x08, 0x08, 0x08, 0x00, 0x00, 0x1C, 0x33,
0x1E, 0x16, 0x12, 0x32, 0x02, 0x00, 0x00, 0x00,
0x67, 0x4D, 0x4B, 0x53, 0x00, 0x00, 0x00, 0x00,
0x04, 0x04, 0x06, 0x02, 0x00, 0x08, 0x08, 0x08,
0x19, 0x01, 0x11, 0x10, 0x18, 0x18, 0x1C, 0x14,
0x00, 0x00, 0x3C, 0x42, 0xC3, 0x81, 0x83, 0x86,
0x00, 0x0C, 0x08, 0x0C, 0x04, 0x04, 0x84, 0x4C,
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x40, 0xC0, 0x40, 0x60, 0x20, 0x20, 0x20,
0x10, 0x10, 0x13, 0x3E, 0x38, 0x60, 0x60, 0x60,
0xFE, 0x60, 0x60, 0xB0, 0x90, 0x88, 0x88, 0x88,
0x8F, 0x80, 0xC0, 0x40, 0x40, 0xE0, 0x40, 0x80,
0x21, 0x30, 0x18, 0x0C, 0x07, 0x00, 0x00, 0x81,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x80, 0x80,
0x14, 0x12, 0x7D, 0x12, 0x11, 0x11, 0x10, 0x08,
0x88, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x10, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
0x88, 0x88, 0x70, 0x00, 0x00, 0x60, 0x40, 0x60,
0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0xBC, 0x88,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8C, 0x8C,
0x00, 0x00, 0x00, 0x00, 0xC0, 0x63, 0xE3, 0x8B,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01,
0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x30, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x38, 0x38, 0x00, 0x00, 0x04, 0x0C, 0x1A, 0x13,
0x9B, 0x93, 0x00, 0xC0, 0x7F, 0x08, 0x08, 0x08,
0x24, 0x3C, 0x00, 0x00, 0x8C, 0xC4, 0x44, 0x44,
0xEE, 0x03, 0x00, 0x00, 0x03, 0x06, 0x04, 0x04,
0x00, 0xC0, 0x38, 0x0C, 0x06, 0x02, 0xFE, 0x12,
0x00, 0x01, 0x18, 0x08, 0x08, 0x89, 0x84, 0x84,
0x00, 0x00, 0x3C, 0x07, 0x01, 0x00, 0x00, 0x00,
0x00, 0x3C, 0x64, 0x84, 0x04, 0x04, 0x04, 0x04,
0x84, 0x04, 0x00, 0x01, 0xC1, 0x61, 0x21, 0x21,
0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x18, 0x30, 0xE0, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x83, 0x86, 0x84, 0x86,
0x11, 0x11, 0x27, 0x2D, 0x28, 0x30, 0x50, 0x60,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x18,
0x44, 0xC4, 0x04, 0x04, 0x04, 0x84, 0x04, 0x04,
0x18, 0x00, 0x07, 0x0C, 0x10, 0x10, 0x11, 0x0E,
0x02, 0x02, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00,
0x84, 0xC4, 0x44, 0x46, 0x42, 0x42, 0x82, 0x00,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x78, 0x07, 0x00,
0x86, 0x82, 0x82, 0x82, 0x42, 0x3E, 0x00, 0x00,
0x20, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xC0, 0x78, 0x0E, 0x00, 0x00, 0x00,
0x42, 0x42, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x14, 0x04, 0x94, 0x54, 0x94, 0x00,
0x00, 0x00, 0xC0, 0x20, 0x8C, 0x15, 0xD4, 0x00,
0x00, 0x00, 0x18, 0xA5, 0x10, 0x8D, 0x3C, 0x00,
0x00, 0x00, 0x01, 0x02, 0x01, 0x02, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x48,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x72, 0xD2,
0x02, 0x02, 0x02, 0x42, 0x02, 0x02, 0x62, 0x44,
0x00, 0x00, 0x00, 0x00, 0x0C, 0x9E, 0x92, 0x02,
0x00, 0x00, 0x00, 0xC0, 0x9C, 0x93, 0x90, 0x91,
0x60, 0x40, 0x40, 0x47, 0x0D, 0x19, 0x11, 0x11,
0x03, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x6E, 0x90, 0x98, 0x98, 0x18, 0x18, 0x00,
0xC0, 0x86, 0x09, 0x0D, 0x0C, 0x08, 0x08, 0x00,
0x80, 0x81, 0x81, 0x81, 0xC1, 0x61, 0x2E, 0x18,
0x70, 0x08, 0x08, 0x08, 0x0C, 0xF8, 0x00, 0x00,
0x04, 0x7C, 0xCC, 0x84, 0x84, 0x04, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x8A, 0x0A, 0x9A, 0xF2, 0x02, 0x00, 0x00, 0x00,
0x45, 0x45, 0x45, 0x0C, 0x00, 0x00, 0x00, 0x00,
0x02, 0x2C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x16, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static unsigned char thai_chars_width[256] = {
0, 4, 4, 5, 5, 5, 5, 4, 4, 4, 5, 6, 7, 6, 5, 5,
4, 5, 7, 7, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5,
5, 5, 4, 4, 4, 4, 5, 4, 5, 6, 5, 5, 7, 4, 4, 4,
3, 4, 4, 6, 4, 4, 4, 4, 4, 4, 4, 8, 8, 7, 6, 5,
2, 4, 3, 4, 5, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5,
6, 5, 8, 5, 5, 5, 5, 7, 6, 6, 5, 8, 0, 0, 0, 0,
0, 0, 0, 2, 0, 0, 8, 2, 7, 8, 8, 8, 8, 0, 0, 0,
0, 0, 8, 5, 0, 0, 6, 6, 7, 4, 5, 8, 8, 1, 0, 0,
0, 0, 8, 7, 8, 8, 8, 1, 0, 8, 7, 8, 6, 0, 0, 0,
0, 0, 5, 7, 8, 8, 8, 8, 1, 8, 4, 0, 8, 0, 0, 0,
0, 0, 8, 3, 6, 8, 8, 8, 8, 8, 6, 8, 8, 1, 0, 0,
0, 0, 8, 8, 7, 5, 8, 5, 2, 8, 7, 8, 6, 0, 0, 0,
0, 0, 8, 7, 8, 6, 3, 0, 0, 8, 8, 8, 2, 0, 0, 1,
0, 0, 0, 7, 0, 0, 0, 0, 3, 0, 8, 7, 8, 8, 7, 2,
0, 0, 0, 7, 8, 8, 8, 8, 8, 1, 8, 7, 6, 5, 5, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
char thaitext_is_upper_sara(THAITEXT_CHAR c) {
return (c == 0x31) || ((c >= 0x34) && (c <= 0x37)) || (c >= 0x47 && c <= 0x4E);
}
char thaitext_is_lower_sara(THAITEXT_CHAR c) {
return (c >= 0x38) && (c <= 0x3A);
}
char thaitext_is_hanged_sara(THAITEXT_CHAR c) {
return thaitext_is_upper_sara(c) || thaitext_is_lower_sara(c);
}
char thaitext_is_longtail(THAITEXT_CHAR c) {
return (c == 0x1B) || (c == 0x1D) || (c == 0x1F) || (c == 0x2C);
}
unsigned char thaitext_get_raw_width(const unsigned char *raw) {
unsigned int width = 0, i, j;
for(i = 0; i < 8; i++)
for(j = 0; j < 8; j++)
if((raw[i] >> j) & 0x01)
if(width < (j + 1))
width = j + 1;
return width;
}
void thaitext_render_dot(unsigned int x, unsigned int y, unsigned int scale, unsigned int color) {
if(scale == 1) glcdPixel(x, y, color);
else glcdFillRect(x, y, scale, scale, color);
}
void thaitext_render_raw(const unsigned char *raw, unsigned int x, unsigned int y, unsigned int scale, unsigned int color) {
unsigned int i, j;
for(i = 0; i < 8; i++)
for(j = 0; j < 8; j++)
if((raw[i] >> j) & 0x01)
thaitext_render_dot(x + (j * scale), y + (i * scale), scale, color);
}
void thaitext_render_char(THAITEXT_CHAR c, unsigned int x, unsigned int y, unsigned int scale, unsigned int color) {
thaitext_render_raw((unsigned char *)&thai_chars_pixels[c << 3], x, y, scale, color);
}
const THAITEXT_CHAR *thaitext_render_line(const THAITEXT_CHAR *s, unsigned int x, unsigned int y, unsigned int scale, unsigned int *color) {
y += scale << 2; // 4 * scale
int flag;
THAITEXT_CHAR b;
unsigned int i, j, dX = x;
while(*s) {
flag = 0;
i = x;
j = y;
switch(*s) {
case THAITEXT_CHAR_ENDLINE:
return s;
case THAITEXT_CHAR_WHITESPACE:
x += scale;
goto LOOP_END;
case THAITEXT_CHAR_COLOR:
*color = ((unsigned int)((*(++s)) << 8)) | (*++s);
goto LOOP_END_INC;
case THAITEXT_CHAR_RAW_PIXEL:
thaitext_render_raw((unsigned char *)++s, x, y, scale, *color);
x += (thaitext_get_raw_width((unsigned char *)s) + 1) * scale;
s += 7;
b = 0;
goto LOOP_END_INC;
}
if(thaitext_is_hanged_sara(*s)) {
flag = 1;
if(thaitext_is_lower_sara(*s))
y += scale << 1;
else {
y -= (scale << 3) - scale;
if(thaitext_is_upper_sara(*s)) {
if(thaitext_is_upper_sara(b))
y -= (scale << 1) + scale;
if(thaitext_is_longtail(b))
y -= scale;
}
}
x -= (thai_chars_width[*s] + 1) * scale;
}
thaitext_render_char(*s, x, y, scale, *color);
x = i;
y = j;
x += flag ? 0 : ((thai_chars_width[*s] + 1) * scale);
LOOP_END:
b = *s;
LOOP_END_INC:
s++;
}
return s;
}
void thaitext_render_text(const THAITEXT_CHAR *s, unsigned int x, unsigned int y, unsigned int scale, unsigned int color) {
while(*s) {
s = thaitext_render_line(s, x, y, scale, &color);
if(!(*s)) return;
y += THAITEXT_CHAR_LINE_HEIGHT * scale;
s++;
}
}
unsigned int thaitext_get_line_width(const THAITEXT_CHAR *s) {
unsigned int ret = 0;
while(*s) {
if(((*s) >= THAITEXT_CHAR_CTRL_RANGE_MIN) && ((*s) <= THAITEXT_CHAR_CTRL_RANGE_MAX)) {
switch(*s) {
case THAITEXT_CHAR_ENDLINE:
goto RET;
case THAITEXT_CHAR_WHITESPACE:
ret += 1;
break;
case THAITEXT_CHAR_COLOR:
s += 2;
break;
case THAITEXT_CHAR_RAW_PIXEL:
ret += thaitext_get_raw_width((unsigned char *)++s) + 1;
s += 7;
break;
}
}
else {
if(!thaitext_is_hanged_sara(*s))
ret += thai_chars_width[*s] + 1;
}
s++;
}
RET:
if(ret) ret--;
return ret;
}
void thaitext_render_text_centered(const THAITEXT_CHAR *s, unsigned int xShift, unsigned int y, unsigned int width, unsigned int scale, unsigned int color) {
while(*s) {
s = thaitext_render_line(s, (width - thaitext_get_line_width(s) * scale) >> 1, y, scale, &color);
if(!(*s)) return;
y += THAITEXT_CHAR_LINE_HEIGHT * scale;
s++;
}
}
unsigned int thaitext_get_line_count(const THAITEXT_CHAR *s) {
unsigned int count = 1;
while(*s) {
switch(*s) {
case THAITEXT_CHAR_ENDLINE:
count++;
break;
case THAITEXT_CHAR_COLOR:
s += 2;
break;
case THAITEXT_CHAR_RAW_PIXEL:
s += 8;
break;
}
s++;
}
return count;
}
void setup() {
static const unsigned int width = IPST_SCREEN_WIDTH, height = IPST_SCREEN_HEIGHT;
glcdFillScreen(GLCD_BLACK);
unsigned int scale = 3;
const THAITEXT_CHAR chars[24] = {
0x1B, 0x4B, 0x27, 0x22, THAITEXT_CHAR_NEWLINE,
0x42, 0x08, 0x49, THAITEXT_CHAR_NEWLINE,
0x40, 0x08, 0x1F, THAITEXT_CHAR_NEWLINE,
THAITEXT_CHAR_COLOR, (THAITEXT_CHAR)((GLCD_YELLOW >> 8)) & 0xFF, (THAITEXT_CHAR)(GLCD_YELLOW & 0xFF),
0x17, 0x35, 0x21, 0x0B, 0x39, 0x25, 0x39, 0x00
};
thaitext_render_text_centered(chars, 0, (height - ((THAITEXT_CHAR_LINE_HEIGHT * scale) * thaitext_get_line_count(chars))) >> 1, width, scale, GLCD_WHITE);
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment