// Text 2 Font for MD_MAX72xx library // // Quick and not very robust code to create a font definition data table for the // MD_MAX72xx library from a text file representation. The text file has '.' commands // to direct how the definition is structured. // #include "txt2font.h" //#define DEBUG #define DECIMAL_DATA 0 // decimal or hex data selection in font tables // Global data --------------- Global_t G; ASCIIDef_t font[ASCII_SIZE] = { 0 }; // Code ---------------------- void usage(void) { printf("\nusage: txt2font \n"); printf("\n\ninput file .txt"); printf("\noutput file .h"); printf("\n"); return; } int cmdLine(int argc, char *argv[]) // process the command line parameter { if (argc != 2) return(1); strcpy(G.fileRoot, argv[1]); return(0); } int initialise(void) // one time initialisation code { char szFile[FILE_NAME_SIZE]; // we have no font definition for (int i=0; i 0 && isspace(buf[i])) buf[i--] = NUL; return; } void padBuffer(char *buf, unsigned int len) // pad the supplied buffer with spaces up to the length specified { if (strlen(buf) < len) { for (unsigned int j=strlen(buf); j= (G.doubleHeight ? ASCII_SIZE/2 : ASCII_SIZE)) { G.curCode = 0; #ifdef DEBUG printf("\t - boundary check fail"); #endif } font[G.curCode].comment[0] = NUL; font[G.curCode].size = 0; } #ifdef DEBUG else printf("\tend of definition"); #endif } else if (strcmp(&inLine[1], CMD_NOTE) == 0) { strcpy(font[G.curCode].comment, cp); #ifdef DEBUG printf("\tnote '%s' for char %02x", font[G.curCode].comment, G.curCode); #endif } } // reset for next line cp = inLine; memset(inLine, NUL, sizeof(inLine)); } return; } void saveOutput(void) // save the current definition as a font definition header file { unsigned int minAscii = 0, maxAscii = 0; // first parse the font table to work out the min and max ASCII values for (int i=0; i=0; i--) if (font[i].buf != NULL) minAscii = i; fprintf(G.fpOut, "// Autogenerated font - '%s'\n", G.name); fprintf(G.fpOut, "// %s height, ", (G.doubleHeight ? "Double" : "Single")); if (G.fixedWidth == 0) fprintf(G.fpOut, "Variable spaced"); else fprintf(G.fpOut, "Fixed width (%d)", G.fixedWidth); fprintf(G.fpOut, "\n\n"); fprintf(G.fpOut, "#pragma once\n\n"); fprintf(G.fpOut, "const uint8_t PROGMEM _%s[] = \n{\n", (G.name[0] == NUL) ? "font" : G.name); fprintf(G.fpOut, "'F', 1, %d, %d, %d,\n", minAscii, maxAscii, G.fontHeight); for (int i=minAscii; i<=maxAscii; i++) { fprintf(G.fpOut, "\t%d,", font[i].size); if (font[i].buf != NULL) { for (unsigned int j=0; j