# HG changeset patch # User Matti Hamalainen # Date 1349613439 -10800 # Node ID 5b1554eb992852479be7362bd1a191c2fbfbb95c # Parent 8fba01374a2907474fba1fcc130ed22c900d2f4d Add option for specifying the output variable name for C source output mode. diff -r 8fba01374a29 -r 5b1554eb9928 fontconv.c --- a/fontconv.c Sun Oct 07 15:33:55 2012 +0300 +++ b/fontconv.c Sun Oct 07 15:37:19 2012 +0300 @@ -20,7 +20,9 @@ OFMT_C }; -char *optInFilename = NULL, *optOutFilename = NULL; +char *optInFilename = NULL, *optOutFilename = NULL, + *optOutName = NULL; + int optOutFormat = OFMT_DMFONT, optSplitWidth = 8, optSplitHeight = 8; @@ -33,6 +35,7 @@ { 2, 'o', "output", "Output file (default stdout)", OPT_ARGREQ }, { 3, 's', "size", "Set glyph dimensions (-s WxH) for image->font conversion", OPT_ARGREQ }, { 4, 'C', "csource", "DMFONT as C source", OPT_NONE }, + { 5, 'n', "name", "Variable name prefix for C output", OPT_ARGREQ }, }; const int optListN = sizeof(optList) / sizeof(optList[0]); @@ -53,11 +56,11 @@ case 1: dmVerbosity++; break; - + case 2: optOutFilename = optArg; break; - + case 3: { int w, h; @@ -84,6 +87,10 @@ optOutFormat = OFMT_C; break; + case 5: + optOutName = optArg; + break; + default: dmError("Unknown argument '%s'.\n", currArg); return FALSE; @@ -159,7 +166,7 @@ { fprintf(f->fh, "\n};\n" - "const int %s_size = sizeof(%s) / sizeof(%s[0]);\n", + "const unsigned int %s_size = sizeof(%s) / sizeof(%s[0]);\n", (char *)f->data, (char *)f->data, (char *)f->data ); fclose(f->fh); @@ -478,11 +485,18 @@ else if (optOutFormat == OFMT_C) { + if (optOutName == NULL) + { + dmError("C source output selected, but variable name not specified.\n"); + goto error_exit; + } + dmMsg(1, "Outputting a DMFONT format bitmap font as C source file.\n"); + if (optOutFilename == NULL) - outFile = dmf_create_csrc_stream(stdout, "fantti"); + outFile = dmf_create_csrc_stream(stdout, optOutName); else - outFile = dmf_create_csrc(optOutFilename, "fantti"); + outFile = dmf_create_csrc(optOutFilename, optOutName); } if (outFile == NULL)