// Prototype of fixed font rendering for Zorzpad memory-in-pixel LCD. #include #include "yeso.h" // This image contains a "glyph atlas" of our font: #include "tamsyn8x16r.xbm" // 4683 bytes at 1777x21 // If each scan line is padded out to a byte boundary, we expect 223 // bytes per line, multiplying by 22 gives 4683. So that's probably // how it works. Also, 21 > 16 so there's probably 2 or 3 pixels of // padding above and below; 3 above and 2 below seems most likely. enum { glyph_width = 8, glyph_height = 16, font_line_bytes = (tamsyn8x16r_width + 7) / 8, first_font_line = 3, }; int main() { yp_p2 size = yp_p(400, 240); // Size of SHARP LS027B7DH01 LCD ywin w = yw_open("font rend", size, ""); ypic buf = yp_new(size); char s[] = "Sphinx of black quartZz,\njudge my vow.\n1+1 = 2, 2*3 = 6.\n" "o/~ Sad songs, they say SOO MUCH! o/~\n" "`x' < `y' {in ASCII} [ok?]\n" "@Una pe@a no es una pena!"; // The font is nominally an ISO-8859-1 font, so let's make an // ISO-8859-1 string. *strchr(s, '@') = 0xa1; // '¡' *strchr(s, '@') = 0xf1; // 'ñ' int x = 3, y = 1; // Cursor position, upper left corner. for (char *p = s; *p; p++) { int c = *(unsigned char*)p; if (c == '\n' || x + glyph_width >= size.x) { // wrap onto next line x = 3; y += glyph_height; continue; } if (y + glyph_height > size.y) { // off bottom of screen break; } if (c < '!') { // unprintable control characters x += glyph_width; continue; } /* Index into font */ if (c >= '\\') c--; // XXX missing char int fx = 1 + glyph_width * (c - 33); /* font X */ if (fx + glyph_width > tamsyn8x16r_width) continue; for (int cy = 0; cy < glyph_height; cy++) { ypix *line = yp_line(buf, y + cy); int bo = font_line_bytes * (first_font_line + cy); /* byte offset */ for (int cx = 0; cx < glyph_width; cx++) { int fxp = fx + cx; /* font x-pixel */ int bit = 1 & (tamsyn8x16r_bits[bo + fxp / 8] >> fxp % 8); line[x + cx] = bit ? 0xf75353 : 0x030303; } } x += glyph_width; } for (;;) { yp_copy(yw_frame(w), buf); yw_flip(w); yw_wait(w, 0); } }