From 74e2bdf58734064c6dc27eb88dc9514bcbb24314 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 18 May 2006 07:56:54 +0000 Subject: [PATCH] * Elite trick in the font generator to cope with C89's string length limitation of 509 characters. Instead of doing: char foo[10] = "abcdefghij"; we now do: struct { char f1[4], f2[4], f3[2]; } foo = { "abcd", "efgh", "ij" }; --- tools/makefont.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/tools/makefont.c b/tools/makefont.c index ed95041..77aa70a 100644 --- a/tools/makefont.c +++ b/tools/makefont.c @@ -33,9 +33,14 @@ #include #include +/* Split our big strings into chunks of 480 characters, because it is + * the multiple of 32 directly below 509, which is the maximum allowed + * string size in C89. */ +#define STRING_CHUNKS 480 + /* This list is built so that it includes all of ASCII, Latin-1, CP-437, * and the UTF-8 glyphs necessary for canvas rotation and mirroring. */ -static int const blocklist[] = +static unsigned int const blocklist[] = { 0x0000, 0x0080, /* Basic latin: A, B, C, a, b, c */ 0x0080, 0x0100, /* Latin-1 Supplement: Ä, Ç, å, ß */ @@ -69,6 +74,9 @@ static int printf_hex(char const *, uint8_t *, int); static int printf_u32(char const *, uint32_t); static int printf_u16(char const *, uint16_t); +/* Counter for written bytes */ +static int written = 0; + int main(int argc, char *argv[]) { PangoContext *cx; @@ -78,8 +86,8 @@ int main(int argc, char *argv[]) PangoRectangle r; FT_Bitmap img; - int width, height, b, i, blocks, glyphs; - unsigned int n, index, glyph_size, control_size, data_size; + int width, height, blocks, glyphs; + unsigned int n, b, i, index, glyph_size, control_size, data_size; uint8_t *glyph_data; struct glyph *gtab; @@ -165,11 +173,19 @@ int main(int argc, char *argv[]) printf("static unsigned int const %s_size = %i;\n", prefix, 8 + control_size + data_size); - printf("static unsigned char const %s_data[] =\n", prefix); + printf("static struct {\n"); + printf("char "); + for(i = 0; (i + 1) * STRING_CHUNKS < 8 + control_size + data_size; i++) + printf("d%x[%i],%c", i, STRING_CHUNKS, (i % 6) == 5 ? '\n' : ' '); + printf("d%x[%i];\n", i, 8 + control_size + data_size - i * STRING_CHUNKS); + printf("} %s_data = {\n", prefix); + printf("\n"); printf("/* file: */\n"); printf("\"CACA\" /* caca_header */\n"); + written += 4; printf("\"FONT\" /* caca_file_type */\n"); + written += 4; printf("\n"); printf("/* font_header: */\n"); @@ -290,7 +306,7 @@ int main(int argc, char *argv[]) } } - printf(";\n"); + printf("};\n"); free(img.buffer); free(gtab); @@ -413,6 +429,14 @@ static int printf_hex(char const *fmt, uint8_t *data, int bytes) while(bytes--) { uint8_t ch = *data++; + + if(written == STRING_CHUNKS) + { + parser += sprintf(parser, "\", \""); + written = 0; + rewind = 0; + } + if(ch == '\\' || ch == '"') { parser -= rewind; @@ -430,6 +454,8 @@ static int printf_hex(char const *fmt, uint8_t *data, int bytes) parser += sprintf(parser, "\\%.03o", ch); rewind = ch ? 0 : 2; } + + written++; } parser -= rewind;