comparison fontconv.c @ 213:5b1554eb9928

Add option for specifying the output variable name for C source output mode.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 07 Oct 2012 15:37:19 +0300
parents 8fba01374a29
children d6c184800384
comparison
equal deleted inserted replaced
212:8fba01374a29 213:5b1554eb9928
18 { 18 {
19 OFMT_DMFONT, 19 OFMT_DMFONT,
20 OFMT_C 20 OFMT_C
21 }; 21 };
22 22
23 char *optInFilename = NULL, *optOutFilename = NULL; 23 char *optInFilename = NULL, *optOutFilename = NULL,
24 *optOutName = NULL;
25
24 int optOutFormat = OFMT_DMFONT, 26 int optOutFormat = OFMT_DMFONT,
25 optSplitWidth = 8, 27 optSplitWidth = 8,
26 optSplitHeight = 8; 28 optSplitHeight = 8;
27 29
28 30
31 { 0, '?', "help", "Show this help", OPT_NONE }, 33 { 0, '?', "help", "Show this help", OPT_NONE },
32 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, 34 { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
33 { 2, 'o', "output", "Output file (default stdout)", OPT_ARGREQ }, 35 { 2, 'o', "output", "Output file (default stdout)", OPT_ARGREQ },
34 { 3, 's', "size", "Set glyph dimensions (-s WxH) for image->font conversion", OPT_ARGREQ }, 36 { 3, 's', "size", "Set glyph dimensions (-s WxH) for image->font conversion", OPT_ARGREQ },
35 { 4, 'C', "csource", "DMFONT as C source", OPT_NONE }, 37 { 4, 'C', "csource", "DMFONT as C source", OPT_NONE },
38 { 5, 'n', "name", "Variable name prefix for C output", OPT_ARGREQ },
36 }; 39 };
37 40
38 const int optListN = sizeof(optList) / sizeof(optList[0]); 41 const int optListN = sizeof(optList) / sizeof(optList[0]);
39 42
40 43
51 break; 54 break;
52 55
53 case 1: 56 case 1:
54 dmVerbosity++; 57 dmVerbosity++;
55 break; 58 break;
56 59
57 case 2: 60 case 2:
58 optOutFilename = optArg; 61 optOutFilename = optArg;
59 break; 62 break;
60 63
61 case 3: 64 case 3:
62 { 65 {
63 int w, h; 66 int w, h;
64 if (sscanf(optArg, "%dx%d", &w, &h) != 2) 67 if (sscanf(optArg, "%dx%d", &w, &h) != 2)
65 { 68 {
82 85
83 case 4: 86 case 4:
84 optOutFormat = OFMT_C; 87 optOutFormat = OFMT_C;
85 break; 88 break;
86 89
90 case 5:
91 optOutName = optArg;
92 break;
93
87 default: 94 default:
88 dmError("Unknown argument '%s'.\n", currArg); 95 dmError("Unknown argument '%s'.\n", currArg);
89 return FALSE; 96 return FALSE;
90 } 97 }
91 98
157 { 164 {
158 if (f->fh != NULL) 165 if (f->fh != NULL)
159 { 166 {
160 fprintf(f->fh, 167 fprintf(f->fh,
161 "\n};\n" 168 "\n};\n"
162 "const int %s_size = sizeof(%s) / sizeof(%s[0]);\n", 169 "const unsigned int %s_size = sizeof(%s) / sizeof(%s[0]);\n",
163 (char *)f->data, (char *)f->data, (char *)f->data 170 (char *)f->data, (char *)f->data, (char *)f->data
164 ); 171 );
165 fclose(f->fh); 172 fclose(f->fh);
166 f->fh = NULL; 173 f->fh = NULL;
167 } 174 }
476 outFile = dmf_create_stdio(optOutFilename, "wb"); 483 outFile = dmf_create_stdio(optOutFilename, "wb");
477 } 484 }
478 else 485 else
479 if (optOutFormat == OFMT_C) 486 if (optOutFormat == OFMT_C)
480 { 487 {
488 if (optOutName == NULL)
489 {
490 dmError("C source output selected, but variable name not specified.\n");
491 goto error_exit;
492 }
493
481 dmMsg(1, "Outputting a DMFONT format bitmap font as C source file.\n"); 494 dmMsg(1, "Outputting a DMFONT format bitmap font as C source file.\n");
495
482 if (optOutFilename == NULL) 496 if (optOutFilename == NULL)
483 outFile = dmf_create_csrc_stream(stdout, "fantti"); 497 outFile = dmf_create_csrc_stream(stdout, optOutName);
484 else 498 else
485 outFile = dmf_create_csrc(optOutFilename, "fantti"); 499 outFile = dmf_create_csrc(optOutFilename, optOutName);
486 } 500 }
487 501
488 if (outFile == NULL) 502 if (outFile == NULL)
489 { 503 {
490 dmError("Error creating file '%s', %d: %s\n", 504 dmError("Error creating file '%s', %d: %s\n",