int main(int argc, char **argv) { int i, j, f = 0, cc = 0, r; unsigned char uc; unsigned short matches; int ncp = sizeof(codepages)/(sizeof(unsigned short*)); int lte = 0; // encoding via lookup-table, if true // Check if chars in font are used in any codepages check_used(cp_common); for (j=0; j<ncp; j++) { check_used(codepages[j]); } // make lookup-table, return number of distinct bytes in font data lte = (font_make_lookuptable() < 128); printf("#ifndef GET_FONT_COMPRESSION_MODE\n\n"); printf("// This is a compressed version of font_8x16_uni.h produced by the tools/font_8x16_pack program\n\n"); printf("// Format of each character is 'FontData' structure, followed by FontData.size bytes of character data.\n\n"); printf("static unsigned char font_data[] = {\n"); for (i=0; orig_font_data[i].charcode != -1; i++) { if (orig_font_data[i].isUsed > 0) { int top = 0; int bottom = 0; for (j=0; j<16 && orig_font_data[i].data[j] == 0; j++) { top++; } for (j=15; j>=top && orig_font_data[i].data[j] == 0; j--) { bottom++; } if (top == 16) // Blank character { // Fix values to fit into 4 bits each (sorted out in draw_char function) top--; bottom++; } char_codes[cc] = orig_font_data[i].charcode; font_offsets[cc] = f; cc++; matches = font_find_matching_glyph(i); if (matches != 65535) { printf("/*%04x == %04x*/", orig_font_data[i].charcode, orig_font_data[matches].charcode); font_offsets[cc-1] = font_find_offset(orig_font_data[matches].charcode); } else { font_data[f++] = (top << 4) | bottom; printf("/*%04x*/ 0x%02x,", orig_font_data[i].charcode, (top << 4) | bottom); r = f; for (j=top; j<16-bottom; j++) { if (!lte) { font_data[f++] = orig_font_data[i].data[j] & 0xFF; printf(" 0x%02x,",orig_font_data[i].data[j] & 0xFF); } else { // lookup-table based encoding uc = orig_font_data[i].data[j] & 0xFF; font_data[f] = fdata_usage[uc]; // byte's index in lookup table if ( (j > top) && (font_data[f] == font_data[f-1]) ) { // repetition found inside glyph data, set bit7 of previous byte font_data[f-1] = font_data[f-1] | 0x80; } else { f++; } } } if (lte) { for (j=r; j<f; j++) { printf(" 0x%02x,",font_data[j]); } } } printf("\n"); } } char_codes[cc] = 0xFFFF; printf("};\n\n"); printf("// font_data length: %d bytes\n", f); if (lte) { printf("unsigned char fontdata_lookup[] = {\n "); for (i=0; i<fontdata_ltlength; i++) { printf("0x%02x,", fontdata_lookup[i]); if ( ((i+1) & 0xf) == 0 ) { printf("\n "); } } printf("};\n"); printf("// lookup table length: %d bytes\n\n", fontdata_ltlength); #if 0 printf(" /* font data byte distribution\n "); for (i=0; i<256; i++) { printf("0x%02x,", fdata_usage[i]); if ( ((i+1) & 0xf) == 0 ) { printf("\n "); } } printf("*/\n\n"); #endif } // Set up codepage entries, and save to file font_init_data(cp_common, 0, 128); printf("// Offsets to font character data stored in the font_data array.\n\n"); printf("static unsigned short cp_common[] =\n{\n"); for (i=0; i<128; i++) { if ((i & 15) == 0) printf(" "); printf("0x%04x,", cp_common[i]); if ((i & 15) == 15) printf("\n"); } printf("};\n"); for (j=0; j<ncp; j++) { font_init_data(codepages[j], 0, 128); printf("static unsigned short cp_win_%s[] =\n{\n", cp_names[j]); for (i=0; i<128; i++) { if ((i & 15) == 0) printf(" "); printf("0x%04x,", codepages[j][i]); if ((i & 15) == 15) printf("\n"); } printf("};\n"); } printf("\n// Array of pointers to codepage tables.\n\n"); printf("static unsigned short* codepages[] =\n{\n"); for (j=0; j<ncp; j++) { printf(" cp_win_%s,\n", cp_names[j]); } printf("};\n"); printf("\n// Codepage names for menu UI in gui.c (gui_font_enum).\n\n"); printf("int num_codepages = %d;\n",ncp); printf("char* codepage_names[] =\n{\n"); for (j=0; j<ncp; j++) { printf(" \"Win%s\",\n", cp_names[j]); } printf("};\n\n"); printf("#endif // !GET_FONT_COMPRESSION_MODE\n\n"); if (lte) { printf("#define BUILTIN_FONT_RLE_COMPRESSED 1\n\n"); } return 0; }
int main(int argc, char **argv) { int i, j, f = 0, cc = 0; int ncp = sizeof(codepages)/(sizeof(unsigned short*)); // Check if chars in font are used in any codepages check_used(cp_common); for (j=0; j<ncp; j++) { check_used(codepages[j]); } printf("// This is a compressed version of font_8x16_uni.h produced by the tools/font_8x16_pack program\n\n"); printf("// Format of each character is 'FontData' structure, followed by FontData.size bytes of character data.\n\n"); printf("static unsigned char font_data[] = {\n"); for (i=0; orig_font_data[i].charcode != -1; i++) { if (orig_font_data[i].isUsed > 0) { int top = 0; int bottom = 0; for (j=0; j<16 && orig_font_data[i].data[j] == 0; j++) { top++; } for (j=15; j>=top && orig_font_data[i].data[j] == 0; j--) { bottom++; } if (top == 16) // Blank character { // Fix values to fit into 4 bits each (sorted out in draw_char function) top--; bottom++; } char_codes[cc] = orig_font_data[i].charcode; font_offsets[cc] = f; cc++; font_data[f++] = (top << 4) | bottom; printf("/*%04x*/ 0x%02x,", orig_font_data[i].charcode, (top << 4) | bottom); for (j=top; j<16-bottom; j++) { font_data[f++] = orig_font_data[i].data[j] & 0xFF; printf(" 0x%02x,",orig_font_data[i].data[j] & 0xFF); } printf("\n"); } } char_codes[cc] = 0xFFFF; printf("};\n\n"); // Set up codepage entries, and save to file font_init_data(cp_common, 0, 128); printf("// Offsets to font character data stored in the font_data array.\n\n"); printf("static unsigned short cp_common[] =\n{\n"); for (i=0; i<128; i++) { if ((i & 15) == 0) printf(" "); printf("0x%04x,", cp_common[i]); if ((i & 15) == 15) printf("\n"); } printf("};\n"); for (j=0; j<ncp; j++) { font_init_data(codepages[j], 0, 128); printf("static unsigned short cp_win_%s[] =\n{\n", cp_names[j]); for (i=0; i<128; i++) { if ((i & 15) == 0) printf(" "); printf("0x%04x,", codepages[j][i]); if ((i & 15) == 15) printf("\n"); } printf("};\n"); } printf("\n// Array of pointers to codepage tables.\n\n"); printf("static unsigned short* codepages[] =\n{\n"); for (j=0; j<ncp; j++) { printf(" cp_win_%s,\n", cp_names[j]); } printf("};\n"); printf("\n// Codepage names for menu UI in gui.c (gui_font_enum).\n\n"); printf("int num_codepages = %d;\n",ncp); printf("char* codepage_names[] =\n{\n"); for (j=0; j<ncp; j++) { printf(" \"Win%s\",\n", cp_names[j]); } printf("};\n"); return 0; }